Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

I didn't believe this until I personally hit it and now I've hit it personally more than once (even after I've been aware of the potential) and I've seen others hit it. And it doesn't even take two variables. The "unless" can make the "not" blend into the background and you can go over the code 5 times trying to figure out what is wrong and not realize that you've got one too few or too many implicit "not"s involved.

There are lots of possible implicit "not"s. You can have an implicit "not" because your variable is called $disabled. You can have an implicit "not" because you are using < instead of >= or such. You can have an implicit "not" because the object lets you ask "are you empty" when you want to ask "do you have any members" or vice versa. Then you can have explicit "not"s (or "!"s).

But the "not" implicit in "unless" is just too subtle and is too easy for your mind (if you are over 40) to drop. And you should try to never have more than one implicit "not" per conditional. But you are likely to not notice the other implicit "not"s when you are writing the code. Or the implicit "not" may not be there when you write the code because you are thinking at it from one direction but the bug forces you to think at it from another direction (which may partially explain why you've got a bug there).

I also dislike swapping out keywords when maintaining code. So I dislike changing "if" to "unless" or vice versa when a conditional is adjusted. Phrase the test so it works with "if" and is as clear as possible, and if that requires that you add a not, then add an explicit one. "if not" will be less likely to confuse you than "unless" when you are agitated trying to debug something and it flows just as well even if you are trying to make your code read like lovely prose.

So avoid the one sure source of an implicit "not": unless. Remove it from the language? Well, I wouldn't miss it, but having it in the language doesn't bother me. It can be useful in obfu and poetry, anyway.

- tye        


In reply to Re^3: Useless <c>unless</c> (subtle) by tye
in thread Useless unless by GrandFather

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (6)
As of 2024-04-19 06:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found