in reply to Re^3: "my $p = value if condition()" as bad|deprecated as "my $p if 0" (Naughty indeed)
in thread "my $p = value if condition()" as bad|deprecated as "my $p if 0" (Naughty indeed)

I, for one, would enjoy hearing an explanation. Why is a block form easier to debug than the statement modifier form? What kind of bug is easier to find in one over the other and why? I'd like to see examples and rationales.

The ad hominem attack and unsupported assertions are optional. Include them if they give you comfort, but please include more than that also.

Thanks.

  • Comment on Re^4: "my $p = value if condition()" as bad|deprecated as "my $p if 0" (Naughty indeed)

Replies are listed 'Best First'.
Re^5: "my $p = value if condition()" as bad|deprecated as "my $p if 0" (maintain)
by tye (Sage) on Jan 16, 2008 at 01:05 UTC

    He didn't say that it made it harder/easier to debug. He started to mention "when you go to add". Adding debugging code is just one reason you might need to add code down the road. Having to do a transformation on the format of the code just to add a line means the code requires more work to maintain. I understand that argument and at least partially agree. If you are strongly stressing maximizing how easy the code is to maintain, then I think that added cost is worth considering.

    Of course, it isn't a slam-dunk, obvious "win" in the cost/benefit analysis in all cases. I think it is more likely to be noticed if statement modifiers are just one of many "costly" practices and they are rather heavily used.

    Of course, chromatic mentions one way that it actually does make it harder to debug. It can also make it harder to add debugging stuff if you need to add a debugging step that should go between two things that you have done in one line.

    - tye        

Re^5: "my $p = value if condition()" as bad|deprecated as "my $p if 0" (Naughty indeed)
by chromatic (Archbishop) on Jan 15, 2008 at 22:52 UTC
    Why is a block form easier to debug than the statement modifier form?

    It's often easier to set a line breakpoint in a debugger if there's only one sequence point per line.

    Of course, a good debugger gives you more options for setting breakpoints than just "When execution reaches this line," so it's a slight reason.