in reply to Coding superstitions
That's not superstition. It's called 'defensive programming', and it's the kind of habit programmers tend to aquire after a few trips down the razor blade of life. You're adding information the compiler doesn't need, but so what? Programming languages aren't for computers anyway.. they're for humans.
If you want to talk about something we could eliminate, let's talk about whitespace. The compiler ignores it, except in very special cases like searching for the closing delimiter of a here document. Yet programmers wage holy wars about whether to indent braces like so:
or like so:if (&condition) { &yes; } else { &no; }
when all the compiler sees is:if (&condition) { &yes; } else { &no; }
if(&condition){&yes;}else{&no;}
And technically, those semicolons aren't necessary either (nor are the braces, now that I think about it). I always use them, though, because experience has shown that I may want to put another statement into one of those blocks, and it's easier to terminate the expression now than to go back and do it later. I always use a trailing comma in list definitions:
@list = ( 'item one', 'item two', 'item three', ## <- unnecessary punctuation );
for exactly the same reason.
High-level code is for humans. If it wasn't, we'd still be using machine code. Redundant information, which the compiler ignores, can still convey information to humans. Conventions like 'always quote string literals' and 'use meaningful variable names' make code more useful for humans, even if they don't do anything for the compiler.
Instead of worrying about whether such things are necessary, ask yourself how much they cost. So the compiler optimizes out a few tokens while it's building the syntax tree. Big deal. It's not worth retraining a habit just to save that dozen clock cycles or so. And if you personally find the code slightly more stable or readable, the payoff is worth the cost.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Coding superstitions
by VSarkiss (Monsignor) on Jan 08, 2002 at 03:05 UTC | |
by mstone (Deacon) on Jan 08, 2002 at 05:08 UTC | |
by tilly (Archbishop) on Jan 08, 2002 at 04:44 UTC | |
Re: Re: Coding superstitions
by mrbbking (Hermit) on Jan 08, 2002 at 06:57 UTC | |
by tilly (Archbishop) on Jan 08, 2002 at 07:06 UTC | |
by NoobJW (Initiate) on Jan 10, 2002 at 01:44 UTC |