Foo.counter = 0;
Foo.prototype.handle = function(message, data) {
if (message == 'bar' && Foo.counter < 3) {
return this.bar(data)
}
else {
throw "I forgot about 'bar'."
}
Foo.counter++;
}var f=new Foo()
f.bar() //Just says that f.bar is undefined and therefor not a function
//If I add
f.bar=function(something){return "nothing"}
//Calling
f.bar("ABC") //Many times always answers "nothing"
IgorPartola's example code won't intervene in the usual function-call process; rather, it provides a tacked-on means of simulating message sending behavior that ought to be included in the language's syntax under Kay's definition of OO. With this convention, you'd never call bar(), or any other method, directly; you'd call handle to send a 'bar' message to the object instead. Then, if you send a message the object doesn't understand, handle() can route it properly.
http://carcaddar.blogspot.com/2009/04/closure-oriented-metap...
http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/m...
I've a lot of respect for Dr. Kay, but history has shown him to be wrong on this point: strong static typing and binding things as early as possible is how robust systems are built and how errors are minimized.
However I won't doubt that the Smalltalk approach is probably right for its original intended purpose (exploratory or didactic programming).
Huh? What about Erlang?
For a good overview, check "Gradual Typing of Erlang Programs: A Wrangler Experience " (http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.160....) and/or "Practical type inference based on success typings" (http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.62....).
Could you expand on this? I don't see how late binding is incompatible with the robustness that static typing provides. In a traditional (C/++/#/Java) OOP setting, virtual methods and dynamic method dispatch allow for late-binding of method names to behavior based on run-time type specializations, but you still have the static compile-time guarantee that a method with the appropriate name and type signature will exist. This seems to me like it has the same robustness as an early-bound model, bounded only by the sophistication of the type system. Do you consider it qualitatively less late-bound than the message-passing paradigm, or am I missing something?