Re:The Io Language
by richcollins on Thursday July 22, 2010 @04:22PM
(#1539431)
One very simple thing that Io gets right is the unification of instance variables and methods as slots. It lets you override behavior with little friction:
[ Parent
| on HN ]
What am I missing?
>>> class Person(object):
... def __init__(self, name=None):
... self.name = name
... def greeting(self):
... return "I'm %s" % self.name
>>> bob = Person("Bob")
>>> bob.greeting()
0: "I'm Bob"
>>> bill = Person()
>>> bill.greeting = "Yo"
>>> bill.greeting
1: 'Yo'
Re:The Io Language
by zephyrfalcon on Friday July 23, 2010 @02:43PM
(#1542046)
Notice that you use bob.greeting() but bill.greeting (without the parentheses), while Io uses the same syntax in both cases. Whether this is good or bad is mostly a matter of preference, I think...
Of course, this implies that Io would need a separate construct to get the value of a slot (e.g. bob getSlot("greeting")), while in Python you'd just use bob.greeting no matter whether greeting is callable or not.
Re:The Io Language
by richcollins on Friday July 23, 2010 @03:03PM
(#1542097)
Your code isn't general. You have to change the interface. In Io is there just one interface (send a message). If the slot identified by the message send is activatable (a method), then it is activated, otherwise it is just returned.
Re:The Io Language
by JoachimSchipper on Friday July 23, 2010 @08:32AM
(#1540978)
I'm not sure, but note that your Python code has to know whether to call greeting or not, while the Io code does the same thing either way.