Sunday, November 30, 2008

On implicit self

I didn't quite like the implicit self in Self and Newspeak, but I couldn't quite point my finger on why. I just realized that the argument can be made quite concisely.

The implicit self is a special case of the grammar of the language which does not need to be there. In languages that strongly rely on message sends as the mechanism to allow behavior to occur, message sends should be expressed as unequivocally as possible. At least from my Smalltalk-biased POV, the fact that all sentences are of the form

receiver message: withArguments

is a benefit because it clearly states what the receiver is. As such, I'd rather see self than having to assume it by scanning the first token until the first occurrence of $: (or '::') to only then be able to disambiguate between a receiver and a keyword.

In short: I prefer the work of my internal parser to be made easier by the use of prefixes, rather than to have to keep a stack that only goes down in the presence of a suffix.

Similar arguments dictate my preference to write [nil] instead of [], and to add ^self at the end of empty methods rather than seeing a "blank" text pane.

I find that the consistency offered by a few keystrokes makes it easier for me to read and understand code faster and more accurately. Therefore, since we read code much more often than we write it, I think that favoring reading speed over typing speed is the right decision to make.

1 comment:

Gilad Bracha said...

Hi Andres,

I'm sorry you do not appreciate the notion of implicit receivers in Newspeak. Vassili wrote a nice post that clarifies some misunderstandings about why the implicit receivers are there, what they do, and why they don't have the problems you imaigne them to have.

http://blog.3plus4.org/2008/11/30/how-to-learn-to-stop-worrying-and-love-implicit-receivers/#comments