Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

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.

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://455463]
[Corion]: Hi marto!
[marto]: Hey Corion, how are things?
[Corion]: Fine! It's amazing how productive I can be with a 3hour daily workload removed :)
[Corion]: My to-do emails level is at a 12-months-low of 21 , from 36 last week ;)

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (11)
As of 2018-05-24 07:22 GMT
Find Nodes?
    Voting Booth?