This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Extending Smalltalk Syntax
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Here's the thing - in this case (and in most of the things that come up), we don't actually need to change the syntax of Smalltalk. You want to be able to replace:
someCollection collect: [:each | each name]
with this:
someCollection name
Well, all you need to do is add this method to class Collection:
people := OrderedCollection new.
people add: (Person new
firstname: 'fred';
lastname: 'flintstone').
people add: (Person new
firstname: 'barney';
lastname: 'rubble').
people add: (Person new
firstname: 'wilma';
lastname: 'flintstone').
people add: (Person new
firstname: 'betty';
lastname: 'rubble').
people firstname.
Then you end up with a collection of the firstnames. Now, there are some obvious issues with this new approach:
I can't send messages through if the collection itself understands them (say Person understood #first instead of #firstname, for instance)
What if I would rather have the protocol use #select: instead of #collect:
Either way, if this sort of thing is something you want, you can do it yourself without having to modify the syntax of the language. Which is good - because you can also change it easily if you don't like it. Syntax changes are just there, and you have to deal with them whether you like them or not. Which is why the approach taken by Java and C# sucks so much...