Fog Creek Software
Discussion Board




Bad Code Revue

Alberto just posted a particularly egregious example of bad code he ran into that was written by one of the people who hired him. What could be a more fun topic than that?

One place I worked the Vice President of Software Engineering believed in the keywords IF and GOTO. All loops were implemented in terms if and goto, never while or do. This was all in C. He believed that the C language was flawed because it 'had too many ways to do things' and that 'disciplined' programmers should use only a minimal subset of the language in order to 'prevent confusion'.

Needless to say, I avoided his codebase like the plague and would definitely rewrite anything I needed rather than try to use what he had, almost none of which was ever in working condition since the simplest change would send him off into his office for a year-long struggle to overcome the simplicity of what he had created. There's more to it but I'll stop at this. Obviously he didn't respect anybody who used the more 'arcane and confusing' parts of the C language.

Anybody got any other good stories along these lines?

X. J. Scott
Tuesday, December 17, 2002


uh, where's Alberto's post?

Jason
Tuesday, December 17, 2002

in the natural selection thread


Wednesday, December 18, 2002

Here's the post:

Yesterday, I came across the following line of code in one of our developers code:

'..test for multiple conditions
If (x<>1) AND x<0 then
    gosub EXIT_HANDLER
endif

I mean, despite the obvious logic flaw, gosub?

It took me about 2 minutes to convince him that the logic was faulty. Then he leant back in his chain, as if he had just discovered the meaning of life and said "Ahhhhhhh".

This developer was on the interview team that interviewed me for a job, I only mention this line of code as it sticks in my mind, plenty more was just as bad or worse.

Chaos.

Interested
Wednesday, December 18, 2002

I got hired as a Delphi developer to write a report engine for a commercial product.  At the interview, they boasted that the product had > 1 000 000 LOC.

They were correct, the application was huge.  After poking around the system for about a day or two, I was a little confused because I couldn't find any business or data objects.  I was told they had 'data engines'.  The rest of the programming world however, calls them forms! 

By setting an arcane set of flags and simulating the proper 'button click' methods, in the proper order, one could enumerate the data on the form.  The data was then copied and displayed on the report.

Even worse, this 'architecture' took them 8 months to develop with a team of 6 'senior' developers!  I would have never thought such epic incompetence could occur on that scale ...

I quit in disgust
Wednesday, December 18, 2002

I started work here a few months ago to kick some products into releasable shape and I have to say they have some of the worst VB code imaginable.

However, I'd have to point the real blame at the manager, who wouldn't know the "Guerrila Guide To Interviewing" if it bit them on the backside. They just seemed to let any old cretin in. Why do people insist on hiring "VB" programmers who've just graduated from writing the odd Excel macro and would probably die of fright if they ever had to worry about pointers or memory allocation.

And, worse, when the programmers screwed up big time, the manager hacked the code into shape so it worked, with no regard for writing anything so passe as a spec or design document.

There are some spectacularly bad bits of code. One guy seemed to not understand what functions were and created this massive switch statement that went on for pages and pages. But my favourite is this gem (real names changed to protect the guilty!!!)

Public Property Get MyProperty() as udtMyStruct

    On Error Resume Next

    With MyProperty
        .This = SomeGlobalVariable
        .That = SomeOtherGlobalVariable
    End With

End Property

Public Property Let MyProperty(udtMySTruct As MyStruct)
    On Error Resume Next

    GlobalForm.DoSomething

End Property

I didn't think this was actually legally possible in VB, but apparantly it is. (Seems that in a Property Get, the name of the property can be used as a variable anywhere; just most people only use it for specifying a return value).

Fortunately, though more through sheer fluke of there being much more competent programmers available due to the bad state of the job market, this seems to be a thing of the past, but it's a right pain having to work around this sort of crutch.

Better than being unemployed....
Wednesday, December 18, 2002

>>>>
It took me about 2 minutes to convince him that the logic was faulty. Then he leant back in his chain, as if he had just discovered the meaning of life and said "Ahhhhhhh".
<<<<

I had one of these from the guy that hired me. It took him a little longer to understand  as he has very poor communications skills and doesn't listen (but to his defense, he's changed a good deal). However, when he finally got it, he paced around for twenty minutes then went into a spiel with some of the partners about how it was the fault of his son and I!

Oh well.....

Cheers,
BDKR

BDKR
Wednesday, December 18, 2002

Here's a good one...

So some folks who didn't know anything about CGI or anything like that were taught Perl, told to build a site, and then I had to verify the work and make some finishing touches.

This was in the early days of the boom.

As a beginning, every page was a CGI, usually just to generate some static text.  Occasionally, there was calls to a database, but mostly just for the shopping cart, which was in awful shape anyways.

But the best part was how they assembled pages.  Remember that PHP/ASP/ColdFusion/etc. hadn't become popular yet.  So instead of writing a library, they would write little Perl scripts to generate portions of a page and then execute them with Perl's backtick (`) functionality.  So if you hit one page, it would spawn multiple perl inte.

The best part was that each button on the left-hand navigation bar was another Perl invocation.

Oh yeah, and they had a fixed price contract and had spent all of their money.  And their buddy-buddy ISP partner decided to run a CPU-intensive backup at 3 PM EST because they didn't want to have to stay late.

w.h.
Wednesday, December 18, 2002

The PRESENTING.... A Bad Code Revue

Setting: In a theater.

[Curtain raises to reveal Joel standing on a platform in classic geek dress, with the rest of the people in the forum standing around him dressed similarly, but with propeller head caps on.]

Joel (sings, baritone): May your signals all trap

Geeks (singing, in chorus): May your references be bounded

Joel: All memory aligned 

Geeks: Floats to ints rounded


All: Remember ...


Joel: Non-zero is true

Geeks:  ++ adds one

Joel: Arrays start with zero

Geeks: and, NULL is for none


Joel: For octal, use zero

Geeks:  0x means hex

Joel: = will set

Geeks:  == means test


Joel: use -> for a pointer

Geeks:  a dot if its not

Joel: ? : is confusing

Geeks:  use them a lot


Joel: a.out is your program

Geeks:    there's no U in foobar

All: and, char (*(*x())[])() is
    a function returning a pointer
    to an array of pointers to
    functions returning char

[crowd cheers, everyone bows, curtain falls]

(with apologies to whoever first penned the "ode to C")

Rob
Wednesday, December 18, 2002

LOL, that was a nice song. Never it before.

Siddharta Govindaraj
Thursday, December 19, 2002

Excellent, Rob. I'm pinning this on our fridge.

Not wanting to steal your thunder, or state the obvious too much, but for our readers for whom English is not their first language, 'revue' is an evening of songs and comedy pieces, and a 'review' is an evaluation of something, such as a piece of code.

David Clayworth
Thursday, December 19, 2002


All right, and here is a DBA's song. It's old, but very funny, I cound resist to post it :)

==========================================

Yesterday: A DBA's backup song
YESTERDAY (To be sung to the tune of Yesterday)

Yesterday,
All those backups seemed a waste of pay
Now my database has gone away
Oh I believe in yesterday


Suddenly,
There's not half the files there used to be
And there's a deadline
hanging over me
The system crashed so suddenly.


I pushed something wrong
What it was I could not say
Now my data's gone
and I long for yesterday-ay-ay-ay.


Yesterday,
The need for back-ups seemed so far away.
Thought all my data was here to stay,
Now I believe in yesterday.

Passater
Thursday, December 19, 2002

couldn't even
where is the preview, huh?

Passater
Thursday, December 19, 2002

*  Recent Topics

*  Fog Creek Home