Tuesday, June 20, 2006

What will we reap ?

Been reviewing more code, both officially (for those who work in the same cubicle farm) and unofficially (trying to use some free stuff).

In the midst of some excellent code down on the farm and I came across this wee gem:

if found == True:

Ouch !

If it was within the free stuff, I would have snickered and moved on. But this wasn't just reading some code, this was "A Review", and I've been reading for well over an hour at this stage.

And now I have to go back over that again, because you've just proved you don't understand the language, and I've been giving you the benefit of the doubt so far.

At least it wasn't followed by

elif found == False:

or, even worse is the old cliché:

if ( FALSE == found ) {

Change of syntax to protect the innocent - never actually seen that one in Python. It's primarily a C++ cliché. (And if you trust your own coding so little, how can you think anyone else will trust it ? "Fear-based programming" indeed)

While I'm over here in curly-braces land, I'll just have a wee whinge about:

if ( someCondition ) {
doStuff();
}

Why are the braces there ? Apparently to protect against errors like

if ( someCondition )
doStuff();
doMoreStuff();

Notice that justifications for this cute abomination never involve "because I might later ...", but always "because someone else might ...". But if your fellow-coders know so little, why are you protecting them, instead of just replacing them with good coders ? Or, why not just switch to Python ?

Why spend extra hours protecting against fixing bugs that have not happened yet, when you should be debugging the huge list in the issue tracker ?

And such justifications often appear on pages which also promote the atrocity which is over-breeding of parentheses: "If you don't use parentheses, you (or others working with your ActionScript 2.0 code) might run into operator precedence errors."

Wouldn't it be simpler to just learn the operator precedence rules ? If they are all that difficult, are you sure you should be programming ? I, for one, would rather have to fix the bugs due to bad precedence (once a year) than to have to read this every day:

if (((*curgene)!=(*curgene2))&&
((((*curgene)->lnk)->is_recurrent)==(((*curgene2)->lnk)->is_recurrent))&&
((((((*curgene2)->lnk)->in_node)->node_id)==((((*curgene)->lnk)->in_node)->node_id))&&
(((((*curgene2)->lnk)->out_node)->node_id)==((((*curgene)->lnk)->out_node)->node_id)))) {


If you are going to write code, please remember: some other poor schmuck is going to have to read it. If you make the kind of mistake which causes bugs, they can be fixed in hours. But a reputation for writing crap code will tend to last for years.

0 Comments:

Post a Comment

Links to this post:

Create a Link

<< Home