“Day 2″ with Io on my more and more misnamed quest. In this chapter Bruce explains basics of conditionals, looping, operator definition and reflection. He also spends a bit more time to explain message passing in Io.
In conditionals and looping section we get overview of some typical looping and branching structures. Such as a simple infinite loop that will keep evaluating until a break:
loop("you spin me right round..." println)
This can come in handy when implementing things such as servers etc. We also get to meet our good old friends (often seen in most languages) for and while loop:
i := 1
while(i <= 10, i println; i = i + 1)
for(i, 1, 10, i println)
for(i, 10, 1, -1, i println)
First two lines are an example of a while loop. It will print numbers from 1 to 10. While loop takes a condition as a first parameter and it will keep evaluating statements passed in second parameter while the condition holds. Lines 4 and 6 are examples of a for loop. First one prints numbers from 1 to 10 and second one counts back from 10 to 1. This is due to the fact that second for loop utilises the optional step parameter. The parameters of a for loop method are: the name of the counter, the first value, the last value, optional step, and a message with sender. As we can see from example step parameter can be negative. Read on »
My quest to learn seven languages in seven weeks continues. Next language that I am tackling is Io. By this time I am now very well aware, that due to the fact that I don’t have much time for private life lately, I will probably end up spending seven months for the task as mentioned in my previous post. In order to make some visible progress, I decided to blog about my endeavours on a day by day rather than language by language basis.
So let me sum up my thought after day one with Io. You might not heard about this language before as it is not as popular or well known as others mentioned in the book. Io is an object oriented prototype language. This means that it doesn’t have the notion of a class as an object template meaning that there is no distinction between classes and instances – all object are merely clones of other objects. The language is very simple and syntax is minimal. Objects are created by cloning like this:
Food := Object clone
Read on »
It is the end of the first “week” with the book. Due to very busy pre holidays period and holidays it actually took me a month to get through it. I hope things will be less hectic in coming weeks so that I can live up to the book’s title.
So week one with Ruby then. Everyone interested in software development has almost certainly come across this language. It has captured the interest of disgruntled masses with very productive Rails framework back in 2005. I remember seeing the infamous blog demo videocast and being blown away by the fact that this guy seems to be able to knock up a blog from scratch in about 15 minutes. What I was even more impressed with was how clean and sensible the code he was writing was. I tinkered around with Ruby for a little bit back then, but I got pulled more deeply into the world of Java at that time, as as this was lingua franca in company where I worked and the idea was that it was more important for me to master that than a side language.
So what did I miss out on by doing that? For one Ruby is a pure Object Oriented programming language which means that everything including literals is an object. It uses strong and dynamic (duck) typing strategies. This allows for polymorphism by functionality rather then by declared types; which gives you more freedom and less typing at the expense of compile time type checking. All the classes in Ruby are open and can be extended, including classes such as String and NilClass. It supports mixins (think interfaces with implementation) as a workaround for multiple inheritance. Provided APIs are rich and frequently provide same functionality via different methods. Ruby and it’s APIs rely on code blocks (closures, higher order functions – how ever you want to call them) heavily. It also provides good metaprogramming facilities. All of this makes it a wonderful and expressive language, but at the same time it gives you all the rope you want to hang yourself. Read on »