Tuesday, January 15, 2013

Amazon: Global selling done wrong

I have an account at Amazon. Actually I have two. One at Amazon.com and one at Amazon.co.uk. In the beginning I just had one at Amazon.com, but to avoid import tax I had to create one in the EU as well. I don't really understand why I needs these two accounts.
Apparantly Amazon only sells E-books through the american version, not the UK version. It's not that they won't sell them to me, they just require me to log into the american version to do the purchase.

I once searched for the a kindle paperwhite, and now amazon is flodding my inbox with add campaigns for the kindle paperwhite. I can go through the order until i get to the shipping details. Why am I getting adds for stuff they won't sell me?
Couldn't they just figure this out beforehand. I also find it strange that sales tax is not included in the listed prices. I know thats the way things work in the US but couldn't they change it for the rest of us.

For the affiliate program it is just ridiculus. I have to link to a localized version of amazon. If my audience is global, there is no way to target everybody. I have to select what version of amazon I want to link to and miss out on all my users that can't use that version.

Wouldn't it just be cool if they could use the information on my account to display the information that is relevant to me, or maybe just redirect me to the version of their site that is of use to me. Maybe I'm too demanding, but it would for sure make me a more happy customer.

Thursday, December 20, 2012

Fizz Buzz in APL

I came across the Fizz Fuzz programmers test and just couldn't help myself programming it in APL:

p←0=3 5∘.|l←i←⍳100
l[(,∧⌿p)/i]←⊂'Fizz Buzz'

And that is the way it is done (the code is self explanatory :))


Wednesday, December 19, 2012

Software inovation by law

At one point in time, some people figured out that the world was full of selfish bastards that would leech off each other and therefore smart people would not innovate because all their hard work would be stolen. The patent was invented and this allowed inventors to work on difficult problems and if succeeding  be rewarded in the end. The leechers however have discovered that they can use the patent system for their own benefit. Instead of patenting stuff that represent a great effort they patent simple every day things like rectangles, colors or human gestures.

So now the patents are no longer used to defend the innovative from the bullies. Instead the bullies uses them to keep the innovative from being innovative. By having a vast amount of patents on everyday things and by keeping them to you self until someone has violated them, you effectively keep anyone from creating anything new unless they can afford a patent war against you.

In other words, it no longer depends how good your ideas are but how much money you have. I hope someone with the power to be heard one day figures this out and requests the system to be changed. Patents should only cover things obtained through some kind of effort, and patent owners should be forced to license the use of their patents to others. Color combinations or shapes are not to be claimed by anyone as their property! That's just my opinion...

Tuesday, December 18, 2012

Happy Happy Joy Joy.. Learning a new programming language

A year ago I started a new job. The company that is now my employer has a lot of code written in an old and obscure language called APL. So I have had to sit down and learn APL.

APL is short for "A Programming Language" and being invented in 1953 it is a very old language. For me its a fresh new approach to programming. Instead of spawning from electronic engineers, APL comes from the twisted mind of a mathematician. That means that the language does not origin from abstracting processor instructions, but from what would be useful for doing math. This makes it an extremely high level language that is very powerful once you wrap you head around it. APL sees the world as vectors and matrixes (single dimensionned arrays and multi dimensioned arrays for the rest of us). Once you have your world defined in arrays, you will be amazed by the expressiveness that APL provides.

I recently listened to hanselminutes where they talked about F#. One of the key points with F# was how little code you had to write to accomplish anything.  The example given was Conway's game of life. Ruby could do it in 140 characters. F# weighed in with an impressive 127 characters. Compared to APL these languages are however very verbose. APL does the same thing in only 38 characters. To be fair, this problem is right down APL's alley as 'twodimensional array' is a native type of APL.


To begin with APL is completely unreadable. First of all, the character set used is not present in you favourite font. Secondly there is no operator prescedence in APL, Expressions are evaluated from right to left.

  • 3 + 4 = 7
    returns 3 (4 is not equal to 7 and returns 0, 3 is added)
  • 4 * 0 + 4
    returns 16 
  • etc.
Example code from wikipedia:

This code finds all the primenumbers up to R.Remember to read this from the right. ⍳R creates a vector  containing the numbers from 1 to R. 1↓ drops the first element of that vector. The new vector is assigned to R. The / in this context means a filter, it will filter the vector on the right by the binary vector(elements are boolean). 
R∘.×R produces a matrix(double sided array) containing the product of all combinations of numbers found in R. R∊ produces a binary vector of all elements in R that are also on the right. The binary vector is inverted by ~ and the filter is applied. Voila, a vector of prime numbers.

All in all it's great to learn a new language that is so different. This probably will never be language of choice but it has given me a different perspective on the other languages I use.

Thursday, August 09, 2012

Unit tests are not all black and white

And they are not all red or green either. From a management perspective it might make sense to divide unit tests into the ones that pass, and mark everything else as an error. After all, this is what is confirmed to work and what is not.

From a development's perspective this approach makes less sense. The main goal is still to get all unit tests in the green zone. It's just that some of the test that do not pass are not errors that need immediate attention. Some of the error may already be planned to be fixed in the future, configuration problems or dependencies on resources that are not available at the moment of the test run.

Take for example a test that uses a database (i known that technical it is not a unit test). You want to test that some updates are done correctly. If for some reason the database is down and you can't get an open connection to the database, would you fail the test? My suggestion is that you don't. The test is not about getting a connection to the database but about doing the update.

They way I like to use unit tests is to utilize the ignore or inconclusive state of tests. If it is some configuration,  some 3. party component missing on the test machine or some error that is scheduled in the future I like to take them out of the errors in need of immediate attention.

I have seen panicking because hundreds of tests fail just because the password of the database user had changed. This should maybe fail in a single test that verifies that the database is accessible, but not the whole test suite.

It's a good idea to prioritize your tasks, and by using levels of severity in your unit tests you can optimize your bug fixing efforts a bit and focus on the errors that are real.

Tuesday, August 07, 2012

Recursive lambdas

More and more programming languages supports a functional approach to programming. the functional approach gives a more compact syntax that for some people will be easier to read because everything can be kept together.

In C#, lambda expressions take us closer towards functional programming. An important concept of functional programming is recursitivity which in many cases can replace loops.

I pulled up my old base conversion algoritm and gave it a try. Basically it takes an integer and returns a string respresented in a base of your choice.

Integers to Text

The variable chars contains the characters used in the output. For a conversion to base 16 (hex) the first 16 are used etc..
C# doesn't let you reference something that is defined in the same line, so the signature of the lambda is defined in the previous line. The actual conversion is all written in one line of code and I'll let you decipher it yourselfes. Because of the recursion, no loop is required. It will basically calls itself for every character to be output. As C# doesn't support tail recursion (this is not completely true, but I won't count on it anyway), recursive code in C# has a limit to how many times a method can call itself.

I also did one that goes the other way.

Text to Integer
What i have now is two methods so that I can convert from any base (limited to the length of the charset used) to any other base. this is how i convert a hex number into base 3.


Thursday, July 26, 2012

Inline, nested if statements

The ?: operator was something I had to get used to when I first saw it. I allows you to define a conditional if statement on a single line with a build in assignment. This compacts a lot of code and once you get used to it it's quite readable.

var <result> = <if-condition> ? <true value> : <false value>;

This can, among other things, be used to translate values. In the following s will contain the text "Small" if i is less than 3, otherwise "Not Small"

int? i = 4;
string s = i<3 ? "Small" : "Not small";

Whatever is behind the colon, you can replace with a new inline if statement. Now its an if/else if/else statement on a single line.

string s = i<3 ? "Small" : i==3 ? "Three" : i>3 ? "Large" : "Not a Number";

Which gives the same result as.

string s;
   s = "Small";
}else if(i==3){
   s = "Three";
}else if(i>3){
   s = "Large";
   s = "Not a Number";

This is even better when used in lambda expressions as a "standard" lambda expression only allows one statement. 

   GetInts().Select(i=>i<3?"Small":i==3?"Three":i>3?"Large":"Not a Number")
            .Aggregate((x, y) => x + "\n" + y)