[Python-3000] default argument surprises

Bruce Leban bruce at leapyear.org
Wed Aug 27 08:47:00 CEST 2008


On Tue, Aug 26, 2008 at 9:23 PM, James Y Knight <foom at fuhm.net> wrote:

> On Aug 27, 2008, at 12:14 AM, Chris Monson wrote:
>
>>
>> And I think that metaphor is easy to read. Chains of else operators can be
>> useful:
>>
>>   x = f() else g() else h() else 0
>>
>> Not a bad idea.  Looks like the time machine is at work again:
>>
>> x = f() or g() or h() or 0
>>
>
> Well...no. "else" here is significantly different from "or": it only tests
> for None, not falseness.
>
> Correct.

>
> Although, maybe you just meant that "else" and "or" have such similar
> behavior, and their names do not obviously distinguish their behavior. And,
> thus, people would find them confusing, so "else" should not be added to the
> language. That I could agree with.
>
> Unfortunately, I agree that it's confusing because else implies a boolean
value. It doesn't mean that some other analog for the ?? operator wouldn't
be useful. Alternatively, an analog for just the ??= operator would
explicitly address this case:

    arg floob value
is
    arg = value if arg is None else arg

although I'm sure there's a better word than floob. The downside of floob is
that it only addresses this case so not a very convincing argument.

--- Bruce
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-3000/attachments/20080826/e7a1e5f6/attachment.htm>


More information about the Python-3000 mailing list