Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^6: Get a known substring from a string

by BrowserUk (Patriarch)
on Sep 13, 2016 at 12:05 UTC ( [id://1171659]=note: print w/replies, xml ) Need Help??


in reply to Re^5: Get a known substring from a string
in thread Get a known substring from a string

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.

Now, perhaps you are a webcoder

and the entire idea of code running for 8 hours per working day is an anathema; so think of it in terms of potential customers lost because your maintenance programmer friendly code causes the page load time to move from 2.75 seconds to 3.25 seconds and your impatient target audience of millennial teens are known to move on if a load takes more than 3 seconds.

How many "one more thoughts" do you need

to save the maintenance programmers during their occasional visits over the next 10 years to make up for hundreds or thousands or tens of thousands of incomplete loads per day of your middling-sized 365/24/7 commercial website?

Now consider that much of the code I write runs on tens (and sometimes thousands) of cores concurrently,

and for days and weeks at a time. 1% saving can save my clients thousands of dollars. On at least one occasion hundreds of thousands; per run. And it is not unusual for my code and algorithms to save not 1% or 10% of runtime; but frequently 50% or 80% and on occasion 96%. Ie. runtimes projected to be multiple years, now complete in weeks or even days.

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.

And finally,

everyone who has read my post and your reply -- including you -- will, barring a catastrophically short memory, now always instantly recognise the idiom we are discussing and almost subconsciously recognise its equivalence to your preferred form.

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.


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^7: Get a known substring from a string
by flowdy (Scribe) on Sep 14, 2016 at 19:03 UTC

    Good answer, I must admit. I acknowledge it, but it does not really convince me. It doesn't need to, either.

    In my job, my code is known as "flowdy's way of Perl coding", because it is full of idioms, it is compact and created with efficiency in mind (clearly this is just my version of the story). To me, it is a compromise between resource usage of perl processing it and how quick I or a colleague of mine will get a clue of what it is supposed to do months later. Since I was said that my code is touched with awe and "Uh, let's leave him the maintenance", I have begun to think twice before getting fond of some new idiom like 1+index(...).

    Idiomatic code is useful when it is intuitively understood by someone not as firm in a programing language. Otherwise, it might become a boomerang, especially when not used that often, and most especially if a considerable number of different idioms of that subtle kind is used. That boomerang might hit the employer so he regrets having hired you.

    Only if a resource usage bottle-neck is significantly shown in benchmarks and there is a specific idiom to solve it, you are completely right. Then the use of the idiom outweighs any more thought needed for recomprehension.

      Idiomatic code is useful when it is intuitively understood by someone not as firm in a programing language. Otherwise, it might become a boomerang,

      That's a crock! No idiom -- and especially not the one you railed against -- would take any half competent programmer (in any language) more than 5 minutes to understand; even if they have to look up the documentation. (Woe & shucks; the idea that a maintenance programmer might actually have to reference the documentation.)

      Heck! It probably wouldn't take more than 15 minutes to post the code here and get a bunch of replies explaining chapter and verse.

      Only if a resource usage bottle-neck is significantly shown in benchmarks...

      And that is the biggest fallacy of all.

      Billions of pounds/dollars/sheckles have, and continue to be, wasted in government, defense and private enterprises, as entire projects and all the resources they've consumed, are scrapped; because performance was left as an afterthought and by the time it was considered, it was simply too late to restructure and recode the projects sufficiently to address the problem.

      There has, to my knowledge, only ever been one project that ran too fast; a software emulator that ran DOS era games under Windows on Pentiums, that ran so quickly, the games as originally coded, became unplayable.

      Every other project I have ever been involved in, be they on mainframes, minis, PCs or servers, be they processor-bound or IO-bound, batch or interactive, stand-alone or client server; I've never heard the users say: "Oh, could you make it run more slowly please". Whereas the opposite of that has, and continues to be, de rigueur across the 35+ years I've been programming commercially.

      The practice of first world programmers, valuing their time over that of their users; their convenience over that of their users; their programming quirks, affectations and dogmas over the efficiency of the code they produce, and the productivity of their users; is the height of arrogance, and a primary driver behind the rise of outsourcing to third-world coders.


      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1171659]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-03-29 13:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found