Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Confessional: why I wrote bad Perl code.

by CukiMnstr (Deacon)
on May 20, 2002 at 20:27 UTC ( #167949=note: print w/replies, xml ) Need Help??

in reply to Confessional: why I wrote bad Perl code.

Not knowing any better?
Sometimes you just don't know any better, so you code spaghetti. And then some time later (maybe a couple of hours later, sometimes years later) you find a piece of code that does the same thing your sloppy code does, but in a more clever/clean/readable/efficient... way, and you go "whoa! Why I didn't do it like this?" Because you didn't knew any better at the time. I know I don't write "good" code at this time, but I certainly write better code today than I did yesterday (using strict, passing arguments to subs in hashes, bind()ing variables when working with DBI...), just because my wonderings in the Monastery, practice and reading have shown me better ways of doing things. And when I find a better way of doing something, I try (if I have a little time) to go back, one script at a time, and change the sloppy way to the clean way, hoping to really learn the technique. So I guess everyone still writes "bad Perl code" if they compare their code written today with the code they could write tomorrow.

just a random thought,

  • Comment on Re: Confessional: why I wrote bad Perl code.

Replies are listed 'Best First'.
Re: Confessional: why I wrote bad Perl code.
by sfink (Deacon) on May 20, 2002 at 20:55 UTC
    Very similar to not knowing any better:

    Because I am a crappy programmer
    If a good programmer thinks things through carefully before starting, then I'm not a good programmer. If a good programmer carefully reviews CPAN for existing implementations before beginning anything new, then I'm really not a good programmer. And if a good programmer implements just the features needed at a given time... well, maybe I should pick another profession.

    But that's just a small taste of how bad I am. I'll switch to a slower algorithm to avoid using a temporary variable. I abbreviate variable names to make things fit on one line. I do things in strange ways just because I heard about them or thought "I wonder if you could...", and I use the result in production scripts. I parse HTML and XML with regular expressions. Often. I write code that I know won't work when given filenames with spaces. I'll sometimes keep using code because I'm proud of how little time it took me to write the initial (almost) working version. I'll use C instead of C++ because C compiles faster (so I can get back to gdb faster). I'll use Inline::C for something that would be easier to write as straight C, just because I feel like using perl. I'll spend two hours optimizing code that I plan to run once, where the initial version would have finished in half an hour. I'll rewrite efficient, elegant code because I couldn't understand the algorithm in the original, and end up with a sloppier version of the same algorithm. And then I'll use my inferior version when the time comes to plug it into the rest of the system.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://167949]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (2)
As of 2020-02-23 08:39 GMT
Find Nodes?
    Voting Booth?
    What numbers are you going to focus on primarily in 2020?

    Results (102 votes). Check out past polls.