The first language switch: Week 2 – Io
June 19, 2011
What I’ve learnt / haven’t learnt about Ruby
Well, there’s still a hell of a lot to learn about Ruby, but I feel that I now have enough of a grounding in it to start to know what I don’t know.
I do know the basic structure of the language, how to read it, and can start to write trivial programs in it without having to stop and think (too much!) I know how classes work, I understand how you can change classes at run-time to introduce phenomenal cosmic power and can see how with little effort, some very interesting things emerge such as creating domain specific languages with meta-programming.
I’ve been able to reason about (but not yet write) some non-trivial programs in Ruby including creating a CSV parser which automatically loaded a file based in the name of the class, and I’ve seen how the behaviour for this can be injected in three different ways: through inheritance, modules and macros. I fully understand the inheritance method, think that I could write the module method from scratch, and can understand the macro method when I read the code.
In short, I’ve had an extremely successful couple of days learning Ruby and think that if I had seen that the study group existed earlier on in the week, my grasp of it would have been much stronger. I think that I’ll continue to learn the language in my own time, but in order to keep up to speed with the rest of the study group, it’s time to make the switch to Io.
First impressions of Io
I must say that installation on my mac was a breeze. I have homebrew installed, so all I needed to do was to open the terminal and type:
$ brew install io
Around 15 minutes later, it was all installed and working. I can’t say the same for my CentOS server, but apparently things are a little more difficult to install on there so I’m not stressing about that (yet!)
From what I’ve read about Io so far, I think that I’m really rather going to like it. Like Ruby, it gives you the power to really screw things up, for example, redefining
Object clone could render the current instance unusable meaning that you need to re-start the interpreter.
An object can be thought of like a hash/associative array of fields and methods. Each of these key => value pairs is known as a slot. So a slot can hold either a value or a method (maybe more? That’s as far as I’ve got!)
There are three ways of assigning a value to a slot:
= will assign a the value only if the slot exists;
:= will create the slot and assign the value to it;
::= will create the slot, creates a setter and assigns the value. The benefit of creating the setter means that when you clone objects you can also set the clone’s values on the same line in an easily readable way.
Sample code for creating Vehicle/car objects
Vehicle := Object clone car := Vehicle clone car make := "Ford" car details := method(make print)