chromatic has asked for the wisdom of the Perl Monks concerning the following question:

Which do you prefer, shorter code using shortcuts, or longer code that avoids tricky one-liners but is much easier to read right off?

My take is that it depends. For quick, one-off scripts where I'm the only one ever to read the code, the quicker and shorter I can do something, the better.

For stuff that I'm making public, or that I'll pass off on someone else, I'll sacrifice a few shortcuts for readability, or, at least, write a couple of lines of comments to explain my hackery.

Replies are listed 'Best First'.
Re: Terse or Self-Documenting Code
by stephen (Priest) on Jan 22, 2000 at 15:06 UTC
    My rule is: if the code will live for more than 24 hours, it must be self-documenting. If another human is going to read the code, or myself in 24 hours after I've forgotten what I was doing, the code must be comprehensible. I've inherited too many pieces of code which might have been PGP signatures for all I could tell. I refuse to inflict that sort of suffering on others.
Re: Terse or Self-Documenting Code
by jdube (Initiate) on Dec 30, 1999 at 09:22 UTC
    Terse but well documented, if you do it right. Don't cut code size for speed, especially if it breaks readability, but if it is faster than the alternative (speedwise, not coding wise) I'd say go short. Don't ever expect ANYthing to be self documenting, you'd be surprised at the people out there (my C++ teacher has to ask me what an int called "counter" does when I don't document it.... UGH)