Master of time

February 12, 2010

I think this comment is unintentionally very amusing:

/**
 * {@code MyTimer} manages time.<br>
 * <b>Collaborations:</b><br>
 * <i>none</i>
 */
public class MyTimer extends JLabel implements ActionListener {
   // ...
}


Weird widget adapter

February 5, 2010

I’m still not really sure what misconception lead to this class:

public class StatusBar {
   private JTextField status;

   public void setStatus (String status) {
      this.status.setText(status);
   }
   public void clearStatus () {
      this.status.setText("");
   }
   public JTextField getStatus () {
      return this.status;
   }
}

I can’t comprehend why they didn’t just extend JTextField to add their methods instead of doing this weird wrapping. This violation of encapsulation principles really hurts somehow.


Were we supposed to…

January 19, 2010

Last week my students had to solve a very basic exercise concerning the MVC pattern. After almost one week time to work on that and ask questions a student approached me after I explained the observer pattern in class:

“Were we supposed to use the observer pattern in this exercise?”

I replied with the question how he managed to use MVC pattern without it and he said that his solution works. Well, yes. It works. But there is no way of adding a second, third, … view. And again I ask myself why they do not understand the most basic things…


Keep looping

November 28, 2009

Another funny implementation of the line iterator mentioned before. Those two did not at all understand the concept of lightweight associated with an iterator. Each call of next() or hasNext() resulted in a call of this method:

public String getLineAtPosition (int index) {
    FileInputStream dataFile = new FileInputStream(this.fileName);
    byte[] buffer = new byte[1];
    String data = "";

    while ((dataFile.available() != 0) && (index != 0)) {
        dataFile.read(buffer);
        data += (char) buffer[0];
        if (lineBreak(data)) {
            index--;
            data = "";
        }
    }
    if (dataFile.available() == 0) {
        return "Insufficient data.";
    }
    while (dataFile.available() != 0) {
        dataFile.read(buffer);
        data += (char) buffer[0];
        if (lineBreak(data)) {
            data = noLineBreak(data);
            break;
        }
    }
    return data;
}

Well, there are a lot of grave mistakes in here, too. But imagine this method called every time! A test case reading Goethe’s “Zauberlehrling” (111 lines) took almost a minute to finish…


Not in use

November 28, 2009

This was handed in as an implementation of a class, which allows iterating the lines of a file one by one. Of course, the students were supposed to use the Iterator interface from the Java library.

/**
 * not in use
 */
public boolean hasNext() {
    return false;
}

I wonder if they even bothered to look at the documentation at all.


Supposed to be funny?

November 28, 2009

I found this comment within a solution to an exercise, which was meant to instruct on formulating an object invariant:

// invariant: we don't guarantee anything


Follow

Get every new post delivered to your Inbox.