| 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
|