[GOODIE] Arithmetic assignments (+= and friends)

Lex Spoon lex at cc.gatech.edu
Mon Jun 17 17:36:20 UTC 2002


"Andreas Raab" <Andreas.Raab at gmx.de> wrote:
>  I have no interest in any kind of minimal syntax. And the
> complexity of explaining that += means "increase this variable's value
> by X" doesn't seem a big hurdle to me.

You haven't tried to teach people to program, have you?  I have the
biggest success in teaching people by teaching them Common Lisp, because
there was little discussion at all on syntax.  I've never tried Scheme,
but I imagine it would be simpler.  The times I've tutored or taught
people in Pascal, C, or Ada, the syntax has really gotten in the way.
Smalltalk is hard for a different reason: you have to grok a bunch of the library
before you can do anything.  The worst cases I've seen are C++ and Java:
you have the same difficulties from Smalltalk, plus you have a lot of 
syntax to learn.

Aside from that, there is a possible cost even an expert programmer. 
Time spent learning the extra forms could have been spent becoming a
better programmer in general with the existing forms.  Admittedly, no
one really knows what the true difference here.  It's just a thought.


"Diego Gomez Deck" <DiegoGomezDeck at ConsultAr.com> wrote:
> This is not true in Smalltalk.
> 
> I read:
>   a += 2.
> 
> as: Send the message #+= to the object named a and then name a to the answer.
> 

Me too!  I suspect a *lot* of existing Smalltalkers will read it so.

There is an interesting parallel to functional languages, by the way. 
In functional languages, := is often a function, and the left-hand-side
is a value holder.  That is, when you see  ":=" in a functional
languages it is really  more like "value:" in Smalltalk.  (And ":=" in
Smalltalk doesn't map over at all.)  The difference is whether you are
talking about the variable (:=), or about the value the variable holds
(value:).

To return to the point, the new += seems more like := than like #value:.
 The new += affects the variable, not (typically) the value.  In fact,
there are existing implementations of += that are more like #value: --
just check out implementors-of += to see 4 interesting implementations. 
Maybe we should leave += acting like #value:, and use a different syntax
for the version that acts like :=.


-Lex



More information about the Squeak-dev mailing list