Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

(ichimunki) re: Juniper Router Audit

by ichimunki (Priest)
on Feb 27, 2001 at 20:42 UTC ( [id://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).

Log In?

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (3)
As of 2024-04-18 01:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found