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. :)
Posted by: Koen | August 29, 2003 03:06 AM
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
Posted by: Yashima | August 29, 2003 04:38 AM
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...
Posted by: Patrick Schriner | August 29, 2003 05:54 AM
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?
Posted by: kasia | August 29, 2003 08:08 AM
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}
Posted by: Arcterex | August 29, 2003 12:28 PM