Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^6: Regex Or Die! (less)

by shmem (Canon)
on Oct 03, 2006 at 22:26 UTC ( #576202=note: print w/replies, xml ) Need Help??

in reply to Re^5: Regex Or Die! (less)
in thread Regex Or Die!

Duh! take two of them :-) :-)

It might be due to me not being a native english speaker that I can't grasp what's the problem with 'unless'. So I looked up the term and... aha: 'unless' translates to 'if not' and 'except if'. Is that the root of the problem? Thinking 'unless' as 'except if' and dropping the 'except'?

You must not use emotionally charged words like "daemonize" to mischaracterize my educating people about my experiences and attempting to explain my best practices.

You're right, I must not use the word 'daemonize' when I mean 'deprecate'. But you may be wrong in thinking that your experiences serve other people to educate themselves, if you don't expose these experiences. I would highly appreciate some pointers to how people got hit by using 'unless', some 'real code' examples showing the whole process of tripping into the trap, getting hurt, licking wounds and healing towards using 'if not'. Surely those examples would give an insight into yet another weird corner of english thinking (you can't learn a language properly if you don't give in to think in that language). As I already stated, 'unless' for me is nothing but 'if not', and if the keyword in perl wasn't 'unless' but 'nif', it would be the same for me.

I forbid you take this so seriously, henceforth. q-:

I hardly do so ever, honest. But sometimes I indulge in grave sounding. *sigh* that discussion about 'to unless or not to unless' is going some time now, and I see neither an end nor any benefit coming from it.


_($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                              /\_¯/(q    /
----------------------------  \__(m.====·.(_("always off the crowd"))."·
");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}

Replies are listed 'Best First'.
Re^7: Regex Or Die! (more)
by tye (Sage) on Oct 04, 2006 at 00:45 UTC

    The most recent example went something like:

    my $val= 48.6; if( $val < 50 ) { die "..."; }

    followed by "Why does this die!??"

    The "if" is a structural element and so it is easy to tune out some details of it when concentrating on the code. In this case, the author tuned out that it wasn't an "unless" like they had originally considered writing.

    It reminds me of the doors with identical handles on both sides and "push" and "pull" labels when they should either have handles that facilitate just pushing / pulling on the appropriate side or just open both ways (and should never have labels). When you go through a door, your goal is what is on the other side and you tune out the mechanics of the door, and a label doesn't help much here (even though "push" and "pull" labels seem obvious and clear). A label on the door that says "Dept. of Waste Management" works great, however.

    Or, another way to look at it is having a label on a door that says "all services except Dept. of Waste Management here". Perl code is about "what to do next"; it is all about "now" and actions. Trying to use parts of English that are about "not now" and "actions to avoid" doesn't mix as well.

    The times I've seen this problem "fire", it was very similar to the example above. It was quite simple code and the programmer (usually also the author of the code) goes over it again and again trying to figure out why the conditional is/isn't firing when it shouldn't/should be... to the point of exasperation.

    So examples of actual code really aren't very interesting or useful in understanding the problem, other than to see that the code is trivial or nearly so.

    BTW, I don't see the distinction between "if not" and "except if". One negates the conditional and the other negates the action, so I'm not sure why you'd see one negation as easy to "lose" while the other is "impossible" to lose. Oh, I guess negating the conditional fits Perl code while negating the action doesn't, if that was your realization.

    For me, I agree with the many who have said that combining complex conditional expressions with "unless" is a bad idea. And I find "if not EXPR" just as easy (and smooth) to read as "unless EXPR" so I see no reason to use "unless" for the case of a simple expression (they mean the same thing, as has been pointed out over and over). That leaves me with no reason to ever use "unless" and several reasons (some subtle) to not use it.

    As the years go by, I find more and more that a conservative "taste" in code design is very likely to pay off in the long run. A lack of "KISS" has become "code smell" to me.

    and I see neither an end nor any benefit coming from it.

    I see some getting upset (to the point of making snide remarks about it in other threads) but the existance of a cranky, noisy minority(?) doesn't mean that there isn't a silent majority(?) that can accept information without feeling attacked. (: Since it hasn't turned into a flame war from my perspective (I feel quite calm and jovial at the moment), I don't mind trying to explain better when asked. Though, if I can't come up with any ways of expressing this that I don't feel I've already done a reasonable job of presenting, then I won't repeat myself endlessly. So I don't see why there shouldn't "be an end" (I certainly don't expect to have "an end" where everyone agrees).

    Oh, and I'm not even trying to deprecate "unless". The lack of "use strict" has not been deprecated (as in, at some future point it will become impossible to have strictures disabled). I'm explaining why some may choose to avoid using "unless", at least in certain types of code. "Avoid" doesn't even mean "never"; it more means that you have to have an unusual reason to justify using it (in the described situations).

    - tye        

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://576202]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (4)
As of 2017-02-25 14:56 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (365 votes). Check out past polls.