Aimred Developer Blog December 2009 Archive
Languages To Learn For 2010
It’s generally good programming practise to try to learn, or at least become familiar, with a new programming language every year. 2009 was a bit of a washout for me in this regard but in 2008 it was Erlang and although I haven’t had the time to actually produce a project with Erlang I’ve read Joe Armstrong’s Programming Erlang and like the concept and semantics of the language. The syntax though is still a little bit wierd to me, but that apprehension is probably due to my lack of practise in the language.
This year I’ve decided to try my hand at two languages, one relatively very old and one relatively very new. The old language is Scheme, although I’m still up in the air over which implementation to try: Chicken Scheme or PLT Scheme. The new language is Google’s Go programming language.
I might try and post a few articles on either language on this blog during the course of 2010, that is if I manage to learn enough to not look like a complete rank beginner.
Neat Ruby Tricks: Named Parameters with Ruby 1.9
One of the syntax sugar additions to Ruby 1.9 is the new syntax for specifying hashes with symbols as keys. In 1.9 you can now specify the hash on line 1 in the format on line 2.
1 { :manufacturer => 'Lenovo', :model => 'Thinkpad R500' } 2 { manufacturer: 'Lenovo', model: 'Thinkpad R500' }
Now this might not look like much of an improvement but it shines in method calls where we can use ‘naked’ hashes as named parameters. For example in the following code snippet line 1 (Ruby 1.8) is the equivalent to line 2 (Ruby 1.9)
1 get_price( :manufacturer => 'Lenovo', :model => 'Thinkpad R500' ) 2 get_price( manufacturer: 'Lenovo', model: 'Thinkpad R500' )
The expression on line 2 using the new syntax is quite a bit neater (in my own opinion) and makes named parameters even easier to read and parse.
There is one caveat to remember with this and that all keys will be converted into symbols.
1 pc_data = { manufacturer: 'Lenovo', model: 'Thinkpad R500' } 2 pc_data[ :manufacturer ] # => 'Lenovo' 3 pc_data[ 'manufacturer' ] # => nil