Worst C# code you've ever seen in production?

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4

45 Replies - 31552 Views - Last Post: 18 June 2015 - 09:10 AM

#16 MATTtheSEAHAWK  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 137
  • View blog
  • Posts: 782
  • Joined: 11-September 10

Re: Worst C# code you've ever seen in production?

Posted 09 December 2010 - 03:53 PM

I shall translate that:
bool value = true;
MessageBox.Show(value.ToString());



Owned.
Was This Post Helpful? 0
  • +
  • -

#17 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: Worst C# code you've ever seen in production?

Posted 10 December 2010 - 02:33 AM

if([i]conditional or method[/i])
    MessageBox.Show("True");
else
    MessageBox.Show("False");



I believe you just got one-upped :bananaman:
Was This Post Helpful? 0
  • +
  • -

#18 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Worst C# code you've ever seen in production?

Posted 10 December 2010 - 06:08 AM

While they are very similar, I think mine is worse because it was used enough to warrant it's own method call.
Was This Post Helpful? 0
  • +
  • -

#19 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Worst C# code you've ever seen in production?

Posted 10 December 2010 - 09:54 AM

I also found this one. It's not a "worst" though.

/// <summary>
/// Summary description for VirtualBrain.
/// </summary>
public class VirtualBrain
{
	/// <summary>
	/// VirtualBrain constructor
	/// </summary>
	public VirtualBrain()
	{

	}

	/// <summary>
	/// Gets the Ultimate Answer to Life the Universe and Everything
	/// </summary>
	/// <returns>the Ultimate Answer to Life the Universe and Everything</returns>
	/// <remarks>http://en.wikipedia.org/wiki/The_Answer_to_Life,_the_Universe,_and_Everything</remarks>
	public int GetTheUltimateAnswerToLifeTheUniverseAndEverything()
	{
		return 1 + 5 * 8 + 1;
	}
}



When I first heard of this project, which has been in ongoing development for almost 8 years, we were told to NEVER, EVER touch the VirtualBrain class because it housed the code that ran the entire system.

This was everything that is in the VirtualBrain class.
Was This Post Helpful? 0
  • +
  • -

#20 Adkins  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 66
  • View blog
  • Posts: 560
  • Joined: 27-October 09

Re: Worst C# code you've ever seen in production?

Posted 10 December 2010 - 09:57 AM

:bananaman: that is outstanding! :bananaman:
Was This Post Helpful? 0
  • +
  • -

#21 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon

Reputation: 2298
  • View blog
  • Posts: 9,535
  • Joined: 29-May 08

Re: Worst C# code you've ever seen in production?

Posted 10 December 2010 - 10:22 AM

View Posteclipsed4utoo, on 10 December 2010 - 04:54 PM, said:

... snip ..,

public int GetTheUltimateAnswerToLifeTheUniverseAndEverything()
	{
		return 1 + 5 * 8 + 1;
	}
}


... snip ...

Hopefully the Compiler simplifies it to a constant

Depend if you're a proper fan / geek of the hhgttg, if are you know that is also correct. What do you get if multiply Six by Nine?


Was This Post Helpful? 1
  • +
  • -

#22 Guest_iScotts*


Reputation:

Re: Worst C# code you've ever seen in production?

Posted 12 December 2010 - 12:33 AM

Wow this is interesting. But do you guys think it would be better to also post the "correct" alternative one could use. This will help a lot of beginner programmers like myself.
Was This Post Helpful? 0

#23 Curtis Rutland  Icon User is offline

  • (╯□)╯︵ (~ .o.)~
  • member icon


Reputation: 5101
  • View blog
  • Posts: 9,283
  • Joined: 08-June 10

Re: Worst C# code you've ever seen in production?

Posted 13 December 2010 - 08:23 AM

Not really. This isn't a teaching thread, more of a "share your horror stories" thread. There really isn't a good way to give "proper" examples of most of these, since they all rely on other context that we don't have.
Was This Post Helpful? 0
  • +
  • -

#24 CodeGrappler  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 120
  • Joined: 29-November 10

Re: Worst C# code you've ever seen in production?

Posted 17 December 2010 - 01:15 PM

I'm currently converting an internal API from VB6 to C# for the company I work for, and this API has a VB6 form in it with over 10,000 lines of code. Refactoring? Whats that?
Was This Post Helpful? 0
  • +
  • -

#25 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Worst C# code you've ever seen in production?

Posted 17 December 2010 - 03:53 PM

That was probably a back in the day where "spaghetti code can be so good" ruled the work place. When VB6 was out there was little thought of refactoring things. You just threw it all in the pot and hoped it worked as it was supposed to. If you found something that didn't work quite right, just throw more code at it until it worked right.
Was This Post Helpful? 0
  • +
  • -

#26 CodeGrappler  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 41
  • View blog
  • Posts: 120
  • Joined: 29-November 10

Re: Worst C# code you've ever seen in production?

Posted 17 December 2010 - 04:25 PM

It most definitely is from way back in the day. But still it's insane and horrible.
Was This Post Helpful? 0
  • +
  • -

#27 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Worst C# code you've ever seen in production?

Posted 17 December 2010 - 07:58 PM

That I would agree with 100%. If you're ever stuck with it, talk with SpectateSwamp. He likes that sort of code.
Was This Post Helpful? 0
  • +
  • -

#28 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1533
  • View blog
  • Posts: 5,972
  • Joined: 21-March 08

Re: Worst C# code you've ever seen in production?

Posted 20 December 2010 - 01:47 PM

We have a project for a customer that was written about 6 years ago in VB6. It's so horrible. We almost have the client ready to move it to .Net. When we go to make changes, we don't try to do anything else for the fear of breaking it. There are so many things wrong with it, it's amazing that it even runs.
Was This Post Helpful? 0
  • +
  • -

#29 Theomi  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 9
  • View blog
  • Posts: 88
  • Joined: 17-January 10

Re: Worst C# code you've ever seen in production?

Posted 08 January 2011 - 03:36 PM

View PostSixOfEleven, on 17 December 2010 - 02:53 PM, said:

That was probably a back in the day where "spaghetti code can be so good" ruled the work place. When VB6 was out there was little thought of refactoring things. You just threw it all in the pot and hoped it worked as it was supposed to. If you found something that didn't work quite right, just throw more code at it until it worked right.


Oh good god i could not stop laughing...
Was This Post Helpful? 0
  • +
  • -

#30 marinus  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 138
  • View blog
  • Posts: 575
  • Joined: 14-April 10

Re: Worst C# code you've ever seen in production?

Posted 26 May 2011 - 09:50 PM

View PostSergio Tapia, on 03 December 2010 - 07:21 PM, said:

How can you use C# and not use functions? Wow!

Another one I saw just this morning:

if(cond1)
{
    if(cond2)
    {
        if(cond3)
        {
         ....//7 layers deep.



I pity my friend/coworker because he's the one stuck maintaining this particular aspect of the codebase.


I did that once , becomes quickly unmanageable mess. And a debugging pain .
Was This Post Helpful? 0
  • +
  • -

  • (4 Pages)
  • +
  • 1
  • 2
  • 3
  • 4