Jump to content

Bad, terrible or simply funny code examples

I thought it might be nice if we had somewhere to post our examples of bad, terrible or downright hilarious code. Code that we may encounter throughout our day or maybe while fixing bugs that just makes us want to role on the floor laughing or go in the corner and cry.

 

 

 

I'll start by sharing some of the gems I had the distinct pleasure of encountering today (C#):

 

Number One

System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(64)))), ((int)(((byte)(64)))));

I think the developer was either drunk, sleep deprived or a combination of both perhaps :) Yes we are indeed casting an integer to a byte and then back to an integer again...

 

Number Two

Next was a class instanced in the context of a number of threads. Only problem was that most of it's variables were declared as static. The problem with that in this context was that they were unintentionally shared across the threads and therefore ended up getting mashed. This resulted in a lovely race condition higher up in the application.

 

Number Three

Thread.Sleep([insert any absurd value]);

Lastly the use of many, many Thread.Sleeps, obviously to try to address bugs such as the one mentioned above!

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

Java.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Java.

Why the hell is everyone hating on Java?

It's good at what it does.

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Why the hell is everyone hating on Java?

It's good at what it does.

Cause the way you code it is horrendous. Has almost no logical order or sense to it.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Cause the way you code it is horrendous. Has almost no logical order or sense to it.

Compared to what?

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Compared to what?

Compared to Python, C, C sharp, C++, and others. Python is one of the most orderly logical languages, which is why it is the best for beginners. The code is very 'readable' if you know what I mean :)

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Compared to Python, C, C sharp, C++, and others. Python is one of the most orderly logical languages, which is why it is the best for beginners. The code is very 'readable' if you know what I mean :)

Going from Java to C++, I had to learn syntax differences mainly(and other things like pointers,etc.)

i5 4670k @ 4.2GHz (Coolermaster Hyper 212 Evo); ASrock Z87 EXTREME4; 8GB Kingston HyperX Beast DDR3 RAM @ 2133MHz; Asus DirectCU GTX 560; Super Flower Golden King 550 Platinum PSU;1TB Seagate Barracuda;Corsair 200r case. 

Link to comment
Share on other sites

Link to post
Share on other sites

Cause the way you code it is horrendous. Has almost no logical order or sense to it.

 

Does not apply to the thread's topic per say, since it is not code, but equally hilarious.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Going from Java to C++, I had to learn syntax differences mainly(and other things like pointers,etc.)

Yeah you have to learn different syntax when switching to most languages, but it's a lot harder to learn java when stuff doesn't make perfect sense like you would expect. For example its a shit ton harder to go from python to java than java to python.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Does not apply to the thread's topic per say, since it is not code, but equally hilarious.

Well really all of java is code, and all of it is hilarious xD

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Well really all of java is code, and all of it is hilarious xD

 

Sorry, I was actually talking about what you said, not Java. :P

I disagree wholeheartedly with you.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Sorry, I was actually talking about what you said, not Java. :P

I disagree wholeheartedly with you.

Well then you can go to whyjavasucks.com to get all the necessary reasons. Hilarious that people use that crap as much as they do.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

Well then you can go to whyjavasucks.com to get all the necessary reasons. Hilarious that people use that crap as much as they do.

 

So whyjavasucks.com is your source of information? I'll give it to you, there are some pretty funny pictures there. But the texts that are supposed to show why java sucks (which are very few) are just stupid pet peeves, or a complete disregard for why things are the way they are (maybe they don't know good OOP). Clearly they favor C#, and as such have this anti-Java thing for the stupidest things.

 

Again, people hating on Java are hilarious. It's one of the most well designed languages out there for the OOP paradigm. Every language design has some flaws, and Java is no exception, but it is a great language overall.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

So whyjavasucks.com is your source of information? I'll give it to you, there are some pretty funny pictures there. But the texts that are supposed to show why java sucks (which are very few) are just stupid pet peeves, or a complete disregard for why things are the way they are (maybe they don't know good OOP). Clearly they favor C#, and as such have this anti-Java thing for the stupidest things.

 

Again, people hating on Java are hilarious. It's one of the most well designed languages out there for the OOP paradigm. Every language design has some flaws, and Java is no exception, but it is a great language overall.

 

Hehe that site was really funny :)

"Warning: Visualizing the code snippet below in its full scale may cause night terrors." Just epic!

 

I agree with @wolfsinner on all of his points though. Plus it's against my personal doctrine to really dislike a language.

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

So whyjavasucks.com is your source of information? I'll give it to you, there are some pretty funny pictures there. But the texts that are supposed to show why java sucks (which are very few) are just stupid pet peeves, or a complete disregard for why things are the way they are (maybe they don't know good OOP). Clearly they favor C#, and as such have this anti-Java thing for the stupidest things.

 

Again, people hating on Java are hilarious. It's one of the most well designed languages out there for the OOP paradigm. Every language design has some flaws, and Java is no exception, but it is a great language overall.

No its just a small joke about it. But from all of the professional coders that I know they just hate working with java, and much prefer C languages. It's great for doing stuff with and is used in many places, but the way it was designed is less than ideal.

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

I don't hate Java because Java is bad, I hate Java because I hate all Java IDEs.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

[...] but the way it was designed is less than ideal.

 

I'm genuinely curious, please elaborate.

 

 

I don't have Java because Java is bad, I hate Java because I hate all Java IDEs.

 

Do you mean hate instead of have? I used to loathe Eclipse, but I've grown accustomed to it. :P I really dislike most native Java IDEs, and even used to write Java code in Visual Studio, which is funny.

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm genuinely curious, please elaborate.

Python:

print ("Hello, world!")

 

Java:

public class HelloWorld{        public static void main (String[] args)        {                System.out.println("Hello, world!");        }}

NEW PC build: Blank Heaven   minimalist white and black PC     Old S340 build log "White Heaven"        The "LIGHTCANON" flashlight build log        Project AntiRoll (prototype)        Custom speaker project

Spoiler

Ryzen 3950X | AMD Vega Frontier Edition | ASUS X570 Pro WS | Corsair Vengeance LPX 64GB | NZXT H500 | Seasonic Prime Fanless TX-700 | Custom loop | Coolermaster SK630 White | Logitech MX Master 2S | Samsung 980 Pro 1TB + 970 Pro 512GB | Samsung 58" 4k TV | Scarlett 2i4 | 2x AT2020

 

Link to comment
Share on other sites

Link to post
Share on other sites

I don't have Java because Java is bad, I hate Java because I hate all Java IDEs.

 

Do you mean hate instead of have? I used to loathe Eclipse, but I've grown accustomed to it. :P I really dislike most native Java IDEs, and even used to write Java code in Visual Studio, which is funny.

 

What about IntelliJ? It's built upon the power of ReSharper after all.  :wub:

The single biggest problem in communication is the illusion that it has taken place.

Link to comment
Share on other sites

Link to post
Share on other sites

 

Python:

print ("Hello, world!")

Java:

public class HelloWorld{        public static void main (String[] args)        {                System.out.println("Hello, world!");        }}

 

That's all I needed to know. Thanks. ;)

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

What about IntelliJ? It's built upon the power of ReSharper after all.  :wub:

 

I never used it, but looks interesting. Will give it a look, thanks. :P

 

EDIT: To stay on-topic. Here's something that I encounter a lot, and that makes me cringe a little.

 

if(condition) return true;else return false;

Want to solve problems? Check this out.

Link to comment
Share on other sites

Link to post
Share on other sites

Do you mean hate instead of have? I used to loathe Eclipse, but I've grown accustomed to it. :P I really dislike most native Java IDEs, and even used to write Java code in Visual Studio, which is funny.

Yes I did, thx. Eclipse if definitely the best I've tried but between random crashes and being incredibly slow sometimes it was just a pain to use. I guess it's worth noting I haven't really done much coding in Java in 5ish years so things may have changed.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

i don't know if someone else here went through the pain of programming in Ladder

oh, the rage

Link to comment
Share on other sites

Link to post
Share on other sites

I work at a company with very large complicated enterprise applications written java. Since the majority of the code is legacy and written in like java 2 we see a lot of stuff like putting random object types in the same collection (no generics) and people trying to use multithreading without having any idea how it works. So it's my teams job to clean up all this crappy code and refactor to allow for more features and better performance.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×