I would expect that most of you never heard about such programming language as Io. Very likely programmers would associate Io with “input-output”, but Io language has nothing special to do with it and has no cool in-out features.
Io is extremely tiny language which runs on supermall virtual machine, even your micro-oven can handle. Having that said I don’t mean that Io is not powerful.
Io is prototypical object-oriented language with dynamic typing. For me, as C# guy, it was not easy to “feel” the language. I could very quickly understand syntaxes and mechanisms of language. It will not take for you longer than 20 minutes to start writing simple code, either. I was understanding what I was trying out, but I didn’t feel myself comfortable with realizing that anything can be changed in this language on the fly which could affect all of the prototypes of changed object. Note that there is no difference between class and object, or better to say, there are no classes in Io. If you define method on some object it is ultimately inherited to the clones. It worth to mention that in Io every operation is message. “Hello world” application which would look like:
Should be understood like: “send message “println” to the string object”.
Here is bit more code (sheep example cloned from this post):
Sheep := Object clone Sheep legCount := 4 MutantSheep := Sheep clone MutantSheep legCount = 7 dolly := MutantSheep clone MutantSheep growMoreLegs := method(n, legCount = legCount + n) dolly growMoreLegs(2)
The coolest thing about Io is its concurrency model, at least I think so.
Io uses coroutines, actors, yielding and future stuff. If you don’t know what it is about. Here is a bit of explanation. Coroutines in Io are user threads, built on top of kernel threads, which allows for quick switching of contexts and more flexibility in general. For simplicity think about coroutines as about threads. Any object can be sent message asynchronously, by adding @ symbol before the message name. This message is then places in object’s message queue for processing. Object would hold coroutine (thread) for processing those messages. Objects holding coroutine are called Actors. Effectively any object in Io can become Actor. When you call some methods asynchronously, result can be saved into so called “future”, value of which is resolved before it is used. You can switch between actors using “yield”. To demonstrate this, I prepared this small piece of code, which prints numbers 0,1,2,3 one by one:
oddPrinter := Object clone evenPrinter := Object clone oddPrinter print := method(1 println; yield; 3 println; ) evenPrinter print := method(0 println; yield; 2 println; yield) oddPrinter @print; evenPrinter @print;
If you found this to be interesting I recommend you to read Io Guide. There you will find many other interesting features of the Io language, which I didn’t mention.
Here are some links:
You may be wondering why I’m writing and learning something about old, small language, which even doesn’t have normal ecosystem.
I’m trying to learn more programming concepts and play with different languages. Recently I was even blamed for writing “enterprise-y code” and suggested to see how code looks like in other programming language communities. Well… of course it is valid and good suggestion, but not that I never thought about it. In my year plan post I mentioned that I would like to learn one more programming language and to start with something I picked up interesting book called “7 languages in 7 weeks”. So far I read and tried Ruby, Io and Prolog. Scala, Erlang, Clojure and Haskell are next in a row. After I’m done with book I will pick one language (not compulsory from list) and extend my knowledge in it. Of course there will be a review on the book.