in reply to Re^4: Radoteur
in thread Radoteur

I read in Perl Best Practices that whenever last or next are used adding labels helps will the readability

If you are prepared to pay a 15% performance penalty for that asinine piece of advice; continue:

cmpthese -1,{ a=>q[ LOOP:for(1..1000){ next LOOP; } ], b=>q[ for(1..1000){ next; } ] };; Rate a b a 7862/s -- -14% b 9195/s 17% --

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

Replies are listed 'Best First'.
Re^6: Radoteur
by QuillMeantTen (Friar) on Oct 20, 2015 at 12:18 UTC

    In simple and obvious code I agree, but right now I am trying to educate myself so I can work on intricate code without making a mess.
    You are entitled to your opinion concerning this practice. I feel that sometimes sacrificing some performance to ease of maintenance might be the way to go

    Yeah, in the code I posted it isnt useful, the loops are quite obvious and so are the concepts behind the algorithm. I'll agree with you that it is a waste of ressources and the same effect could be obtained with comments.
    Please bear in mind that I am not as experienced as you are and as I learn I try and apply what I consider to be best practices everywhere so I naturally start thinking that way first before choosing performance over readability.

      In simple and obvious code I agree, but right now I am trying to educate myself so I can work on intricate code without making a mess.

      Actually, “intricate” code is a mess, almost by definition! Putting performance to one side for the moment, the best way to avoid writing spaghetti code1 is by keeping things as clear and simple as possible. Structured programming was first proposed precisely for this reason; and the Perl next and last commands violate the (original) structured programming maxim that every loop have only a single entry point and a single exit point.

      Does this mean you should avoid next and last when programming Perl? No, they’re too useful — and, when used judiciously, they actually make the programming logic clearer (to a seasoned Perl programmer, anyway). But when nested loops begin to intertwine their control flow, spaghetti code is likely to be the result. And the need for multiple loop labels is a strong warning sign that control flow may have become too complicated.

      So, by all means use labels on loops when it makes sense to do so. But please don’t assume that doing so equates to “ease of maintenance” — it may all-too-easily lead to the exact opposite.

      1Also called write-only code, since it is unmaintainable.

      Hope that helps,

      Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,