tags:

views:

342

answers:

5

What is the ugliest code that you wrote - not because you didn't know better, but because of limitations of the software, the hardware or the company policy?

Because of unusual choices in database layouts and programming languages, I once built a C program that read in a SQL database structure and generated another C program that'd read that database and back it up into a file, or copy it into a second database that shared more or less the same columns. It was a monster clunky code generator.

+3  A: 

Any regular expression. :)

Craig Stuntz
couldnt agree more.
BBetances
A: 

I have my pride and do not write extreme ugly code (although the definition of ugly changes with experience). My boss pays me to write code and he expects it to be good.

Sometimes you have to write hacks. But you always have to claim the right to fix these later on else you will be faced with the concequences later on.

Gamecat
Thats right. The definition of "ugly" definitely changes. Ugly is always yesterday. :-)
pi
can I work at your place
zaratustra
+2  A: 

In the late 90s I had to write several web sites in Informix Universal Server web blade (aka Illustra web blade)

For anyone who doesn't know anything about this execrable environment, it forced you to use the most bizarre language I have ever come across. As Joel Spolsky described it

When it did run, it proved to have the only programming language I've ever seen that wasn't Turing-equivalent, if you can imagine that.

More on it here http://philip.greenspun.com/wtr/illustra-tips.html

And an example of a 'simple' if condition:

cond=$(OR,$(NXST,$email),$(NXST,$name),$(NXST,$subject))

I wish I could find the full api document, as looking back now in hindsight it would be hilarious.

One example of it's dire nature was the fact that it had no loops. Of any kind. It was possible to hack looping functionality by creating a query and iterating through its rows, but that is so wrong it makes me feel sick.

edit: I've managed to find a complete code sample. Behold:

<HTML>
<HEAD><TITLE>WINSTART bug</TITLE></HEAD>
<BODY>
<!--- Initialization --->
<?MIVAR NAME=WINSIZE DEFAULT=4>$WINSIZE<?/MIVAR>
<?MIVAR NAME=BEGIN DEFAULT=1>$START<?/MIVAR>

<!--- Definition of Ranges ---->
<?MIVAR NAME=BEGIN>$(IF,$(<,$BEGIN,1),1,$BEGIN)<?/MIVAR>
<?MIVAR NAME=END>$(+,$BEGIN,$WINSIZE)<?/MIVAR>
<!--- Execution --->
<TABLE BORDER>
<?MISQL WINSTART=$BEGIN WINSIZE=$WINSIZE
    SQL="select tabname from systables where tabname like 'web%' 
     order by tabname;">
    <TR><TD>$1</TD></TR>
<?/MISQL>
</TABLE>
<BR>
<?MIBLOCK COND="$(>,$BEGIN,1)">
    <?MIVAR>
    <A HREF=$WEB_HOME?MIval=WINWALK&START=$(-,$BEGIN,$WINSIZE)&WINSIZE=$WINSIZE>
    Previous $WINSIZE Rows </A> $(IF,$(<,$MI_ROWCOUNT,$WINSIZE), No More Rows,  )
    <?/MIVAR>
<?/MIBLOCK>
<?MIBLOCK COND="$(AND,$(>,$END,$WINSIZE),$(>=,$MI_ROWCOUNT,$WINSIZE))">
    <?MIVAR>
    <A HREF=$WEB_HOME?MIval=WINWALK&START=$END&WINSIZE=$WINSIZE>
    Next $WINSIZE Rows  </A>
    <?/MIVAR>
<?/MIBLOCK>
</BODY>

Prettify doesn't know how to colour it, quelle surprise

DanSingerman
A: 

Once upon a time, I was working for a small programming house with a client who had a legacy COBOL application that they wanted converted to Visual Basic. I was never a fan of VB, but that's not an unreasonable thing to want.

Except that they wanted the interface to be preserved and to function identically to the existing version.

So we were forced to produce a VB app consisting of a single form with a grid of roughly 100 text entry boxes, all of which were completely passive. Except the one in the bottom right, which had a single event handler that was several thousand lines long and processed all the data in all the entry boxes when you exited the field.

Dave Sherohman
A: 

A program that exchanged information between two applications. Needless to say the data between the two programs was in different format, different use-cases, and even meant different things from one app to the other. There were TONS of special cases and "nice" conversions:

if (InputString == "01")) 
         { Output.ClientID = Input.Address;}
else if ((InputString = "02") && (Input.Address == null) &&(Input.ClientID < 1300))
        { Output.ClientID = Input.ClientID +1;}
else if (Input.ClientID = 0 ) 
        { Input.ClientID = 2084; }

And on, and on for hundreds of lines.

This was for internal use in a large manufacturing plant... I cried durring most of the time I worked there.

Radu094