Tuesday, June 3, 2014

Time to learn some Q

Ever since coming across this maddness I've found J and the APL family of languages quite interesting.  To the unfamiliar the beginnings of the J interpreter look to be something akin to an IOCCC entry.  But then how and why would brilliant sounding guys like Ken Iverson and Arthur Whitney be coding like this?  Through a bit of research I've learned that this style can actually make code much simpler to read, almost like a book in fact.  Or that's the claim at least.  I've yet to really make any headway with that fragment, so I myself am not a yet a convert.  Perhaps actually learning an APLish language will help.

I've briefly touched on J off and on over the years but never really buckled down.  This time around I'm switching to one of it's successors, Q.  A free 32 bit version of the interpreter (and kdb+) can be found here.  On Linux, simply extract it to where you want it to reside, set $QHOME to that location, and put $QHOME/l32 in your shell's path.  Run "q" and you're good to go.  If your machine is running a 64 bit OS you will need 32 bit compatibility libraries however.

I've already started in on this tutorial.  So far so good.

Tracking progress through old code

It feels good to have a look at some older code you've written and see that you've most definitely improved.  I'd urge everyone to try it.

I've recently been learning more Ruby by doing problems on Code Abbey.  The very first problems involve summing integers that are passed in via standard input.  My original solution turned out to be as follows:

numbers = []
numberStrings = gets.chomp.split
numberStrings.each {|number| numbers << number.to_i}
sum = 0
numbers.each {|number| sum = sum + number}
print "#{sum.to_s}\n"

And this is fine, in that it works. But were I to code this today it would simply read like this:

puts readline.chomp.split.map(&:to_i).reduce(:+).to_s

Of course it's the exact same thing conceptually, but Ruby-wise, it's a vast improvement.

So, have a look at some of your own code my friends. You may be pleasantly surprised at the progress you've made.