Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: "Ralf Mimoun" <nospam@xxxxxxxxx>
- Date: Sat, 28 Oct 2006 16:51:54 +0200
HI,
first, I don't understand some of the outrage. Somthing like
if Assigned(x) = True then begin
x.Free;
end;
does not hurt. Before and beside the nice OO world, you have to check before you free memory (and that's one of the thing that .Free does). Who cares if there is an additional test? Speed? Come on, maybe 0.0001% of all functions can't live with that test. It's not bad if someone wants to be really conservative while writing code.
Darren Davis wrote:
....
2. Short-circuited boolean evaluation
I was working on a piece of code I'd written and I came across
something like:
If assigned(something) {and (something.value = somevalue)} then
Now I'm looking at a bit of key code commented out. off to sourcesafe
and I find the culprit (guess who), and ask why? It transpires for
some unknown reason he decided to build the source tree with
short-circuited boolean evaluation turned off. Suddenly everyone
elses code started breaking, so after commenting out a few bits he
then gave up and turned it back on. Never dawned on him to undo the
changes he'd made however.
That story has two sides. First, yes, that guy definitely had to undo the changes. Second: writing code that fails when you change a compiler switch in the IDE or the build tool is bad style. Even dangerous. If you rely on a specific switch, then write that switch in the code. Or better: DO NOT WRITE CODE THAT ONLY WORK WITH SHORT-CIRCUIT BOOL EVALUATION!. Why do you? Faster to type? Forget it. Typing is _not_ a speed factor in a project. Easier to read? Definitely not!
My advise: if you need or want short circuit evaluation, then write that code. Or make damn sure that your personal preference really works, and write that switch in the pas file, or in a inc file. Be explicit. Yes, I know, there are many with a different opinion.
....
It was crashing on everyone's machine except his - and he's playing
the works on my machine card. So I look at the code and immediately
spot that in most cases, the function will have an undefined result.
But how did he get it to work on his machine. He turned off compiler
optimisation.
And he ignored completely the hints and warnings. They are some of the best tools to write better code, and they are so cheap. I hope you don't have to work that much with that guy.
....
Problem is when read-only certain components still
need to be enabled, and when not read-only, certain components follow
a logic of only being enabled under certain conditions. All screens
now break horribly. So eventually I manage to get the guy to make the
routine virtual, and I override it and ignore his code and use mine
in my screens. In the meantime for the rest of the screens, the
simple routine became a monstrous fix to make ~some~ things read-only.
We all write some hacks from time to time. Besides making that function (or property) virtual, you cold even (ab)use the Tag property to define if something should not be changed. Yes, not nice, not clean, but sometimes a fast shortcut. Must be documented, of course.
5. If it doesn't work - just comment it out
Yes, they can be funny - as long as you don't have to work with that code :-)
Ralf
.
- Follow-Ups:
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Dave Nottage [TeamB]
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Wayne Niddery [TeamB]
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Darren Davis
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Peter Morris [Droopy eyes software]
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Bart van der Werf
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Rick Beerendonk
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- References:
- Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: John Jacobson
- Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- From: Darren Davis
- Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- Prev by Date: Re: Assigned and FreeAndNil
- Next by Date: Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- Previous by thread: Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- Next by thread: Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things
- Index(es):
Relevant Pages
|
|