For Programmers: Free Programming Magazines  


Home > Archive > Smalltalk > December 2007 > Re: FINALLY: Another language adopts Smalltalk's keyword -syntax









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: FINALLY: Another language adopts Smalltalk's keyword -syntax
Paolo Bonzini

2007-12-18, 7:21 pm


> moveLeft(Distance distance, Speed speed)
> {
> this.target =
> new Vector(this.position.x() - distance.value(), this.position.y())
> this.speed = speed ;
>
> }


Yes, but then you invoke this as

s.moveLeft distance: 3.meters, speed: 5.mph

which loses the "English-ness" claimed in the Groovy article. Using
variables called "at" and "left" is mandatory in Groovy if you want to
keep the English-like naming of methods.

> The converse drawback in Smalltalk does not appear to be as easily overcome
> (weak typing etc) .


I don't see how weak typing helps or hinders the problem that you
cannot write both of

s moveLeft: 5 meters at: 3 mph
s at: 3 mph moveLeft: 5 meters

In fact, I think that this example is not very good, but there is a
case in Smalltalk where reordering keywords would be nice. This
exception is constructor methods; for example I know that the right
method to create Rectangles is #left:top:right:bottom:, but somebody
who used CSS a lot may think it is #top:right:bottom:left:, and
somebody who is thinking in Cartesian coordinates may want
#left:bottom:right:top:.

In the general case, however, the way Smalltalk people use (and name)
keyword messages is such that there is *usually* no confusion on the
order to be used. The first example above is English, the second is
not; a Smalltalk programmer might have used the name #moveLeftAt:by:,
as in

s #moveLeftAt: 3 mph by: 3 meters

but not #at:moveLeft:. A good IDE will help you as long as you can
remember the first keyword (which is usually an imperative verb, so it
is easy to remember).

Paolo
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com