Week 2 Day 1 – Dipping my toe into Io

Today i started to learn a new programming language, for the first time since trying out Lisp several months ago. Here are my first thoughts upon encountering Io.

My initial reactions

Reading a book doesn’t tell you much. I read the chapter twice before i actually tried it out, and doing feels so different from reading. Something about seeing it produce results before your very eyes feels thoroughly enlightening!

I like the space between the receiver and message. It’s so readable. “Vehicle type” and “Vehicle description” are just natural language, you’d hardly think it was code at all!

I don’t much like the concept of the Lobby. It’s like everything is just hanging around there, chilling out, doing nothing. Don’t you guys have someplace to be?! I suppose every language has to keep its objects somewhere – the difference with Io is we get to find them all in one place.

Really understanding prototypes

When i tried out the proto method i think i properly GOT IT. Seeing those hex identifiers really proved to me that i didn’t clone my ferrari from some abstract Car concept. I cloned an actual Car. THE Car, in fact.

Io> ferrari proto
==>  Car_0x1002a6be0:
  drive            = method(...)
  type             = "Car"

Io> Car
==>  Car_0x1002a6be0:
  drive            = method(...)
  type             = "Car"

Io> Car proto
==>  Vehicle_0x1003d9090:
  description      = "Something to take you far away"
  type             = "Vehicle"

Creating a singleton

Could it possibly be any easier to create a singleton?!

Io> Highlander clone = Highlander
==>  Highlander_0x1005ae7f0:
  clone            = Highlander_0x1005ae7f0
  type             = "Highlander"

“Highlander, your clone method returns Highlander.” — “Right you are!”

Io typing

I would say that Io is strongly typed. It will not let me add together a Number and a Sequence (Sequence seems to be what Io calls a string)

Io> 1 + "2"

  Exception: argument 0 to method '+' must be a Number, not a 'Sequence'
  message '+' in 'Command Line' on line 1

However, like Ruby, some strings can be converted to numbers:

Io> 1 + "2" asNumber
==> 3

So, even though Io might have guessed what i meant by 1 + “2” it’s not going to just do it for me unless i ask nicely!

The typing is dynamic, meaning it is figured out at runtime, as demonstrated by this test:

Io> Tester := Object clone
==>  Tester_0x100532ad0:
  type             = "Tester"

Io> Tester test := method(1 + "2")
==> method(
    1 + "2"

Io> Tester test

  Exception: argument 0 to method '+' must be a Number, not a 'Sequence'
  +                                   Command Line 1
  Tester test                          Command Line 1

Other discoveries

Here is a useful thing:

Io> Object slotNames sort
==> list(, !=, -, .., <, , >=, ?, @, @@, actorProcessQueue, actorRun, ancestorWithSlot, ancestors, and, appendProto, ...)

I am not sure of the distinction between a Sequence and a String. It appears that a Sequence is a String.

Io> "hello" type
==> Sequence
Io> "hello" isKindOf(Sequence)
==> true
Io> "hello" isKindOf(String)
==> true

You can change an object’s prototype and all of a sudden it won’t be able to respond to slots anymore:

Io> Vehicle := Object clone
==>  Vehicle_0x1003d94b0:
  type             = "Vehicle"

Io> Vehicle description := "Something to take you far away"
==> Something to take you far away

Io> Car := Vehicle clone
==>  Car_0x1004ed400:
  type             = "Car"

Io> Car description
==> Something to take you far away

Io> Car setProto(Object)
==>  Car_0x1004ed400:
  type             = "Car"

Io> Car description

  Exception: Car does not respond to 'description'
  Car description                      Command Line 1

I found that interesting!

I think i’m going to like Io! :)