Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Thom Yorke raps
Nov 2, 2004


I remember there used to be a thread like this, but I can't find it anymore. Just post code that either you or your coworkers/classmates have written that is hilariously bad.

I've been looking through a large system recently, since I just started a new co-op and I have to get caught up. This one coder (who I've never met) has stuff like this in all his classes:
private static final int FIVE = 5;
private static final int NEG_ONE = -1;
private static final int FIVE_BILLION = 5000000000;
private static final String SPACE_PIPE_EQUALS = " |=";
private static final String ERROR_WITH_CODE = "Error with code";

I was reading one of his classes today that had 50 lines of constants written like that. In an 800 line class. Also, in multiple places he does this:
File fw = new File(args[0]);
File fh = new File(args[1]);
File nv = new File(args[2]);
File nh = new File(args[THREE]);
File tw = new File(args[FOUR]);

He does this in multiple classes. 0, 1, 2 are fine, but any number higher than that he replaces with a named constant. He also doesn't comment his code, and uses method names like "task" and "task2". Then there was this method:
code:
private boolean compareInts(int one, int two)
{
    boolean areEqual = false;
    if(one == two)
    {
        areEqual = true;
    }
    return areEqual;
}
His code is unreadable, and I am considering begging my boss to let me rewrite it, since he doesn't have me doing anything else. Of course, if I do that then I need to try to understand what exactly his code does, which may be impossible.


I'm sure compared to many of you that this isn't all that bad, so share your own tale of horror!

Adbot
ADBOT LOVES YOU

Thom Yorke raps
Nov 2, 2004


CeciPipePasPipe posted:

How come the guy is still employed?

My guess is that he is/was a co-op. They were apparently rather excited to hire me, and all I did was answer some pretty basic questions on OOP (not saying this to brag, because I am not that good of a programmer), so they probably don't have the most talented pool to choose from. Hell, they're hiring from my school, I know they don't have that talented a pool to choose from. When I mentioned the lovely naming to the senior developer, he said he had not seen it, so probably no one really noticed.

Thom Yorke raps
Nov 2, 2004


dwazegek posted:

quote:

code:
String numPorts;

String result = null;
try {
   doSomething(Integer.toInt(Integer.toString(getIntValue(numPorts))), result);
} catch (Exception e) {
}

if (result != "worked") {
   ...error handling code...
}
Does that even work? My java's a little rusty, but in C# you'd have to pass result with either the ref or out keyword to change it.

No. Strings are immutable, so any changes made inside the method don't apply to result anymore. Never mind the fact that result will never equal "worked" since they will never point to the same object, and he should have used .equals.

Thom Yorke raps
Nov 2, 2004


This was really awesome.
code:
public class AwesomeData {
    List<Something> persons;
    int numberOfPersons = 0;
.
.
.
.
    public void setNumberOfPersons(int num) {
        numberOfPersons = num;
    }
    public int getNumberOfPersons() {
        return numberOfPersons;
    }
    public void addPersons(Something p) {
        persons.add(p)
    }
}
code:
public class UsesAwesomeData {
    AwesomeData ad;
.
.
.
    public void someRandomClass() {
        ad.addPersons(p);
        ad.setNumberOfPersons( ad.getNumberOfPersons() + 1 );
    }
}
In an over 10 million dollar project that has as a requirement that it must be very fast. To the point where we are running the program + the database on 48 servers with a tb of RAM. It is like they don't know what Collections are. This is from the same project from the OP.

Thom Yorke raps
Nov 2, 2004


code:
boolean isA = getABoolean();
boolean isB = getAnotherBoolean();
boolean isTrue = !(a^b);
I had a 15 minute discussion with the original coder after sending him a code review with the last line changed to
code:
boolean isTrue = (a == b);
He didn't believe me that the lines were equivalent, even when I showed him the truth tables.

Adbot
ADBOT LOVES YOU

Thom Yorke raps
Nov 2, 2004


Java code, everything is a boolean
code:
boolean isFoo = !(isBar ^ isJustFucked);
Had a 10 minute discussion with the senior developer who wrote this when I wanted to change it to
code:
boolean isFoo = isBar == isJustFucked; 
I ended up having to draw the truth tables, and he still told me I had to retest all the code before making that one change. This at a place where running the tests took over an hour, which is a WTF all by itself.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply