Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
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).

In reply to (ichimunki) re: Juniper Router Audit by ichimunki
in thread Juniper Router Audit by cleen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (4)
As of 2024-03-29 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found