Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: Control Structures

by adrianh (Chancellor)
on May 10, 2005 at 08:24 UTC ( #455463=note: print w/ replies, xml ) Need Help??


in reply to Re: Control Structures
in thread Control Structures

Both unless() and the trailing if() are constant sources of bugs in the code I see.

Depends in my experience. With newbie developers or with people new to Perl it can cause problems. Appropriately used I find they produce clearer and more readable code.

Personally I'd rather train up the developer than simplify the language.


Comment on Re^2: Control Structures
Re^3: Control Structures
by willyyam (Priest) on May 10, 2005 at 13:08 UTC

    New developers will create bugs regardless of language. It is a gift, without which they would never learn.

      New developers will create bugs regardless of language. It is a gift, without which they would never learn.

      To put my devil's advocate hat on for a minute - new developers will create bugs, but language choice can have a huge effect on what kind of bugs.

      For example a newbie developer using a language that naturally supports iteration over containers like Perl's foreach() or Ruby's each() won't hit a whole bunch of off-by-one errors that languages like C curse people with.

      I remember very well an introductory AI programming course that I helped teach a few years back. At the same time as the students were building a GUI driven 3D block world in Pop-11 they were bashing their heads against the wall with segfaults with simple "add up a list of numbers" programs in their C based introductory programming course. No experience before or since has been a better demonstration to me that language choice really matters.

      I just happen to think that trailing if and unless() are not a major cause of problems for novice developers. Certainly not enough of a problem to remove the gain in clarity that they give to experienced developers.

        Yes, do-while is a far worse problem, which is why we changed it to loop-while in Perl 6, and redefined do-block to make it the once-through loop (which conveniently makes it illegal to put a while on it).

        I would also submit that the fallthrough of C switches falls into the category of bugs waiting to happen. Fallthrough is approximately the worst way to implement an "or". So that's not how Perl 6 will do it.

        Another control flow fixup is to unify loop variables with closure parameters, so there's no longer any weird implicit blocking of special-purpose my variables.

        Unifying switches with exception handlers will also prevent a bunch of "roll-your-own" control flow bugs in Perl 6.

        If you count OO dispatch as a form of control flow (and I do), the roll-your-own OO support in Perl 5 also contributed to various forms of bugginess. One might go as far as to say that most of the fixups in Perl 6 consist of choosing better defaults (without making them mandatory).

Re^3: Control Structures
by perrin (Chancellor) on May 10, 2005 at 15:12 UTC
    The problem with unless() is just that people get lost in double negatives and precedence. The problem with trailing if() is this.
      The problem with unless() is just that people get lost in double negatives and precedence.

      Some people do certainly but in my experience it's not a "constant sources of bugs". Certainly not enough of a problem for me to drop the improved clarity I see when the construct is used well.

      The problem with trailing if() is this.

      I'd count that a perl bug, and since perl 5.9.1 we'll get a warning for this "dubious and deprecated construct". I've never seen this in live code, and have never been tempted to write anything that looked like it. If this is the only problem then I'm not worried :-)

        I've seen it in live code, and it took a long time to figure out that was the problem. It's not worth taking the chance until Perl 5.10 is commonly used, in my opinion.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (8)
As of 2014-09-16 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite cookbook is:










    Results (156 votes), past polls