Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: Understanding this code

by sundialsvc4 (Abbot)
on Sep 28, 2015 at 14:10 UTC ( #1143246=note: print w/replies, xml ) Need Help??

in reply to Understanding this code

My simple advice to you would be:   “This is Golf.”   As in, “write-only code.”   Simply re-write the damn thing into something that you, and any and everyone else who will in due time follow you, can understand and maintain.

(Incidentally, I would say this about any such piece of code, no matter who the author was, and I would also not be speaking personally against the author in saying this.   To me, it is simply an engineering question.)

I believe quite strongly in “The Glance Rule.™”   Source-code should be written in such a way that it can be reliably and accurately understood “at a glance,” by anyone who is moderately(!) versed in the language.   If the reader has to “puzzle out” the meaning of the code, however briefly, or to post a question on PerlMonks seeking explanation, it should just be rewritten.   Such code often turns out to be rigid, costly to maintain, and sometimes actually slower.   Dozens of people over an equal number of years might touch that code before it is retired, if ever it is, and they are usually doing so in order to change what it does, not to fix it or further improve upon it.   “Code accordingly.”

Replies are listed 'Best First'.
Re^2: Understanding this code
by GotToBTru (Prior) on Sep 28, 2015 at 14:47 UTC

    If you can't understand it, how could you re-write it?

    This code might possibly be daunting at first glance, but someone moderately versed in Perl would have no trouble parsing it. This is practically self-documenting. "Record all the values between the value of an element and the value of the next one, for every element in the array (except the very last)."

    Dum Spiro Spero

      My goal would be to avoid having such code be put into the system in the first place.   If the way that the code is written is such that it is “daunting at first glance,” there surely must be another way to write it.   This other-way might be more efficient or it might be less, but in the long run it will be more maintainable, and that is the factor that is most important to me.

      Over the (very ...) long lifespan of a production system, many of its algorithms will have to be changed, and these changes can “ripple” almost anywhere through the source-code ... leading developers into new areas, where they might find obtuse code (and little documentation) which they must now change without breaking something else.   If they “do it wrong,” however slightly, they might introduce new errors and not know it at the time.   The time spent “figuring out” is time lost, and the risk associated with code that is “risky” is an unnecessary risk (and cost) to be avoided at all costs.   Simplicity, and the “glance rule,” saves money and reduces risk.

      And, yes, this viewpoint stems from what has been the primary focus of almost my entire career:   project turnarounds, and legacy code.   I See Dead Projects.™   When you see “code like this” that has been around a while ... it isn’t pretty what has happened to it.   Nor what it costs the company.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2019-04-23 02:02 GMT
Find Nodes?
    Voting Booth?
    I am most likely to install a new module from CPAN if:

    Results (114 votes). Check out past polls.