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[1;]/i]←⊂'Fizz'
l[,p[2;]/i]←⊂'Fuzz'
l[(,∧⌿p)/i]←⊂'Fizz Buzz'

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


http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html

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.

http://tryapl.org/

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:
(~R∊R∘.×R)/R←1↓⍳R


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.