The Ugly Code-Duckling #3

As you are, soldier. When me and my fellow tutors where looking over the last exams in the programming lecture, I made a few notes on what can safely be considered as “crimes against humanity, style and every definition of common-sense”. Somehow, I suppose because of the huge workload I have to cope with at the moment, I forgot to publish a new “Ugly Code-Duckling”.

Well to serve yet another cenotaph (/hug Thesaurus) as a warning to future generations:

At first I was curious why someone would use an integer array to encode a duration of days which, at least in my opinion, seems to be predestined to be encoded as an integer variable.

int[] duration;

Well, “diligence” and “intelligence”, surely not among my most distinct traits contrary to “creativity” I still could not figure out how the Java-program in front of me should work… Well, until I saw the following:

public void setDuration( int n ) {
duration = new int[n];
}

Well, after a few minutes I capitulated to stinging pain in the back of my head and just accepted what my eyes told my brain to be part of the reality I love so much. And we all know that humanity has its flaws, so what do I know…

…well - I know that another line in the source-code quoted:

duration.length = duration.length + 1;

End of transmission.


About this entry