Python vs. Io

Daniel Ehrenberg LittleDanEhren at yahoo.com
Sat Jan 31 14:34:28 EST 2004


> I think I get the idea. Let's see:
> 
> P = Object clone do(  # saw do() used in iolanguage mail archive
>     allocated = 0
>     init = method(
>         id := allocated    # semi-colons required?
>         allocated += 1
>     )
>     howMany = method(return allocated)
> )
> 
> x := P clone
> y := P clone
> write("allocated? ", P howMany())
> # output ...
> # allocated? 2
> 
> Correct?
> 
No, init and allocated should have used :=, even though init has
special meaning. I don't really know why you have the howMany method
since it doesn't really do anything (everything is public and methods
can be called with just references), and all clones of P will
dynamically inheret allocated. Also, when initializing variables,
their scope must be specified (which is the whole reason for the
difference between := and =), so id := allocated should probably be
self id := allocated. self, along with a few other variables, is
implicitly sent to all functions (and do).

> Thanks for making me aware of this language, it has some
> interesting ideas. I'm not annoyed by the difference between :=
> and =. I understand the issue(s) they're trying to solve: you don't
> need to declare local variables, or use self, explicitly. I don't have
> a problem with that. I imagine it could lead to subtle bugs (if you
> update a slot when you meant to set a new one), but that is only
> speculation on my part.

Actually, the whole scoping model is really that you're working in
transparent objects with inheretance, even for things like the global
scope and the scope of functions.
> 
> I'm not a fan of the parenthesis (which might be expected from
> a Python user - love that significant whitespace ;).

At first I didn't like them easier, and with the syntax of most
languages, there really isn't any advanatage, but Io code by
convention can be much more dense (while still readible). For example,
Io doesn't have a ternary operator (like Python), but the flow control
function if can be used like one. For example:

x := if(Nil, 1, 0)

would set x to 0. Note that only Nil (and things that emulate Nil) are
false in the context of if.

> I'm also not a
> big fan of 'clone', I'd rather see 'new', but I do understand why
> 'clone' is more apt. Of course, in this language, you could always
> just say
> 
> Object new = Object getSlot("clone")
> P = Object new
> ...
> 
> I can appreciate the flexibility of that.

Yeah, that is an advantage. That way of using 'new' will be inhereted
dynamically for all objects.

Daniel Ehrenberg



More information about the Python-list mailing list