Yenya's World

Tue, 24 May 2011

Mysterious Source Code

About a month ago, I have spotted a two-page listing of source code in our printer room/kitchenette. I have glanced over it briefly, and during subsequent visits to the room, I became more and more fascinated by it. Finally, about a week ago, I have grabbed it for myself, because nobody seemed to care about it anymore. So here it is, in all its glory:

source code page 1 source code page 2

Click the thumbnails for full-size images. Sorry for not providing a plain text version, and sorry for the Czech language in the comments. I have two reasons for which I find it really fascinating:

  1. There are two pages of source code, which does literally nothing. It only wraps an existing class with a new one with marginally different API (two exceptions joined into one exception, and retrying in case of failure). Nobody sane would write these two pages by hand, so I expect the code has been at least partially generated by some IDE. Obviously nobody can expect the code to be read by a human (actually, not read, but carefully examined for traces of some non-trivial application logic, should there be any). So I wonder what the present meaning of "the source code" phrase is, when it is no longer written nor readable by humans.
  2. The only real "application logic" is the for-cycle near the end of the second page. And even this has been totally destroyed by the "every block should have only one exit point" mantra of the programming theoreticians. Adding a simple return statement when the message sending finally succeeds would save them the following:
    • a boolean variable
    • a complicated condition in the for-cycle
    • an if statement when the maximum number of tries is reached

I can only hope this is some kind of a silly example and not a real assignment given to the students of the Programming in Java course. I think the students have to be taught that mid-layers are root of all evil, and not some highly theoretical (read: impractical) rules like "goto is evil" or "a single exit point only".

Section: /computers (RSS feed) | Permanent link | 4 writebacks

4 replies for this story:

gRis wrote:

I would have said it is a code snippet for the Public Administration Informatics guys, but it reminds me too much of the atrocities we used to create in PB162 several semesters ago. I suggest you ask in the course discussion forum, or submit it to TDWTF.

himdel wrote:

Nope, this was an actual PB162 homework, I remember having to write something very similar. Courses like this are what made me really despise Java (I don't, anymore, but I still think it's rather silly). However, IIRC it was meant to teach about chaining exceptions, which it probably does well. And while they might have taught the single point return nonsense, there were only automated tests so the student who wrote that could have written it better.

EL wrote:

Having taught Java (meaning I was the "teacher" on the excersises for two terms) I'd say that this is just silly looking excersise, with empasis on the word looking. My guess is that this is a way to teach students how to use exceptions (which you have to do a lot in Java). Normally, on such a small piece of code, you wouldn't bother, but this is how the students IMHO get used to the exceptions. BTW: While I understand the "old programmers" desire to minimize the amount of variables etc., from my point of view there are two most important things that should be considered regarding a source code: - readability (that includes consistent coding) - the best available complexity (in the terms of computational complexity) So in this case, the return would definitelly make more sense than the overcomplicated condition, but the (non)existence of the boolean variable doesn't seem so relevant (although it vanishes from the code as well as a result).

EL wrote:

Ooops, sorry for the (non)formatting, I tought it would be preserved.

Reply to this story:

URL/Email: [http://... or mailto:you@wherever] (optional)
Title: (optional)
Key image: key image (valid for an hour only)
Key value: (to verify you are not a bot)


Yenya's World: Linux and beyond - Yenya's blog.


RSS feed

Jan "Yenya" Kasprzak

The main page of this blog



Blog roll:

alphabetically :-)