A good approach is to start from the place that your code could be either bad or good. Once it actually works, as in, solves the problem, realize that that's the most important thing.

Ask yourself how clearly visible the solution logic is. If your program flow jumps right out at you and doesn't need explanation, it has a chance at being good code. Ask your cow-orker if he/she can see it as clearly and explain it.

Then, as has been posted, go find some samples of other code and try to understand it. It doesn't matter if the code is considered "good" or "bad", only that it's somebody else's. Pay attention to your own internal conversations while looking over the code. What questions are you looking to answer?

One of the problems inherent in looking at other peoples' code is that everybody's idioms are different, and everybody's "working subset" of Perl is different. Code that's a natural for an OO Perl addict is obtuse to someone from the dark ages (like me) who thinks parentheses have their uses and IF should come before THEN.

More important than syntax is to understand the various patterns of coding in modular fashion. Here's a good exploration to start with. It's more important to learn how to approach a problem in an analytical manner than it is to learn from the bottom up what "good code" is, although writing code that mirrors the flow WILL help you maintain your program DTR.

Bad code -- or rather, the maintenance of bad code -- does teach one a lot. I've had the good fortune of being asked to maintain both good code and bad (hey, I did get paid to do it!), and both experiences have helped me greatly. I've also had to go back and look at my own work many a time, and the view from after another turn of the spiral always yields more insight. "Good code" is such a moving target. Good code is code that works and can be understood by another, no matter what set of idioms it uses. Elegant code is in the eye of the beholder, and, once again, it's more in the problem solving approach than it is in the details of the code.

Of course, doing your best to emulate good code writers will get you much further than hanging with slackers! < grin > :D

In reply to Re: Does bad code really teach you to write good code? by samizdat
in thread Does bad code really teach you to write good code? by Gekitsuu

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.