Re: Coding Horrors, Cargo Cult Programming, and other Ghoulish Things



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

.



Relevant Pages

  • Re: Any new Treos coming to Cingular?
    ... Because it doesn't have a "feature" that doesn't work right anyway. ... And if you want to switch back, ... The Treo can do the GPS, music and listen for new email at the same ... since we all probably worked on 320x240 screens just a ...
    (alt.cellular.cingular)
  • Re: How could we improve Time Machine and Spaces?
    ... - Bind Safari to a screen and then open one Safari window. ... Imagine you have some critical web application open that relates to your project on a screen, so use F8 to show all your screens, and drag that window over to that project's screen. ... Switch to another screen and click the Safari icon on the dock. ... Despite it being bound to the original screen, it will switch to the screen where its only window is. ...
    (comp.sys.mac.system)
  • Re: Is there a way to check quality of SunRay connection?
    ... > I suspect it may have a high packet error rate. ... > in a cursory review of the admin screens that tabulates error ... Switch of any advanced screen savers, ... move line to other port on switch/hub and check again. ...
    (comp.unix.solaris)
  • Switching from Ad Hoc to access point mode and visa-versa
    ... I've downloaded the evaluation version. ... and switch the mode to and from accesspoint ... You could download the evaluation version of PB and go from ... >> Currently the switch in connection mode has to be done manually ...
    (microsoft.public.windowsce.embedded.vc)
  • RE: Strange Problem with Fast User Switching
    ... I apologize for posting in the wrong newsgroup, it was a mistake I made, as I ... and repair Windows from that. ... > to switch to another user on the computer using Fast User Switching. ... > whole situation, there are no error screens or error sounds, etc. ...
    (microsoft.public.windows.mediacenter)