Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
my %hash1; #Hash for stuff my %hash2468; #hash for even nos my@blahblah; # Is this even necessary? my %someOtherKindOfHash; # Maybe stuff here my %h3; #you might want this hash, too.

That is a complete mess of a declaration of global variables. Yet, I see this over and over in code I'm given. Instead, why not do something like

# Predeclared hashes. Used throughout the script. my %hashForStuff; my %hashForEvenNumbers; my %hashForEvenMoreStuff; my %hashThatIThinkIMightNeed; # Is this even necessary? # my @blahblah;

I like your post in general, but have one thing to say to this: Noooooo!

Take a look at what you're replacing this with. It's even worse then what you started with. "hashFor" is just 7 characters that repeat "%". No gain except making every expresion that they appear in that much longer. And longer code is harder to understand then shorter code that does the same thing (in general). The mind boggles when it sees long things. The fact that much of the code isn't really doing anything but telling you what you already know doesn't come into effect until later. It's the same reason that obvious comments make unreadable code.

A good replacement might be:

# Globals my(%stuff, %morestuff); my %evens; #For even numbers # Some other stuff that I don't feel like manualy coppying # and then making a comment because mozilla's copying seems # to be broken (or perhaps I am)
Everything is grouped by use, names are descriptive, but no longer then is acatualy useful.

However, both of us are missing the real problem here. To quote Linus: "To call a global function 'foo' is a shooting offense". WTF is "stuff"? Telling the reader what stuff is is an absolute neccessity. You should always be able to tell what a varaible should contain, and with container varibles, by what it's indexed. If %evens is "for even numbers", why isn't it an array in which only even indeces are used? Perhaps "for even numbers" isn't really what the author meant, but rather "of even numbers".

I reccomend everybody read Linus' coding standards. Not because I think Linus is a God, but because they're damm good coding standars. (If you don't have the kernel source on your box, BTW, look at the Linux Cross Reference.)

Thanks,
James Mastros,
Just Another Perl Abbot

In reply to Re: Maintainable code is the best code by theorbtwo
in thread Maintainable code is the best code by dragonchild

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

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

    How do I use this? | Other CB clients
    Other Users?
    Others exploiting the Monastery: (6)
    As of 2020-10-30 11:21 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      My favourite web site is:












      Results (278 votes). Check out past polls.

      Notices?