Friday, February 10, 2006

Hint to new programmers

So I'm working my way through code written by a recent grad.... this sucks! So to all new programmers out there...

RETURN TAKES A PARAMETER FOR A REASON!

Just because you CAN return void and use an object field as an implicit return parameter DOESN'T MEAN YOU SHOULD!

....and I suppose some lawyer would decide it was murder.....

3 comments:

Anonymous said...

Sounds like you need to ensure that your up-n-coming programmers learn the joys of lint-clean code. And that includes the /* ARGSUSED */ keyword :-)

Stephen Thorne said...

Of course! When you return from a function you should return '0' for success, and '-1' for failure.

Silly graduate, not knowing this simple thing.

Anonymous said...

Heh, funny stuff. Perl is the opposite. If you ever see perl featuring "return undef" you probably see a bug waiting to crop up. undef IS the "no-value" value, granted, but "return undef" in a sub evaluated in list context results in a list containing a single element of undef, not an empty list.

Rather, to indicate "no data" or failure, you should be using just plain old unadorned "return" with no value.

... just in case there weren't enough reasons to never use perl for anything longer than 100 lines.