in reply to Re^3: Complex conditional sort
in thread Complex conditional sort

but that's one of the most important things to be familiar with when dealing with sorting in my opinion. Especially the <=> and cmp operators.

Only those. Again, Perl makes no guarantee as to what the others return. It's definitely not important to be familiar with what they return as they can return anything true and anything false. In fact, they don't always return the values you think they return.

I'd probably choose using the >0 test.

Same exact problem as negation.

Replies are listed 'Best First'.
Re^5: Complex conditional sort
by wind (Priest) on Mar 09, 2011 at 19:27 UTC

    I figured you'd say that. I hear ya when it comes to perl not "promising" any particular return value. But can you name any example where !!$test doesn't return 1 or ''/0 currently? And do you really think it's likely that's going to change?

    Obviously, for safety sake with future versions, it probably is better to rely on documented return values instead of assumed current implementation. However, it seems a little silly to me to be that wary of something so basic changing. I wouldn't have been the only person to occasionally take advantage of observed behavior instead of only relying on documented. To future ill or not.

      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.

      * —

        True, thank you for clarifying your concerns.

        I also totally agree against the anti-golfing proclivities. I will gladly use excessive parenthesis () instead of relying on detailed knowledge of order of operations. However, I feel that use of !! is one of those border cases where it might help for more people to be aware of its use. I'm happy using the ternary operator ?1:0 to be more clear though if I feel that's what's necessary.