if your code works and you can maintain it, don't worry too much about how it looks. You'll improve the more you write.

As someone who's been really scared by some of the stuff he found today (perl coded I wrote circa 1994/5), I'll agree with this, especially if you're actively trying to improve all the time.

One thing I'd say though, is leave yourself some comments. I looked at some of my 1994 code today and couldn't work out at all what it was meant to be doing!

Aside: It's fascinating seeing how style has changed over this time too. And not just my style - perl style in general. In my perl directory were some scripts by TomC and Randal that just look so dated now. Yes, a lot of this was down to them being in Perl 4 rather than 5, but I think there's been a significant shift in what code looks like over time as well...

On the other hand, I'd like to emphasise that this approach can only work when *you* are the only maintainer of the code. Code should always be developed with future maintainers in mind. If that's guaranteed to be you, then do whatever, but if it's likely to be someone else, then an entire different set of rules come into play.

Then you're into good structure, proper comments, use (strict, warnings, taint), sensible variable names, documentation (good comments + "self documenting code" != documentation), even, dare I say it, testing!

Fortunately Perl is a great language for all of these things! And luckily it's a great language for refactoring too, so if you're stuck with maintaining really bad code, it's easy to improve it a bit at a time.

Have fun!

Tony


In reply to Re: Bad Code / Ugly Code by salvadors
in thread On the Road to Perl Enlightenment, My 100th Post, and New Year's Resolutions by coreolyn

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, details, 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, summary, 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.