default args (was Re: Any reason for assigning block parameter
in inject:into:)
nicolas cellier
ncellier at ifrance.com
Sun Apr 29 15:46:55 UTC 2007
Yes i understand that, behaviour is in a single method, all others are
wrappers.
But:
- all others do hold a copy of the default values.
- they are 2**N
So imagine you want to change a default value, or you want to add
another argument...
Unless wrappers pass nil, and core method implements
'var = var || default' nonsense:
realValue := argValue ifNil: [defaultValue].
Nicolas
J J a écrit :
>> From: nicolas cellier <ncellier at ifrance.com>
>> Reply-To: The general-purpose Squeak developers
>> list<squeak-dev at lists.squeakfoundation.org>
>> To: squeak-dev at lists.squeakfoundation.org
>> Subject: Re: Any reason for assigning block parameter in inject:into:
>> Date: Sun, 29 Apr 2007 15:00:02 +0200
>>
>> However, this pattern should be limited to very few optional args,
>> because N optional args make (2 raisedTo: N) different messages.
>> That's a lot of code to maintain.
>>
>> Nicolas
>
> You're over-stating this. It's simple. You provide the base method
> that takes all options and one method for each different interface to
> that method you provide. And this approach certainly scales better then
> setting the defaults by hand, although Python style defaulting would be
> less typing.
>
> 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.
>
> [1] IMO, this is the superior method for a dynamic language because the
> others require runtime checks to be done every time the function is
> entered, while this way it is only a compile time check.
>
> [2] This is certainly better then having to manually type out every
> default case, but (afaik) it is still a runtime check for a dynamic
> language.
>
> _________________________________________________________________
> The average US Credit Score is 675. The cost to see yours: $0 by
> Experian.
> http://www.freecreditreport.com/pm/default.aspx?sc=660600&bcd=EMAILFOOTERAVERAGE
>
>
>
>
More information about the Squeak-dev
mailing list
|