Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

(ichimunki) re: Juniper Router Audit

by ichimunki (Priest)
on Feb 27, 2001 at 20:42 UTC ( #61098=note: print w/ replies, xml ) Need Help??


in reply to Juniper Router Audit

Sadly, I can't comment on much here except for some stylistic issues. And I'll chip in these two bits, just because this is what struck me as I looked at this code and recalled both my own experiences with similar things and some reading I've been doing lately on the practice of programming. Of course, this script was probably written quickly for a specific purpose, and I don't doubt that it works well. But if it comes time to change this in a few months, or if someone else is going to adapt it or use it, the structure of the code is going to be an obstacle.

The deeply nested "if-else" and looping structures do a lot to obscure the logic behind this program. In more than one instance there is an "if" followed by another "if", neither of which takes an "else" case. It is much clearer in these case to use an "and". Likewise, many of the condition branchings could be probably be eliminated by similarly using "and" and "or" instead of nesting.

Following this thought, I've also got a bias towards moving functionality into smaller routines of 5-25 lines and calling those from within branches and loops as much as possible. This assists the reader in understanding the code more than it assists the machine in being fast, but this is Perl, so speed is not our primary concern. Done this way, each level of routine reads quickly (like an outline) and I don't need to keep mental track of any more details than necessary. It may eventually mean less work for the programmer as well, since the functions will be easier to test in isolation... and comments become almost unneeded-- the code becomes self-documenting.

Again, these are just my thoughts, and I don't want to seem overly critical. I find myself programming this way all the time for shorter scripts, but it seems like taking a few minutes to do some higher level planning, even writing pseudocode for the main body of the program, can often save some real headaches when the script starts to get bigger than the screen (and more likely, starts to get bigger than my brain can manage to keep track of).


Comment on (ichimunki) re: Juniper Router Audit

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (2)
As of 2014-09-21 03:14 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (166 votes), past polls