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.
| [reply] |
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,
| [reply] [d/l] [select] |