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
Lysandus
Jun 21, 2010
A guy I work with will take code like this:
code:
if( whatever )
{
    doSomething;
    doSomethingElse();
}
else
{
    doThis;
    doThat();
    doTheOther;
}
He turns it into this:
code:
if( whatever ){
    doSomething;
    doSomethingElse();}
else{
    doThis;
    doThat();
    doTheOther;}
He then commits it to the repository with the comment "Code cleanup."

He also hates to use functions because "it makes the code too hard to follow."

Adbot
ADBOT LOVES YOU

Lysandus
Jun 21, 2010
He's gotten better at not doing that over the years, but he'll still complain about functions being hard to follow. He's actually pretty smart when it comes to some of the weird poo poo we need to figure out.

Here is another gem I found in some old networking code we have:

code:
        StringBuffer buffer = new StringBuffer( 120 );
        boolean useHTTPS = false;
 
        try
        {
            if( useHTTPS )
            {
                buffer.append( HTTPS_START );
            }
            else
            {
                buffer.append( HTTP_START );
            }

Lysandus
Jun 21, 2010

Orzo posted:

Don't you have some sort of standards wherever you work in which one of you (I'm assuming him, since I hate his style) is blatantly breaking a rule?

I'm my department yes, but he is in another department and they put up with it.

Lysandus
Jun 21, 2010

Jonnty posted:

Presumably they were going to add a way of changing useHTTPS later? That's not a colossal horror if so.

I would hope, but by the time I inherited the code it was already 2 years old and the original programmer was long gone. I ended up rewriting most of the networking library anyway.

Lysandus
Jun 21, 2010
We got a new guy who's interning here until he finishes his degree. When he was sent to my department I asked him what his java experience was and he replied "Pretty extensive. I've have had 4 classes now on Java." After the usual training B.S. I let him start fixing some bugs and gave him an easy one to start with. I even told him how to fix it by extending ClassA and override MethodA, etc.

Six hours later he commits the changes which included copy and pasting ClassA to a new file calling it ClassB and changing some code in MethodA because he couldn't figure out he needed to remove "final" from ClassA.

Apparently they save the final keyword for the 5th java class. :bang:

Lysandus
Jun 21, 2010

Painless posted:

The way you describe it, your way of "fixing" things sounds like a coding horror in itself. Class A has a bug, so fix it by quietly removing 'final' and extending with a class that has the bug fixed?

It wasn't a bug in the sense that there was a flaw in ClassA. I just call everything in our issue tracker a bug.

Lysandus
Jun 21, 2010
Touché.

Lysandus
Jun 21, 2010

WangNinja posted:

code:
INSERT INTO 
	ScoringEntry  
(
	projectid, 
	type, 
	questionid, 
	answerid, 
	AgencyMarketingInd
) 
SELECT  
	@servID, 
	'S', 
	@q1QuestionID, 
	@q1AnswerID, 
	@AgencyMarketingInd 
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q2QuestionID, 
	@q2AnswerID, 
	@AgencyMarketingInd 
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q3QuestionID, 
	@q3AnswerID, 
	@AgencyMarketingInd
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q4QuestionID, 
	@q4AnswerID, 
	@AgencyMarketingInd 
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q5QuestionID, 
	@q5AnswerID, 
	@AgencyMarketingInd 
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q6QuestionID, 
	@q6AnswerID, 
	@AgencyMarketingInd 
UNION ALL 
SELECT  
	@servID, 
	'S', 
	@q7QuestionID, 
	@q7AnswerID, 
	@AgencyMarketingInd

My sql isn't that great, but it looks to me like every question and answer has its own column, which physically made me lol.

Lysandus
Jun 21, 2010
I found this today and it's not even that bad but it struck me as so funny I started cracking up at my desk.


code:
text.setMessageText(moreBody);
text.setMessageText( text.getMessageText() + " " + moreBody );
Basically it's suppose to take the moreBody and append it to the existing body so you should end up with "1 2" for example. Since it's wrong you end up with "2 2".

Lysandus
Jun 21, 2010
Found this one today.

code:
    public boolean addModuleName( String moduleName )
    {
        boolean moduleNameAddedSuccessfully = false;
        
        if( _modules != null )
        {
            try
            {
                _modules.addElement( moduleName );
                moduleNameAddedSuccessfully = true;
            }
            catch( Exception addModuleNameException )
            {
                System.out.println( addModuleNameException.toString() );
            }
        }
        else
        {
            moduleNameAddedSuccessfully = false;
        }
        
        return moduleNameAddedSuccessfully;
    }
I can understand checking the vector to make sure it's not null, but the rest...

Lysandus
Jun 21, 2010
I saw this today and just stared in wonder.

code:
public static final int COLOR_DARK_GREEN = Color.DARKGREEN;
public static final int COLOR_DARK_BLUE  = Color.DARKBLUE;
Color.DARKGREEN and Color.DARKBLUE are already static constants in another class. Why do they need to be re-static-constanted?

:psyduck:

Lysandus
Jun 21, 2010

Nevett posted:

This is in C#, in an ASP.NET project I've inherited.

code:
	public Boolean IsNumeric(String strString)
	{
		Boolean bValid = true;
		for (Int32 nI = 0; nI < strString.Length; nI++)
		{
			String strChar = strString.Substring(nI, 1);
			if (strChar != "0" && strChar != "1" && strChar != "2"
			 && strChar != "3" && strChar != "4" && strChar != "5"
			 && strChar != "6" && strChar != "7" && strChar != "8"
			 && strChar != "9")
			{
				bValid = false;
			}
		}
		return bValid;
	}


Run this thread through there and see how long it takes.

Lysandus
Jun 21, 2010
code:
for (int i = 0; i<1; i++ )
{
     /do some stuff, guess how many times.
}

Lysandus
Jun 21, 2010

Hammerite posted:

I think this could be defensible, depending on what exactly it's being used to do. Similar to how while (true) {...} can be a useful control structure.

I challenge thee to provide an example.

Lysandus
Jun 21, 2010
Exceptions are great until they are thrown 14 calls back with no indications of which method threw it.

:suicide:

Lysandus
Jun 21, 2010

NotShadowStar posted:

What crazytown language doesn't vomit a stack dump when you get an uncaught exception?

RIMs bastard java they put on Blackberrys.

Lysandus
Jun 21, 2010

Internet Janitor posted:

Fun fact: in "RIM Java", static initialization on final variables can be fired every time the classloader of a subclass is executed.

Try this with strings and watch your memory footprint EXPLODE INTO WONDERLAND!

Lysandus
Jun 21, 2010
This isn't so much a horror, as it just bugs me.

code:
HttpHeaders.HEADER_ACCEPT_ENCODING
Isn't
code:
HttpHeaders.ACCEPT_ENCODING

enough? :confused:

Lysandus
Jun 21, 2010
Just came across this comment:

code:
//Battery status constants.  DON'T gently caress WITH THESE VALUES.
Way to stay professional ex-dick that left this mess for me.

Lysandus
Jun 21, 2010
This might not be a horror for some of you but gently caress.

code:
if( bananas )
     grabBanana();
God drat I don't care if it's one line. Put some {} on that poo poo.

Lysandus
Jun 21, 2010

Orzo posted:

This is a preference and probably the furthest thing from a horror I can think of. Follow your team's guidelines when it comes to this one.

Our department made it a guideline long ago because we all hate it. I was reminded of it today while looking though a library from another department.

Lysandus
Jun 21, 2010
Here's a riddle for you.

Q: What do you get when you have a graphic designer who's never coded before create an application?


A: One 5000 line class that contains the entire app.

Lysandus
Jun 21, 2010
code:
if ( !responseBuffer = ByteBuffer.wrap(newData) )
{
    responseBuffer = ByteBuffer.wrap(newData, 0, newData.length);
}
:psyduck:

Lysandus
Jun 21, 2010
code:
public int getItemId(int ID)
{
    return ID;
}
:psyduck:

Lysandus
Jun 21, 2010

Internet Janitor posted:

Lysandus: Placeholder for validation logic? Please? :(

It's existed for three versions of the software and there are no comments around it indicating it might be.

NotShadowStar posted:

Probably a typo or slip of the brain. Likely meant 'return _itemID' or some such.

Slow coding horror weeks!


Here's the best part. The only place it's used.
code:
for( Contact contact : contactVector)
{
    Log( "Adding contact with ID: ", getItemId( contact.getId() ) );
	        		
    //other processing stuff
}
If it was to have another use, I have yet to find it.

Lysandus
Jun 21, 2010
I'm digging through a connection class for one of our internal apps and there is no handling for HTTP 401 responses from the server.


And by no handling I mean the entire app crashes if the server returns a 401.

Lysandus
Jun 21, 2010

quote:

When you define static fields (also called class fields) of type String, you can increase application speed by using static variables (not final) instead of constants (final). The opposite is true for primitive data types, such as int.

For example, you might create a String object as follows:

private static final String x ="example";

For this static constant (denoted by the final keyword), each time that you use the constant, a temporary String instance is created. The compiler eliminates "x" and replaces it with the string "example" in the bytecode, so that the BlackBerry® Java® Virtual Machine performs a hash table lookup each time that you reference "x".

http://docs.blackberry.com/en/developers/deliverables/5716/Using_static_vars_for_strings_447038_11.jsp

Lysandus
Jun 21, 2010

Ugg boots posted:

Oh god, this is a Blackberry JVM implementation only thing, right?

Thankfully yes.

Lysandus
Jun 21, 2010
code:
long thisInterval = ((Long)data).longValue();
long nextInterval = ((Long)data).longValue();
						
if( thisInterval < nextInterval )
{
    _data = data;
}

Lysandus
Jun 21, 2010

Edison was a dick posted:

Well it might do something if data changes, which could happen if it's volatile.
What are data and _data?

It's not. data is passed into the method and _data is the passed in data but global. Later on the method _data = data; anyway based some some other criteria.

Lysandus
Jun 21, 2010
Bad naming usually pisses me off, but this was a good laugh.

code:
private void addBasicGorillasToTheBananaHeaders ( Hashtable<String, String> properlyRequestedBananaRequisitionFormsWithCheifGorillaApproval  )
{
    //stuff
}

Lysandus
Jun 21, 2010
I found this today.

code:
if( !true )
{
}
Nothing identifying around it. Just that.

Lysandus
Jun 21, 2010
This is the best part. People around me were poking their heads out of their cubes to see why I was laughing so hard.

code:
throw new InvalidArgumentException(ValueToBeTested + " is not a valid boolean value.");

Lysandus
Jun 21, 2010

toiletbrush posted:

Just a tiny one, displaying a DateTime in a razor view...

code:
@DateTime.Parse(model.Date.ToString()).ToLongDateString()

So he took a date, made it a string, parsed a date from that string and turned that date into a string...

:psypop:

That's some inception horror there.

Lysandus
Jun 21, 2010
code:
<?php
//namespace SECRETNAMESPACE;

class DO_SecretTable {

	/** 
	* @var string
	*/ 	
	var $Column0;
	/** 
	* @var string
	*/ 	
	var $Column1;
	/** 
	* @var string
	*/ 	
	var $Column2;
	/** 
	* @var string
	*/ 	
	var $Column3;
	/** 
	* @var string
	*/ 	
	var $Column4;
	/** 
	* @var string
	*/ 	
	var $Column5;
	/** 
	* @var string
	*/ 	
	var $Column6;
	/** 
	* @var string
	*/ 	
	var $Column7;
	/** 
	* @var string
	*/ 	
	var $Column8;
	/** 
	* @var string
	*/ 	
	var $Column9;
	/** 
	* @var string
	*/ 	
	var $Column10;
}

?>
It goes to 46

Lysandus
Jun 21, 2010

Hughlander posted:

This is mild for the thread but I need to vent since the person who wrote this left the company right before shipping and left me to take over their systems...

How do you know when you need to refactor someone's code?

When a 300 line function ends with:
code:
                                                }
                                          }
                                    }
                              }                       
                        }
                  }
            }
      }
}

I see your bid and raise you!

code:
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
									}
								}
							}
						}
					}
				}
			}
		}
	}
}
This is out in the real world. Note: A lot of white space was removed to prevent table breakage.

Lysandus
Jun 21, 2010
code:
if( phoneNumber.length() > 0 )
{
	if( phoneNumber != null )
	{
		doStuff();
	}
}
:psyduck:

Adbot
ADBOT LOVES YOU

Lysandus
Jun 21, 2010
Ok, which of you did this.
Fizz Buzz Enterprise Edition

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