Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re^4: Improving if statements

by SuicideJunkie (Vicar)
on Sep 19, 2014 at 15:15 UTC ( [id://1101227]=note: print w/replies, xml ) Need Help??


in reply to Re^3: Improving if statements
in thread Improving if statements

Why make the job harder by adding a large pile of additional potential typos?

There are always cranks to complain about everything. That doesn't mean you shouldn't try to do things well. Someone will complain no matter which side of the utensil drawer your spoons are on, but that doesn't mean you should throw them in randomly.

When things get a bit more complicated, then you add to the data structure. Instead of a simple hash of lookups, have a hash of hashes which include the lookup value and a type. When you have a one-off exception case, add a new type, and handle that. If it isn't a new type of thing, then you trivially add it to the list of things to check instead of copying a block of code.

This is what requirements and experience are for. Keep it simple with a fixed block and save time now, or make it flexible as an insurance payment now to protect against future additions. For best results, keep the flexibility options in mind while you write the simple case, and make it modular enough that refitting flexibility in later is as easy as tacking an elsif condition on. Either way you go, you don't need to repeat yourself if you use the right data structure.

You don't have to compromise quality or maintainability on this one.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-20 01:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found