develooper Front page | perl.perl5.porters | Postings from September 2008

Re: unless(...) terser than if(!...)

Thread Previous | Thread Next
From:
Vincent Pit
Date:
September 7, 2008 17:00
Subject:
Re: unless(...) terser than if(!...)
Message ID:
48C46BE8.3060001@profvince.com

> On Sun, Sep 7, 2008 at 4:59 PM, Nicholas Clark <nick@ccl4.org> wrote:
>
>   
>> But I feel no such qualms about a major release - using overloading to make
>> your value both true and false strikes me as crazy. Really anything that
>> deliberately has implementation inconsistencies between semantically equivalent
>> actions (such as $a = $a + 1; $a += 1; ++$a;) is in my mind bad practice and
>> foolhardy to rely on in perpetuity.
>>
>> Nicholas Clark
>>     
>
> But the thing about operator overloading is, coming from C++, the idea
> is to use the existing syntax for things that are totally different,
> for instance the bitwise shift operators in C++ getting used for
> stream IO.
>
> It's easy to imagine  someone overloading prefix bang to mean, for
> instance "ALL CAPS" knowing that unary not is never going to apply to
> their string object class.
>   
You can't keep the pie and eat it.

If one gives a special meaning to "!", he can't really expect to have it
keep its behaviour in boolean context. In your example, I don't see why
you would test the truth of !$x if you expect it to return something
else than "the logically contrary of $x".




Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About