Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re^4: Regex Or Die! (!unless)

by shmem (Chancellor)
on Oct 02, 2006 at 16:27 UTC ( [id://575904]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Regex Or Die! (!unless)
in thread Regex Or Die!

The "not" that is implicit in "unless" is subtle enough that it can get "lost" when you are looking at code.

I never had that problem. For me, the "not" cannot be lost, because without it it's not unless any more.

This shows that not only shouldn't you use "unless" even for simple conditionals, but shouldn't even consider using "unless".

No, it does not. That's an undue generalization. You may not advocate the banishment of a language construct as a general rule just because "quite a few" got "burned by it now". There's no count of those which never got burned by using 'unless', and which are quite comfortable using it as a statement modifier or a control construct in the sense perlsyn states:

"if" executes the statement once if and only if the condition is true. "unless" is the opposite, it executes the statement unless the condition is true (i.e., if the condition is false).

Subtleties in the english language regarding 'unless' are irrelevant and must not be stressed to daemonize it's use. After all, we're programming perl, not writing english statements.

--shmem

_($_=" "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^5: Regex Or Die! (less)
by tye (Sage) on Oct 02, 2006 at 23:21 UTC

    I'm not banishing unless from Perl. But I have a collection of 'best practices' for writing highly maintainable code and not using unless is one of those.

    I never had that problem.

    And I said that my experience is that people won't "get it" if they haven't seen it. You don't have to try to learn from my experience of having done this and having seen other people do it several times. I didn't see the problem with unless until... I personally saw the problem with unless. (Well, I, like many of us, quickly saw that unless should be avoided in many situations; but I didn't initially see the problem with using it with very simple expressions.) The problem is subtle but the effect is maddening.

    No, it does not. That's an undue generalization.

    You dropped my smiley. Unwad your panties.

    Subtleties in the english language regarding 'unless' are irrelevant and must not be stressed to daemonize it's use. After all, we're programming perl, not writing english statements.

    I wasn't the one who brought the English language into the argument. The English language was used to justify the use of unless in Perl and I countered that argument. You can't banish the use of the English language in an argument about a programming language whose keywords are mostly English words. Besides, the problem with unless have much to do with the use of "unless" in English. Really. So you can tell me that I "must not" make my argument and thus demonstrate that you didn't understand my argument, but I will continue to try to express this difficult-to-express point whether you think my methods should be banned or not. I explained why it is relevent. You can declare that "it is irrelevent" but you'll have to back up such a declaration with more than "we aren't writing English statements". My argument never hinged on being confused that I thought we were writing English statements. My argument is about the word "unless" and subtle ways that it impacts comprehension (by English-speaking programmers) of code that uses that word.

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

    There's no count of those which never got burned by using 'unless', and which are quite comfortable using it

    I counted as one of those. Now I know better. The people I've seen burned by this were quite surprised when it happened. It took a while to even realize that there was a pattern to this. I don't think that there are two types of people in the world, those who understand unless and have no problem using it and those who have difficulty understanding it. It isn't even in the same ballpark as rocket surgery to understand that, in Perl, "unless" just means "if not".

    Anyway, in case you didn't notice, I got a chuckle out you responding to my use of "shouldn't" (in one sentence with a smiley attached) with declarations that I was trying to "banish" and then you using phrases like "you may not" and "must not". I forbid you take this so seriously, henceforth. q-:

    - tye        

      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.

      cheers,
      --shmem

      _($_=" "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}

        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?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://575904]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (8)
As of 2024-04-20 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found