Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
++vladb! Good discussion. I think I've written (and still write, though I should know better) sloppy code for all of the reasons you mention. And it all comes back to bite me in the butt every time, because the bad assumptions I made all turn out to be wrong.

Code was meant for personal use?
At some point someone else will find out about it, start using it, maybe even modify it, and then you'll be expected to maintain it. I write handy throw-away scripts all the time, but the problem is that I never throw them away, because they're handy. And I share them with people who know just enough Perl to be dangerous. Unfortunately, when they extend my handy scripts for themselves, they do it in the same sloppy style I used in the first place, because I thought it was just a throw-away. And since I'm the resident Perl programmer, I get to fix those scripts when they break.

Code was only a temporary solution or a patch?
As people use the code and want it to do more and more things, it will grow, one feature at a time, until it is an unrecognizable blob of spaghetti that gives you a headache just to think about. Again, you'll be expected to maintain it. I've spent the last couple weeks undoing many of the mistakes I originally made with a small program that was only supposed to do one simple thing once upon a time. I used a few global variables and a few sloppy subroutines with side effects in package main. Well, you can guess what the code came to look like. Dozens of globals, dozens of sloppy subroutines with side effects, all in package main. Total spaghetti. And it had come to be used for all sorts of things I had never envisioned. Ugh.

Too lazy to think any better?
I've come to see that writing sloppy code is false laziness. I may save myself a few seconds and some design effort in the short term, but eventually I will pay ten-fold in undoing entrenched sloppiness when the program grows. If I were truly lazy, I would never write sloppy code in the first place.

I think you've hit the nail on the head in identifying some reasons we write sloppy code. Of those, it seems that they can all be prevented with a little effort except for Tight deadlines, which are generally controlled by someone other than the programmer.

I am also tempted by Cleverness. It's fun to write one clever statement that could instead be written as three straightforward, easily maintainable statements. But later on, when I try to modify clever code I've written, I've often thought, "What the heck?" and been confused. I've done that enough times to realize that readable code is better than clever code, if you ever have to modify it. Thanks for bringing up this painful (but important) subject.


In reply to Re: Confessional: why I wrote bad Perl code. by thelenm
in thread Confessional: why I wrote bad Perl code. by vladb

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 02:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found