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
very
Jan 25, 2005

I err on the side of handsome.

Bonus posted:

I see someone has been reading Schrödinger's book on programming.

Don't worry, the software is working perfectly in another universe.

Edit: Some of my old code:
code:
static int oldscore = 999, oldlevel = 999, 
    oldblocks = 999, oldcombolevel = 999;
I hope you don't score more than 999 points.
code:
  piece = next[0];
  next[0] = next[1];
  next[1] = next[2];  
  next[2].randompiece();
And then there's this.

very fucked around with this message at 15:19 on Mar 22, 2008

Adbot
ADBOT LOVES YOU

enki42
Jun 11, 2001
#ATMLIVESMATTER

Put this Nazi-lover on ignore immediately!
The single greatest argument in VB.NET

code:
Public Sub Stuff (Optional ByRef x As Object = Nothing)
To anyone who doesn't know VB.NET, this may or may not take in an object of any type, and modify it in any way the function sees fit, up to and including changing the type completely.

Another gem:

code:
Dim intResult as integer = CInt(1)
Dim intResult as Integer = CInt("1")
Both of these appear in our code HUNDREDS of times.

wunderbread384
Jun 24, 2004
America's favorite bread
One of the guys who worked on my project before I got there was a great coder, but an absolutely horrible speller. I'm constantly finding variables or methods named catagory, assistint, lisence, componint, and crap like that. I never thought people would need spellchecking in an IDE, but man did this guy need SOMETHING.

It's not so bad in the Java code because it's pretty obvious when you're accessing something that doesn't exist, but in the client code and legacy web services it's a bitch sometimes. Every once in awhile I'll wonder why data coming from the service is undefined, and it'll end up being I was expecting category rather than catagory or license instead of lisence. And naturally since it's a service we can't just go and change the definitions, because other people might be depending on it. So I'm stuck writing things like getLisenceId() just so it's consistent at least.

such a nice boy
Mar 22, 2002

At my last job, we hired a guy who was supposed to be pretty good at...well...some technology. I won't say which, because you'd be able to figure out who it is. In fact, he was one of the coauthors of the O'Reilly book on it, so we assumed he really knew his stuff.

Our product was written in Java, and he was supposed to write the section dealing with this technology. 2 days before we were supposed to code freeze, he's freaking out, saying that nothing works and he can't figure out why. I look at his code.

First clue something was wrong: he's storing EVERYTHING as strings. Integer return codes? Strings! Boolean values? "True" and "False". Casting them to ints or bools every time he needs to use them, which is pretty often.

Sometimes the casting was insane. I would see things like this:

code:
String numPorts;

try {
   doSomething(Integer.toInt(Integer.toString(getIntValue(numPorts))));
} catch (Exception e) {
} 
all over the drat code. What's worse is that he would try to get return values in strings that were passed as parameters. So the above code would really look like this:


code:
String numPorts;

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

if (result != "worked") {
   ...error handling code...
}
I walked over to my manager's office and showed him the code. His jaw almost hit the ground.

I spent the next 2 days and nights trying to figure out what the guy's code was really supposed to do, finding all the copy-pasted code, refactoring, and getting rid of the numerous unnecessary "factory" classes and abstract classes that he tried using in his failed attempts to get his code to work.

dwazegek
Feb 11, 2005

WE CAN USE THIS :byodood:

such a nice boy posted:

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.


We used to have a control that could display multiple other controls in a grid, which we used to display multiple video streams simultaneously. For whatever reason, if you changed the number of cells in the grid from (e.g.) 4 to 6, the control would first switch to 5 cells, and then to 6. Also, if you wanted less cells than you had, it word reset itself to 1 cell, and then count up until it reached the desired amount.

Turns out the resizing code looked something like this:
code:
public void SetCellCount(int cellCount)
{
  if(cellCount == currentCellCount)
  {
    return;
  }
  if(cellCount < currentCellCount)
  {
    Reset(); //among other things, currentCellCount gets reset to 1 here.
  }
  while(currentCellCount < cellCount)
  {
    currentCellCount++;
    SetCellCountInternal(currentCellCount);
  }
}
Okay, so that explains the messed up behaviour of the control, but why not just set the cell count to what you want to have immediately? Well, this is what SetCellCountInternal looked like:

code:
private void SetCellCountInternal(int cellCount)
{
  switch(cellCount)
  {
    case 1:
      //create one cell and set it's location
      break;
    case 2:
      //remove first control from grid
      //set first control to a different size and location
      //create second control and set it's location
      break;
    case 3:
      //remove first control
      //remove second control
      //set first control to a different size and location
      //set second control to a different size and location
      //create third control and set it's location
      break;
    //etc, 12 cases in all
}
The method was over 200 lines long, the last case alone was 24 lines of code.
Seems that the reason why it always counted up when adding controls, was that for case N to work, case N - 1 had to have run.

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.

return0
Apr 11, 2007

such a nice boy posted:

What's wrong with that code? Is it just that
code:
if (_a > _b)
would have been better?

Yes, that's why it was insane. I wanted to branch based on which number was higher (i.e., if(_a > _b) ). My code requires more work, breaks for cases where an argument is negative, and obviously relies on _b not being zero. That's why it was such a wtf for me. I don't even remember writing it, but source control doesn't lie.

Vulture Culture
Jul 14, 2003

I was never enjoying it. I only eat it for the nutrients.

such a nice boy posted:

I walked over to my manager's office and showed him the code. His jaw almost hit the ground.
I hope you guys have code review policies in place now. :)

bitreaper
Jan 1, 2007

First day on my new job, confronted with this:

INSERT INTO Applications ( Password, AccessLevel, MemberNum, MemberType, MemberExpiry, PCExpiry, AccountCreated, Title, FirstName, LastName, Gender, Lang, BirthdayMonth, BirthdayDay, BirthdayYear, HomePhone, WorkPhone, MobilePhone, FAX, Email, Street, Apartment, PostalCode, City, Province, Country, MailingSame, MailStreet, MailApartment, MailPostalCode, MailCity, MailProvince, MailCountry, Sport, Passport, , L2F, L2FMonth, L2FYear, L2FSport, L3F, L3FMonth, L3FYear, L3FSport, L4R, L4RMonth, L4RYear, L4RLocation, L4F, L4FMonth, L4FYear, L4FSport, NCID, NCIDMonth, NCIDYear, NCIDLocation, L5F, L5FMonth, L5FYear, L5FSport, Uni1Name, Uni1FromMonth, Uni1FromYear, Uni1ToMonth, Uni1ToYear, Uni1Program, Uni1Degree, Uni2Name, Uni2FromMonth, Uni2FromYear, Uni2ToMonth, Uni2ToYear, Uni2Program, Uni2Degree, Equivalence, Course1Name, Course1FromMonth, Course1FromYear, Course1ToMonth, Course1ToYear, Course1Degree, Course2Name, Course2FromMonth, Course2FromYear, Course2ToMonth, Course2ToYear, Course2Degree, WorkedGames, WorkedOlympics, WorkedParalympic, WorkedCommonwealth, WorkedPanam, WorkedCanada, International, IntAthlete, IntSeries, IntFromMonth, IntFromYear, IntToMonth, IntToYear, Emp1ActiveYear, Emp1WeekHours, Emp1YearMonths, Emp1EverFullTime, Emp1EverLocation, Emp1EverFromMonth, Emp1EverFromYear, Emp1EverToMonth, Emp1EverToYear, Emp1Name, Emp1FromMonth, Emp1FromYear, Emp1ToMonth, Emp1ToYear, Emp1Position, Emp1FullTime, Emp1Street, Emp1Apartment, Emp1City, Emp1Province, Emp1PostalCode, Emp1Contact, Emp1Phone, Emp1Income, Emp2Name, Emp2FromMonth, Emp2FromYear, Emp2ToMonth, Emp2ToYear, Emp2Position, Emp2FullTime, Emp2Street, Emp2Apartment, Emp2City, Emp2Province, Emp2PostalCode, Emp2Contact, Emp2Phone, Emp2Income, Emp3Name, Emp3FromMonth, Emp3FromYear, Emp3ToMonth, Emp3ToYear, Emp3Position, Emp3FullTime, Emp3Street, Emp3Apartment, Emp3City, Emp3Province, Emp3PostalCode, Emp3Contact, Emp3Phone, Emp3Income ) VALUES ('','member','','Associate Member','7/2/2009','3/3/2010','6/2/2008','Mr.','Fake','Fakington',0,1,0,0,0,'','','','','fake@gmail.com','','','','','','0',0,'','','','','','0','0','',0,0,0,'0',0,0,0,'0',0,0,0,'',0,0,0,'0','0',0,'0',0,0,0,0,'','',0,0,0,0,'','','',0,0,0,0,'','',0,'',0,0,0,0,'','',0,0,0,0,'',0,0,0,0,0,0,'','',0,0,0,0,'',0,0,0,0,0,'',0,0,0,0,0,0,0,'',0,'','','','','','','',0,'',0,0,0,0,'',0,'','','','','','','',0,'',0,0,0,0,'',0,'','','','','','','',0)

Microsoft OLE DB Provider for ODBC Drivers error '80040e14'

[Microsoft][ODBC SQL Server Driver][SQL Server]Line 1: Incorrect syntax near ','.

bitreaper
Jan 1, 2007

I got a call because a website I'd written a while back was "broken in IE fix it now". Some other guy had been making changes to the site and had no idea what was broken, so I figured it was easier just to fix all the rendering bugs by adding a conditional stylesheet than to try to track down his changes. I spent about half an hour hacking together fixes for everything before I realized what the problem was. He had removed the doctype and <html> tag entirely, sitewide, which sent IE into quirks mode and subsequently some kind of horrible deathspin. To date I have no idea what his rationale for doing that could have been.

pokeyman
Nov 26, 2006

That elephant ate my entire platoon.

bitreaper posted:

... Passport, , L2F, ...

It's funny; I laughed at the error message, then noticed what I imagine is the error (quoted) one second later.

Why can't I do that with my own code...

bitreaper
Jan 1, 2007

pokeyman posted:

It's funny; I laughed at the error message, then noticed what I imagine is the error (quoted) one second later.

Why can't I do that with my own code...

Weird, that's exactly what I did; I ran it through a validator and it just told me there was an error on line 1, then I noticed the double comma.

Ratty
Dec 6, 2005
At my old job some one once wrote:

code:
  for(int i = 1;i < 3; i++){

    if(i == 1){
      
      //the code did something here
       
    }


    if(i == 2){
      
      //the code did something here
       
    }

  }
The guy that wrote it had a good sense of humour so we printed it out and started a wall of shame.

-- Ratty

Jethro
Jun 1, 2000

I was raised on the dairy, Bitch!

Ratty posted:

At my old job some one once wrote:

code:
  for(int i = 1;i < 3; i++){

    if(i == 1){
      
      //the code did something here
       
    }


    if(i == 2){
      
      //the code did something here
       
    }

  }
The guy that wrote it had a good sense of humour so we printed it out and started a wall of shame.

-- Ratty

He was SO close to independently developing the FOR-CASE paradigm

-- Ratty

aeiou
Jul 12, 2006

It's cold in here...
Just kidding! It's to
fool enemies..

Jethro posted:

He was SO close to independently developing the FOR-CASE paradigm

-- Ratty

I have seen this a couple times in code at work and i fail to understand HOW people come up with this. And then afterword not realize that they could just have put all the statements in a row? Am I missing something here?

At my work we have an office in Russia. Now normally the people there are fine coders, but one person (who had left before I got there) has yet to show me an example of good coding. She would use variables like zzzz, zzz, zz, z, vvvv, vvv, vv and v in one javascript document. Not to mention table layouts and image slices on a web page built 10 months ago.

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

aeiou posted:

I have seen this a couple times in code at work and i fail to understand HOW people come up with this. And then afterword not realize that they could just have put all the statements in a row? Am I missing something here?

Being in a loop, you get to make use of the break keyword, and you have an iterator variable (i) which indicates which step was achieved... I used it once or twice like that anyway.

ashgromnies
Jun 19, 2004

such a nice boy posted:

What's wrong with that code? Is it just that
code:
if (_a > _b)
would have been better?

The way I see it - what if _b is == 0? Run-time error.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof

Mashi posted:

Being in a loop, you get to make use of the break keyword, and you have an iterator variable (i) which indicates which step was achieved... I used it once or twice like that anyway.

Are you serious? I have trouble imagining how that's more practical than something like this:

code:
function forCase() {
	if (firstProcess()) {
		return a;
	}
	if (secondProcess()) {
		return b;
	}
	if (thirdProcess()) {
		return c;
	}
}
Especially since a, b, and c can be made into something more useful than an iterator value with a vague and possibly transient meaning.

Mashi
Aug 15, 2005

Just wanted you to know your dinner's cold and the children all agree you're a shitheel!

DaTroof posted:

Are you serious? I have trouble imagining how that's more practical than something like this:

code:
function forCase() {
	if (firstProcess()) {
		return a;
	}
	if (secondProcess()) {
		return b;
	}
	if (thirdProcess()) {
		return c;
	}
}
Especially since a, b, and c can be made into something more useful than an iterator value with a vague and possibly transient meaning.

AI saw it as a way to avoid nesting an IF statement 6 levels deep. I never said it was good I just offered some possible reasoning for doing it. Also I am self taught so yea I used to do alot of weird and zany poo poo...

Heresiarch
Oct 6, 2005

Literature is not exhaustible, for the sufficient and simple reason that no single book is. A book is not an isolated being: it is a relationship, an axis of innumerable relationships.
At a previous job, I had to maintain a huge pile of very, very poorly-written PHP for a variety of homebrewed web applications. It had several major problems.

First, the guy who wrote it absolutely insisted that all of the code for a given application be in one PHP file.

Second, no documentation anywhere. No comments, no notes, no nothing. His variable names... well, see below.

Third, he didn't believe in functions. Everything was written as independent procedures, repeated as often as necessary. The only functions I found in his code were obviously cut-and-pasted from example books because they didn't match the rest of his style at all.

Fourth (and this is the real horror), he had an include.php file that had hundreds of lines of string replacements for HTML elements. And they looked like this:
code:
$TD = "<td>"
$td = "</td>"
Yes, he used uppercase names for the variables that contained the opening tags for HTML elements, and lowercase names for the variables that contained the closing tags. This made his code for page output almost entirely unreadable, on top of everything else he did wrong.

More often I ended up just throwing out big chunks of his code and replacing it entirely. I really wish I had had time to totally re-do the accounting system before handing it off to my replacement, because giving responsibility over that mess to someone else is probably the worst thing I've ever done to a human being.

ToastedZergling
Jun 25, 2007

Chubby Walrus:
The Essence of Roundness
I saw something like the when I first worked for a client that had an "ecommerce site that is 90% complete, but the developer bailed..."

<?php

// turn any post or get into a variable...
foreach($_REQUEST as $key => $value){
eval($key.' = '.$value);
}
// wing it
if($sql == ""){
} else {
mysql_query($sql);
}

?>

Somehow I knew that 90% was much closer to 9%.

DaTroof
Nov 16, 2000

CC LIMERICK CONTEST GRAND CHAMPION
There once was a poster named Troof
Who was getting quite long in the toof
Haha. Somehow that reminded me of an ecommerce site I saw at a development firm that eventually went belly up. I think I've been blocking it from my conscious memory for the past few years.

* The lead developer declared that ASP was insecure, so everything had to be written as CGI executables in Visual Basic.

* He also didn't trust IIS, so the web server was O'Reilly WebSite. The 16-bit free version.

* The order database was written in Access. Every order had its own MDB file. When somebody started an order, one of the CGI programs would copy an empty version of the database and populate it with a single order. Every MDB was named for its order number: 1001.mdb, 1002.mdb, etc.

* The customer's credit card information was stored in plain text in the MDB.

* The web server needed to be restarted several times a day because of a bug that was causing HTTP requests to hang. After a few days, I discovered the problem when I checked the server's monitor. One of the CGI programs was popping a message box with debug information. The process would halt while it waited for someone to click the OK button.

* In response to the above problem, the lead developer sincerely suggested that one of us sit next to the server so we could watch for message boxes.

The site finally died after 1500 orders, because each order was in a separate 200k MDB file and the server's drive ran out of space. Less than twenty of those orders were actually completed. Most of them were in-house tests. The vast majority only had one or two items in the order. Hundreds of 200k databases that each contained less than 400 bytes of actual data.

And of course, after we took the machine offline for an emergency tuneup, it quickly became apparent that someone had compromised it weeks ago.

Eight years later, that poor bastard of a client finally has a functional web site, but they still don't take orders online.

iamstinky
Feb 4, 2004

This is not as easy as it looks.

aeiou posted:

I have seen this a couple times in code at work and i fail to understand HOW people come up with this. And then afterword not realize that they could just have put all the statements in a row? Am I missing something here?

I think it comes from writing on the fly. Initially you write one statement to be evaluated and everything works fine. Then you have to make a decision if the counter has some other value. So you say if it's value I definitely need to do it this way and if it's value 2 I may need to do it a different way. Then all the sudden the code is done and you realize that you are in essence doing the same thing regardless of value. At this point you may or may not have time to fix it.

So I think it's a lack of pre-planning.

ashgromnies
Jun 19, 2004

DaTroof posted:

Haha. Somehow that reminded me of an ecommerce site I saw at a development firm that eventually went belly up. I think I've been blocking it from my conscious memory for the past few years.

* The lead developer declared that ASP was insecure, so everything had to be written as CGI executables in Visual Basic.

* He also didn't trust IIS, so the web server was O'Reilly WebSite. The 16-bit free version.

* The order database was written in Access. Every order had its own MDB file. When somebody started an order, one of the CGI programs would copy an empty version of the database and populate it with a single order. Every MDB was named for its order number: 1001.mdb, 1002.mdb, etc.

* The customer's credit card information was stored in plain text in the MDB.

* The web server needed to be restarted several times a day because of a bug that was causing HTTP requests to hang. After a few days, I discovered the problem when I checked the server's monitor. One of the CGI programs was popping a message box with debug information. The process would halt while it waited for someone to click the OK button.

* In response to the above problem, the lead developer sincerely suggested that one of us sit next to the server so we could watch for message boxes.

The site finally died after 1500 orders, because each order was in a separate 200k MDB file and the server's drive ran out of space. Less than twenty of those orders were actually completed. Most of them were in-house tests. The vast majority only had one or two items in the order. Hundreds of 200k databases that each contained less than 400 bytes of actual data.

And of course, after we took the machine offline for an emergency tuneup, it quickly became apparent that someone had compromised it weeks ago.

Eight years later, that poor bastard of a client finally has a functional web site, but they still don't take orders online.

Whenever I feel insecure about my programming skills, there's always a story like this to make me think, "At least I'm not completely retarded."

ohrwurm
Jun 25, 2003

Some gems from an ASP app that I inherited:

code:
if strCompanyID = "1" then
    intCompanyID = 1
elseif strCompanyID = "2" then
    intCompanyID = 2
elseif strCompanyID = "3" then
    intCompanyID = 3
elseif strCompanyID = "4" then
    intCompanyID = 4
end if
:what:

code:
strsql = ""
  strsql = "select AppVars.RecordID From AppVars where AppVars.VarName = 'RAFDE'" 
  set rsGetRAFDE = Server.CreateObject("ADODB.Recordset")
  rsGetRAFDE.ActiveConnection = connection
  rsGetRAFDE.Open(strsql)
  if not rsGetRAFDE.EOF then
    strRAFDE = cstr(rsGetRAFDE.Fields("RecordID"))
  end if
  rsGetRAFDE.Close
  set rsGetRAFDE = nothing

  strsql = ""
  strsql = "select AppVars.RecordID From AppVars where AppVars.VarName = 'RAF2'" 
  set rsGetRAF2 = Server.CreateObject("ADODB.Recordset")
  rsGetRAF2.ActiveConnection = connection
  rsGetRAF2.Open(strsql)
  if not rsGetRAF2.EOF then
    strRAF2 = cstr(rsGetRAF2.Fields("RecordID"))
  end if
  rsGetRAF2.Close
  set rsGetRAF2 = nothing
This block above gets used about 10 more times in the exact same way, just to set some variables. It's like they have never heard of functions.

Imagine at least 25 pages of this at several thousand lines each littered with inline sql, years of uncommented edits, and tons of copied and pasted code and you will see what I work with daily.

Bastard
Jul 13, 2001

We are each responsible for our own destiny.
I posted this before, and by God, I'll post it again. A PHP gem created by a freelancer we hired:

code:
//init vars
$a;
$b;
$c;
...
$z;
This was complimented by no documentation whatsoever, and each var had a different type value, based on where it was used in the code. So at one time, $a was an array, somewhat later a string, after that a number (as in: use it like an int).

Debugging that was an interesting experience in anger control.

MrMoo
Sep 14, 2000

Eggplant posted:

Some gems from an ASP app that I inherited:
ASP always seems to promote the worst coding. I just wonder how these people think. Do they take days to do a couple of lines and forget half way through, or are just blind drunk?
code:
/* start poo poo */
$strNotFind=0;
$strData=$MyRS["size"];
while(strlen($strData)>0)
{
  $linLen=strlen($strData);
  $delimPos=(strpos($strData,"/") ? strpos($strData,"/")+1 : 0);
  if ($delimPos==$strNotFind && $linLen>0) {
    print "<option>".$strData."</option>";
    $delimPos=$linLen;
  } else {
    print "<option>".substr($strData,0,($delimPos-1))."</option>";
  } 
  $strData=substr($strData,strlen($strData)-($linLen-$delimPos));
}
/* end poo poo */

mantaworks
May 6, 2005

by Fragmaster
It's not as bad as many of you encountered, but it deserves a post.

code:
theater.movieb1.onRollOver = function() {
	pichover_right(this, 0);
	this.swapDepths(1000);
};
theater.movieb1.onRollOut = function() {
	pichout_right(this);
	//this.swapDepths(2);
};
theater.movieb2.onRollOver = function() {
	pichover_right(this, 0);
	this.swapDepths(1000);
};
theater.movieb2.onRollOut = function() {
	pichout_right(this);
	//this.swapDepths(2);
};
theater.movieb3.onRollOver = function() {
	pichover_right(this, 0);
	this.swapDepths(1000);
};
theater.movieb3.onRollOut = function() {
	pichout_right(this);
	//this.swapDepths(2);
};
theater.movieb4.onRollOver = function() {
	pichover_right(this, 0);
	this.swapDepths(1000);
};
theater.movieb4.onRollOut = function() {
	pichout_right(this);
	//this.swapDepths(2);
};
// When clicking home
menu.menuleft.home_mc.home.onRelease = function() {
	if(menu != 0){
		newpage = 0;
		if(page == 0) {trace("You are already home!");}
		if(page != 0) {buildup();}
		if(page == 1) {cleanup();}
		if(page == 2) {cleanup();}
		if(page == 3) {cleanup();}
		if(page == 4) {cleanup();}
		if(page == 5) {cleanup();}
		if(page == 6) {cleanup();}
		page = 0;
		menu.menuleft.home_mc.gotoAndStop("down");
		menu.menuleft.about_mc.gotoAndStop("up");
		menu.menuleft.mark_mc.gotoAndStop("up");
		menu.menuleft.hall_mc.gotoAndStop("up");
		menu.menuleft.theater_mc.gotoAndStop("up");
		menu.menuleft.available_mc.gotoAndStop("up");
		menu.menuleft.contact_mc.gotoAndStop("up");
	};
};
Repeat this for about ten times and with random lines of code commented or added.

j4cbo
Nov 1, 2004
huh?
I wrote this. You'll need a decent grasp of x86 assembly to comprehend the horror...

code:
/* void iret(int addr, ...); */
.global iret
iret:
        add $4, %esp 
        iret

Scaevolus
Apr 16, 2007

j4cbo posted:

I wrote this. You'll need a decent grasp of x86 assembly to comprehend the horror...
To be fair, Assembly doesn't really lend itself to clear and readable code (without having a 1:1 opcode:comment ratio).

more falafel please
Feb 26, 2005

forums poster

j4cbo posted:

I wrote this. You'll need a decent grasp of x86 assembly to comprehend the horror...

code:
/* void iret(int addr, ...); */
.global iret
iret:
        add $4, %esp 
        iret

x86 isn't my strong suit, but isn't that basically infinite recursion without overflowing the stack? I guess I'm assuming that 'iret' on its own is a call of some sort.

trex eaterofcadrs
Jun 17, 2005
My lack of understanding is only exceeded by my lack of concern.
iret is an interrupt vector return. If I'm understanding this right, it's like a hosed up longjmp.

_aaron
Jul 24, 2007
The underscore is silent.
This isn't as bad as some of the trainwrecks in here, but it made me scratch my head for a minute.
code:
 (C#)
for (int i = 0; i < this.publishToClients.Count; i++)
{
   if (this.publishToClients[ i] is PublishToSetting)
   {
      PublishToSetting client = this.publishToClients[ i];
      if (clientStr.CompareTo("") != 0 )
      {
         //add a comma if it isn't the first client in the string
         clientStr += ",";
      }
      clientStr += client.Alias + ":" + client.Ip + ":" + client.Port + ":" + client.TheProtocol;
   }
}
This is for writing out configuration data to a file. First of all, we have no reason here to not be using a 'foreach' loop instead of a counter-controlled 'for' loop. Secondly, "publishToClients" is an instance of a custom collection class (actually just a derivation of list because people on this team didn't learn about generics until recently) that is guaranteed to only hold objects of type PublishToSetting. That first 'if' statement is completely useless. Lastly, and this could be just personal preference, but they have the special first case handling in the loop rather than doing it once before the loop and then not worrying about any handling for that inside.

I swear my coworkers aren't idiots. I think this is just a case of coding something out and then not really looking it over once you're done with it.

Victor
Jun 18, 2004
code:
string clientStr = this
    .publishToClients
    .OfType<PublishToSetting>()
    .Select(c => string.Format("{0}:{1}:{2}:{3}", c.Alias, c.Ip, c.Port, c.TheProtocol))
    .Join(",");
(string Join(string delimiter) is a method I made, because MS didn't include it by default, for some odd reason.)

_aaron
Jul 24, 2007
The underscore is silent.

Victor posted:

code:
string clientStr = this
    .publishToClients
    .OfType<PublishToSetting>()
    .Select(c => string.Format("{0}:{1}:{2}:{3}", c.Alias, c.Ip, c.Port, c.TheProtocol))
    .Join(",");
(string Join(string delimiter) is a method I made, because MS didn't include it by default, for some odd reason.)
Hahaha, that's pretty awesome. But correct me if I'm wrong here: most of that stuff is .Net 3.5 stuff, right? We are still using vs2005 (but will be upgrading soon), so that doesn't apply to our stuff. When we do make the switch, I will certainly keep this in mind.

grimace
Jun 20, 2001

Jon Bence don't take
no phone surveys
because he's dead
RIP 19__ - 2009, 580 lbs
Most of the stuff that I find that makes me want to die is far more basic than the other stuff posted so far. Like this:

code:
//string st = MessageBox.Show("Are you sure you want to delete?","Delete",MessageBoxButtons.YesNo).ToString ();
            //if (st == "Yes")
            //{

            try
            {
                /*
                code that actually deletes something
                */
                Label7.Visible = true;
                Label7.Text = "Deleted Successfully";
            }
            catch (Exception ex)
            {
                Label7.Visible = true;
                Label7.Text = "Can't Delete. <br/> Following Exception raised " + ex;
            }
// }
Yes, this is in an ASP.NET site.

edit: It gets better. Every control on the page is generically named (LinkButton1, LinkButton2, Label3, Label4, etc), and whoever wrote it used at least 4 labels (that I can initially see) instead of validators for error messages.

Also, every method has SQL in it, and it's all inline. Better yet, half of it is duplicated from another page.

grimace fucked around with this message at 19:55 on Mar 26, 2008

Victor
Jun 18, 2004

_aaron posted:

Hahaha, that's pretty awesome. But correct me if I'm wrong here: most of that stuff is .Net 3.5 stuff, right? We are still using vs2005 (but will be upgrading soon), so that doesn't apply to our stuff. When we do make the switch, I will certainly keep this in mind.
Yup, .NET 3.5, C# 3.0.

chocojosh
Jun 9, 2007

D00D.
When I first started my current C# job I hadn't touched HTML for about two years besides one database university course. I had also never touched .NET.

I was first asked to convert a simple page from asp to ASP.NET. For some stupid reason I didn't realize that drop down lists had a text and a value property. I ended up creating a "DropDownInfo" class to map the texts displayed to the IDs via two hashtables, and you'd see code all over the place like:

code:
Page_Load() {
   Get drop down text and IDs from stored procedure
   Store the texts and IDs into an instance of the dropdowninfo class
   Databind the texts to the dropdown lists
}

Update_Button_Click_Handler() {
   Get the selected text from the drop down list.
   Get the matching ID from the drop down info.
   Pass the matching ID to the stored procedure to update.
}
Ugggh. The senior dev didn't have the heart to tell me to rewrite it as it was my first time and that page is very rarely updated.

EssOEss
Oct 23, 2006
128-bit approved

Victor posted:

string Join(string delimiter) is a method I made, because MS didn't include it by default, for some odd reason.)

I disagree. string.Join has existed ever since 1.0.

MSDN Library posted:

code:
public static string Join(
	string separator,
	string[] value
)
.NET Framework
Supported in: 3.5, 3.0 SP1, 3.0, 2.0 SP1, 2.0, 1.1, 1.0

Adbot
ADBOT LOVES YOU

Victor
Jun 18, 2004
Notice how the signature between what I posted differs from what you posted. Moreover, mine works on IEnumerable<string> and is an extension method. Here's the definition:
code:
public static string Join(this IEnumerable<string> strings, string delimiter)
{
    return strings.Any()
        ? string.Join(delimiter, strings as string[] ?? strings.ToArray())
        : "";
}

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