Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: On bad habits

by tlm (Prior)
on Jun 21, 2005 at 12:59 UTC ( [id://468653]=note: print w/replies, xml ) Need Help??


in reply to On bad habits

By far, my single worst habit is making my code too terse. Typically I realize it only weeks later when I find myself needing to decipher it. When I first write it never seems too difficult to understand; this apparent legibility is an artifact, of course, but I have a hard time distinguishing it from the real thing. I'm not entirely cured of this bad habit, but at least I am aware of it.

My second worst habit is being too enamored of the whiz-bang features, the challenging syntax acrobatics, and the cool puzzles hidden in practically every programming task, which easily leads me to miss the best solutions when these happen to be boring. Again, I'm very aware of this, but in this case a cure is not even in sight.

the lowliest monk

Replies are listed 'Best First'.
Re^2: On bad habits
by Nkuvu (Priest) on Jun 21, 2005 at 16:38 UTC
    Funny, I'm just the opposite. I make my code too lengthy and comment too much.

    I used to have the bad habit of while (chomp(my $line = <INPUT>)) but a few gasps from some monks cured me of that. Amazing what even minimal peer review can do for coding practices.

      But just to clarify, the biggest problem with that code fragment is not that it's lengthy, but that it discards the last line of the file when it does not end in a $/.

      the lowliest monk

        Exactly. And this is something that I never realized until someone pointed it out to me (just never really thought about it). I was fortunate enough to never have this bite me, and got out of the habit of the fragment before it did actually cause problems.
      Verbose is fine, if it's clear and easy to read. Don't let people tell you that you must use $_ just because it's there.
        I don't have any good examples of my old bad code. But I'm referring to comments on how the Perl code is working when it is totally unnecessary. Comments like
        # Make '3' into '03' $some_value = sprintf "%02d", $some_value;
        or perhaps code snippets where it can easily be reduced -- note that this is a contrived example, because I tend to collapse my conditionals if possible (and have for a very long time). But still it illustrates my point:
        my $time = localtime(); if ($time =~ /^Tue/i) { if ($time =~ /2005$/) { print "It's some Tuesday in 2005\n"; } }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2024-03-28 09:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found