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

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