This is a single archived entry from Stefan Tilkov’s blog. For more up-to-date content, check out my author page at INNOQ, which has more information about me and also contains a list of published talks, podcasts, and articles. Or you can check out the full archive.

Hello World and Fibonacci

Stefan Tilkov,

Tim Bray makes two points about language books. The first one ('In any such book, the first example program should print the string “Hello world.”') is of course absolutely correct. The second one is perfectly addressed by DeWitt Clinton – what I like best is this gem from the David Madden's comment:

fib = Hash.new{ |h, n| n < 2 ? h[n] = n : h[n] = h[n - 1] + h[n - 2] }
puts fib[15]

(For the none-Rubyists among you: the Hash constructor accepts a block that will be called when a lookup is performed for a key that has no value, in this case storing the value and then returning it – a simple write-through-cache.)