Jonathan Boccara's blog

10 Halloween Horror Code Stories That Will Freak You Out

Published October 31, 2017 - 4 Comments

Halloween C++

Tonight is Halloween!

The day of the dead, the day where people go around dressed up as ghosts, vampires and other zombies to celebrate and actually… have fun!

Yeah, Halloween is that too. I’ve looked it up a bit and found out that there are some customs of Halloween that don’t really relate to the dead. Like apple bobbing, for example. I’ve never bobbed an apple but man, that looks like fun.

But since we can’t exactly bob apples on a blog, let’s do another customary Halloween thing: telling horror stories! But not just any horror story. Horror code stories.

I’ve asked around and scoured the web searching for the ugliest, scariest pieces of code that programmers have laid eyes on. So we’re taking a day off from expressive code here, going quite to the opposite actually.

I’ve compiled my 10 favourite ones together here. I’ve tried to put as many as possible in C++, but I couldn’t resist including some pearls in other languages too. Don’t hesitate to add comments if you know other examples of scary and ugly horror code!

Even though some of them might send a chill down your back, like all things with Halloween, they’re a bit of fun too 🙂

Happy Halloween!

1) A multithreading tip

How can you make a thread communicate a piece of information to another thread? Nothing easier, the file system is waiting for you:

Thanks Kev for sharing this brilliant one!

2) Algorithms on sets

We’ve already come across the importance knowing our algorithms.

How can we return the element of a set that has the higher number of occurrences? Here is a pretty brave attempt:

Horror code

Source: Reddit (https://i.redd.it/ms7pd9skf85y.png)

3) Checking if a point is inside a rectangle

We have two classes point and rect that represent a point and a rectangle respectively. Given a point and a rectangle, how to check whether the point is located inside the rectangle?

Here is a very, very meticulous method:

horror code

Source: Reddit (https://i.redd.it/6zyfbwabjr4y.png)

4) Odd numbers

Is a number odd? At least, this code is:

horror code

Source: Imgur (https://i.imgur.com/k6zfz4O.png)

horror code C++

5) Expressive field name

This one is taken from the .NET framework. Consider the following field:

Looks like it enables some optimizations related to the JIT, right?

Well, here is what the documentation says:

Specifies that just-in-time (JIT) compiler optimization is disabled for the assembly. This is the exact opposite of the meaning that is suggested by the member name.

(bold font is mine).

horror code

6) Idiomatic C++

Thanks to Jens Weller for sending this one in:

This is C++. But not really in its most glorious and idiomatic form:

7) Is this a prime number?

Here is a pretty incredible function that checks whether a given number is prime. To illustrate, its prototype starts like this (I especially love the greeting comment):

Here is the complete code (click to enlarge):

horror code

Source: discordapp.com

Pretty amazing, huh?

horror code

8) Downright ugly

This one is plain ugly. If you’re a sensitive person, maybe you want to look away while performing one energetic scroll-down with your mouse to skip over it (click to enlarge):

horror code C++

Source: markland.fr

9) Robust binary to decimal

Starting from a string representing a binary number, here is a maybe not so robust piece of code that converts it to a number in base 10:

horror code

Source: Reddit (https://i.redd.it/4zduxp6lb85z.jpg)

…and it goes all the way down to 63, of course.

10) An unexpected end

Let’s close off this distressing Halloween series with an innocent piece of code that got violently severed to meet an unexpected end (notice that there are 745 lines of code below that return statement):

horror code

Source: Reddit (https://i.redd.it/6ifqlo0m04fz.png)

Oops. I know, it’s hard to sustain.

Bonus

Here is a little piece of innocuous-looking code, but that can cause horrible pain to debug. Courtesy of reader Tomek Jonarski who posted it in the comments section:

Thanks Tomek!

Let’s go bob some apples

That was gory!

If you share this article with a friend or colleague, make sure they’re not afraid of looking at this kind of unsettling code. And if they are, bobbing a couple of apples could be just the thing to relax after this! And if you know other pieces of horrible code don’t hesitate to put them in comments.

Happy Halloween!

horror code C++

Share this post! Facebooktwittergoogle_pluslinkedin    Don't want to miss out ? Follow:   twitterlinkedinrss

Receive regular updates to make your code more expressive.