in reply to Re^5: Complex conditional sort
in thread Complex conditional sort
But can you name any example where !!$test doesn't return 1 or ''/0 currently?
Overloaded operators can do this.* I'm talking about properly written overloaded operators, not ones that try to repurpose "!". It's not an issue here and it's not likely to ever be an issue, which is why that's not the argument I chose to make.
What I did focus on is the writing of unreadable code to save one character. I find it too demanding of your reader to know that "!" returns +1 for true given the lack of cost of not demanding this knowledge.
The cost of confusion is low, but so is the cost of avoiding it.
* —
package Boolean; my $true = bless(\(my $data = -1)); # Like BASIC my $false = bless(\(my $data = 0)); use overload '!' => sub { ${$_[0]} ? $false : $true }, 'bool' => sub { ${$_[0]} }; sub boolean($) { $_[0] ? $true : $false } sub true() { $true } sub false() { $false } 1;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^7: Complex conditional sort
by wind (Priest) on Mar 09, 2011 at 21:00 UTC |