default args (was Re: Any reason for assigning block parameterin inject:into

J J azreal1977 at hotmail.com
Mon Apr 30 04:43:03 UTC 2007


>From: "Lukas Renggli" <renggli at gmail.com>
>Reply-To: The general-purpose Squeak developers 
>list<squeak-dev at lists.squeakfoundation.org>
>To: "The general-purpose Squeak developers 
>list"<squeak-dev at lists.squeakfoundation.org>
>Subject: Re: default args (was Re: Any reason for assigning block 
>parameterin inject:into:)
>Date: Sun, 29 Apr 2007 17:39:54 +0200
>
>My example was a bit JavaScript biased, but wh about something like that?
>
>aString := aString asUppercase.
>aNumber := aNumber asInteger.
>...

Yea, ok, that does make more sense.  I guess I just get nervous when someone 
appears to me to suggest that we need something that other languages have to 
have due to design issues.

Not that I have anything against JavaScript, I hear it is quite flexible in 
many areas.  It just sounds like default argument situations is not one of 
those areas.

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

I usually see (and use) this for doing lazy initialization of ivars, I 
haven't seen it for defaulting method arguments.

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

Selector prefixes?  You mean the technique of providing shorter methods 
which call the main method with default arguments?  It is just a pattern, no 
pattern makes sense in every possible situation.  A few default-able 
arguments is very manageable.  More then that and one would probably want 
some other pattern, not default arguments at all.

_________________________________________________________________
MSN is giving away a trip to Vegas to see Elton John.  Enter to win today. 
http://msnconcertcontest.com?icid-nceltontagline




More information about the Squeak-dev mailing list