default args (was Re: Any reason for assigning block parameter in inject:into:)

Lukas Renggli renggli at gmail.com
Sun Apr 29 15:39:54 UTC 2007


> I think JavaScript et al. need that because they don't have method
> overloading or keyword arguments like Smalltalk does.  The patten
> mentioned below simply isn't needed.

My example was a bit JavaScript biased, but wh about something like that?

aString := aString asUppercase.
aNumber := aNumber asInteger.
...

> > Languages like Smalltalk can use keyword arguments for default arguments
> > [1], languages like Python use special default argument syntax [2] and
> > languages that were not designed as well (at least in this area) have to
> > rely on 'var = var || default' nonsense.

In Smalltalk this literally translates to

    var := var ifNil: [ default ]

This is rarely used in Smalltalk, however it is very similar to:

    var || (var = default);
    var ifNil: [ var := default ]

> Nicolas is right, this gets real messy, real fast. See Seaside:
> Canvas <-> HtmlBuilder

Not just there, there are many other examples where framework
designers had to rethink that approach because it stopped to scale.
That's probably also a reason why there is the 'move method'
refactoring. Selector prefixes for default arguments simply do not
scale.

Cheers,
Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch



More information about the Squeak-dev mailing list