irb beats calc any day

This may wind up the shortest entry to date - yet I hope as valuable as any other post.

Several months ago I switched the host OS on my laptop - from Windows XP to Gentoo Linux. One of my many reasons for doing so was the ease of maintaining a performant system under Linux (esp. Gentoo). All those Windows services we so very rarely use add up to wasted memory and processor.

My Gentoo installation is loaded with only those components I regularly use. Recently I needed to crunch some financial figures. A calculator was not installed on my system but Ruby was! And that leads me to maybe the best calculator of all...

Before I get into how Ruby solved my immediate calculation needs let's review Ruby's support for numbers. Integers can be almost an unlimited length in Ruby. 64-bit or smaller are represented by Fixnum instances, but beyond that Ruby uses Bignum. The type is implemented as a variable-length set of short integers. So the limitation is free memory...nothing more.

This is a wonderful advantage for a calculator - but the big advantage is how complex your expressions can be using Ruby interactively. Just fire up irb and run your calculations. You get far richer expressions and memory storage than any calculator:

$ irb
irb(main):001:0> pi = 3.1415926
=> 3.1415926
irb(main):002:0> radius = 20
=> 20
irb(main):003:0> area = pi * radius ** 2
=> 1256.63704

This calculator-trick used to be possible in Windows. But now QBasic Missing from Windows 2000. That's okay, you can install Ruby on Windows - or try IRB Online.

For more Ruby - stay tuned for my next post on design patterns: Template Method using Ruby.