Select wisely the idioms you use.
Believe me, I do!
I, for one, would not use that one because I find it is just for the sake of brevity without its being worth one more thought every time it is read.
So you optimise your code in order to save the maintenance programmer, "one more thought", during each of his occasional visits over the future life of the code.
Say that "one more thought" requires 5 seconds; or 10, and the code stays in use for 10 years and the maintenance programmer visits it one every 6 months, or three; over the lifetime of the code you've "saved" a maximum of 400 seconds (0.11 hours) of programmer time.
Now. let's say that the difference in performance of that one usage, is 1% on the overall runtime; and over that 10 year lifetime the program runs for 8 hours a day every work day for those 10 years, then you have cost the users of that program 208 hours of their time. The owners 208 hours of extra processor wear, electricity and air conditioning costs.
Now lets say there are 3 uses of that idiom; and half a dozen uses each of half a dozen other efficient idioms that you reject; and the difference in runtime isn't just 1% but 25%.
Now your "potential" savings in programmer time over 10 years becomes 1236 seconds, A whole 20 minutes!
But your cost to the users and owners is: 5000 hours! Of user time, cpu resource, energy.
And these are not one-offs, but regular gigs over the last 15 years -- I've made a pretty good living at it. And beyond the occasional novel algorithm, a large part of that work has been underpinned by writing what is often fairly prosaic algorithms as efficiently as Perl allows. Ie. Using Perl to its best effect.
That is the very purpose of, nay even the definition of, "idioms". They are 'patterns of usage'; short forms of more complex code that, with regular usage and familiarity become as recognisable as the languages native constructs. They become as a part of the language to those who have taken the time to become familiar with them.
If your Perl code is used as a training aid -- you're a teacher, lecturer, or book writer -- then your "optimise code for the casual reader, newbies and maintenance programmers" stance has some merit; otherwise it is the very definition of premature (naive, unfounded, illogical and thoughtless) pessimisation.
In reply to Re^6: Get a known substring from a string
by BrowserUk
in thread Get a known substring from a string
by jake7176
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |