« About those sillly copyright notices | Main | If you use spamassassin »

Probably the stupidest code I've seen to date..

It went something like this.. (variable names changed to protect the innocent)


public List getWhatever(int id) throws NotFoundException
{

    ArrayList thisList = new ArrayList();

    try
    {
       thisList = (ArrayList) getItFromSomePlaceElse(id);
    }
    catch(Exception)
    {
        // ignore
    }

    return (List) thisList;
}

Just like that.. stupid casts and all.. *banging head on wall*

Comments

i hope this was meant to be stupid code. :)

I can beat that one ... ;-)

while(true){
....
if(something){
....
break;
}
else {
....
break;
}
}

http://www.newgods.org/~yashima/dd/whiletrue.html

And it was not the only 'weirdness' I encountered in that project

Cast are very nice if someone does a rename refactoring, say with Eclipse.

You donīt think Eclipse could recognize something like:

something.instanceOf Class .forName("SomeClassName.class");

and change "SomeClassName" to the refactored name...

No, these casts are stupid.. It's casting an interface to the inheriting object, then casting the inheriting object back to the interface to return it.. for absolutely no reason.

Can you say broken code if anyone ever changes the implementation of the called code to say.. LinkedList?

Perl allows you to write far more bizzare things. The code below does a lookup to see if the answer provided is the correct answer. I think. Maybe, it's been a day or so since I wrote the code so I'm a bit fuzzy :)

$d[0]->[$q->{number}-1]->{answers}->$answerlookup{$mydata{$q->{number}}}]->{answer}