Hi, Just found this forum, and some nice WTF?!



  • Hi all, just found this site. Love it.
    Just inherited a Java project from someone who, apparantly, didn't know Java (or OO, or really any good coding practices at all.)
    some choice parts (vars changed to protect the stupid)

    switch(x) {
    case 1:
         //do a bunch of stuff
         break;
    default:
    }

    where x is NEVER EVER EQUAL TO 1. It took me 20 minutes to check all references to x and make sure it would never be 1.

    These guys LOVED their switches. In the class that handles the SQL stuff, they defined a whole bunch of constants like LOCATIONS=1, FILES=2, etc. So then I come along, and almost the whole project is full of sqlObject.getData(1) and sqlObject.getData(25)

    of course, that method looks more or less like
    public ResultSet getData(int choice) {
      try {
        switch(x){
          case LOCATIONS:
            //execute query to get and return locations
          case FILES:
            //execute query to get and return files
        }
    }

    Oooh did I have fun trying to figure out what the heck that class was supposed to do, so I could do a total re-write.

    WTF?!

    --Jordan



  • Welcome, and thanks for sharing!

    So they would define the constants, then use the integer (numerals) for the parameters in those methods?



  • The usage was totally inconsistant, occasionally they'd use the int parameters, but the constants were defined public static final, so sometimes they'd do the sqlObj.USER. the sql class even had a constructor that took a single int, and stored it as int selection, and then sqlObj methods would take other instances of the same class as a paramater, and use a getSelection() method.

    Really quite horrifying. The blank stares when I asked for the design docs when I took over the project were pretty amusing though.


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.