Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Welcome to the Monastery
 
PerlMonks  

Re^2: Short and easy way to write if...elsif syntax

by sundialsvc4 (Monsignor)
on Aug 27, 2012 at 14:30 UTC ( #989994=note: print w/ replies, xml ) Need Help??


in reply to Re: Short and easy way to write if...elsif syntax
in thread Short and easy way to write if...elsif syntax

To the “down-voters” among you, who may mistake brevity for lack of wisdom or experience, I invite your reconsideration.   Here’s why.

The “clever improvements” as suggested cause each of the various if cases to become coupled.   In other words, as long as each and every if-case that could possibly be required, for the entire service lifetime of this application (which could be a decade or more), is identical ... the code is “clever,” and perhaps it may look a wee bit more agreeable to the digestion.

However ...

Change will come.   Some day, a condition will need to be added that will break the rule.   And, when that happens, suddenly the code that is working properly now must be torn-apart, more or less, and recoded.   What was meant to be clever has just turned bad, and it de-stabilized all of the logic that it “cleverly” tied together.   Whereas, if the “ugly” if..elsif structure had simply been retained, no changes to any of the existing code, with its admittedly repetitive structure, would have been required.   You would simply need to add another elsif block at the appropriate point.   You can keep that up indefinitely.

Please bear in mind that I have spent most of my career in “code rescue” and project-turnarounds.   Which means that my perspective on such things is somewhat like that of a coroner.   Such “cleverness,” well-intentioned though it once may have been, after a surprisingly short amount of time attracts a large number of blowflies.   Maintainability is king, and software must be designed in anticipation of a very long service life involving many different people.   You won’t be at that job forever ... but your work will be, and someday I might be called in to have a look.


Comment on Re^2: Short and easy way to write if...elsif syntax
Re^3: Short and easy way to write if...elsif syntax
by chromatic (Archbishop) on Aug 27, 2012 at 16:20 UTC
    The “clever improvements” as suggested cause each of the various if cases to become coupled.

    (Some annoying typography elided.) How so—especially in the given/when case?

      Given/When is syntactic sugar for if..elsif.

        Perhaps I'm misunderstanding what you're saying, but given is a topicalizer, aliasing a lexically scoped $_ to a scalar's value which when operates on. The if/elsif construct doesn't create topics. Given this difference in functionality, how is given/when syntactic sugar for if/elsif?

Re^3: Short and easy way to write if...elsif syntax
by pvaldes (Hermit) on Aug 27, 2012 at 23:55 UTC

    The real problem here could be probably the choice of a hash for this work. The idea behind a hash should be that keynames are unique and not subject to small variations, like in this case.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2014-04-17 22:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (458 votes), past polls