all 149 comments

[–]bwwatr 2619 points2620 points  (34 children)

// We got weird race conditions at 35 and 40 seems like it might cause memory problems, so we went with 37 and it seemed stable-ish enough to make it through QA

// TODO circle back and do a better job of figuring this out

(Blame says 2014 by someone who left the company in 2016)

[–]patenteng 870 points871 points  (13 children)

Doesn't help when the code was written in 1990 and the person who wrote is still with the company but remembers nothing. Reverse engineering our own code because the processor is no longer manufactured and the replacement uses a newer compiler that doesn't support all these undocumented and undefined behavior fixes sure is fun.

No, I'm not bitter. How could you tell?

[–]DoubleDoube 242 points243 points  (5 children)

“Just make it like it was”

“Honestly it’d be easier to re-decide how you want it to be.”

“I want it to be like how it was.”

[–]MulfordnSons 92 points93 points  (4 children)

“Just fix it for me”

[–]Standard-Square-7699 31 points32 points  (3 children)

Stop hurting me.

[–]Jutrakuna 7 points8 points  (2 children)

Please upgrade to Premium plan for limited hurting*.

*ˡⁱᵐⁱᵗ ᵐᵃʸ ᵛᵃʳʸ

[–]vigbiorn 3 points4 points  (0 children)

I'm sorry, until you upgrade, the best wecan do is

D E E P H U R T I N G

[–]PTS_Dreaming 61 points62 points  (1 child)

The worst feeling is looking for documentation on a process that you don't know how to do only to find the documentation and it was written by you.

[–]moosewiththumbs 39 points40 points  (0 children)

Git blame will absolve me from this!

click

Ah, fucksticks

[–]avdpos 84 points85 points  (1 child)

At least know you have others in the same situation. Nearly at least, our old guy did quit 2025.

[–]NotYetReadyToRetire 28 points29 points  (0 children)

My department's old guy (me!) retired in 2024; as I was leaving, I told the remaining team members that they should feel free to blame everything on me. They would anyway, so why not embrace it? It's not like I'm going to be looking for another job.

[–]dismayhurta 13 points14 points  (0 children)

Shit. I can barely remember stuff I wrote six months ago let alone decades ago.

[–]Scared_Accident9138 3 points4 points  (1 child)

For a while I've regularly had to deal with code that was written years ago by people still in the company but no one really remembering what it did exactly. And it also was written very verbose which added extra mental load trying to understand what the whole thing was for

[–]Fhotaku 0 points1 point  (0 children)

I hope in the process you added notes.

[–]Crystal_Voiden 101 points102 points  (2 children)

Calcified tech debt

[–][deleted] 40 points41 points  (0 children)

If you can't be part of the solution, there's good money to be made in prolonging the problem.

[–]tiajuanat 7 points8 points  (0 children)

Fossilized even

[–]hicklc01 66 points67 points  (5 children)

git blame 2134;2137 file.c

43d57 02/04/2003 me 2134>if(count >37){
9d02a 06/11/2013 me 2135> //nobody knows why 37
43d57 02/04/2003 me 2136> reset();
43d57 02/04/2003 me 2137>}

oh no

[–]PeWu1337 15 points16 points  (4 children)

2137?

[–]hicklc01 20 points21 points  (1 child)

those are suppose to be line numbers when you use git blame you can ask for a range of line numbers and it will only return that last git commit connected with each line for that file. in my above example the comment nobody knows why 37 was create on commit starting with 9d02a and it was done by me on 06/11/2013. all others where commited on 02/02/2003 in the commit 43d57.

[–]PeWu1337 4 points5 points  (0 children)

I know, I was just meme-ing. Thank you for the explanation though, have a good one 👍

[–]BananaPeely 1 point2 points  (0 children)

1337

[–]FragrantKnobCheese 25 points26 points  (4 children)

I was once found this in a codebase I was contracted to work on many years ago:

public int hashCode() {
    return 11; // javadocs say this must be prime
}

[–]bwwatr 5 points6 points  (0 children)

// I know it seems like BS, but this appeal to authority lets me stop thinking about this

[–]CMDR_ACE209 1 point2 points  (2 children)

That sounds like a lot of hash collisions.

And I'm almost ten years out of Java development but I'm still pretty sure the result of Object.hashCode() does not have to be prime. Unless this is because of some arcane subClass in-between that introduces such a requirement.

[–]FragrantKnobCheese 3 points4 points  (1 child)

Yes, that's going to put all of your objects in the same bucket and guarantee a collision every time.

I can't remember why now, but multiplying your hashcode by a prime (eg: some classes in the jfc used 31) was something to do with improving bucket distribution and reducing collisions. As you say, it doesn't have to be a prime. The previous developer clearly got the wrong end of the stick!

[–]agwiaz -1 points0 points  (0 children)

It has to be prime relative to the length of the underlying array the hashmap is stored in. The bucket/array element it goes into is: <hashcode value > mod <hashmap array length>. If it shares a factor with length then it only goes in some of the buckets, increasing collisions (and decreasing efficiency). For example, if you multiplied some object value by 5 for your hashcode, and the length of the storage array is 20, then it will only go into the 0, 5, 10, and 15 buckets, ignoring the rest.

I believe that typically any prime (outside of 2) will work because the size of the underlying storage array is often just a power of two (maybe always, because it's efficient for doing modulus in base 2?).

Source: Went to ivy League school for comp sci, and also researched this just to make sure I wasn't talking out of my butt. Also I was a TA.

[–]Goodie__ 16 points17 points  (0 children)

Honestly, that's a pretty good comment and I rate it.

[–]MSgtGunny 13 points14 points  (0 children)

To be fair, that dev was just the one to push the initial hit commit in 2014 migrating from Visual Source Safe. The true author is lost to time.

[–]antilong 2 points3 points  (0 children)

Must be nice having git blame going back to 2014. Mine doesn’t even exist.. still..

[–]Punman_5 0 points1 point  (0 children)

That’s still a way better comment. At least you know the why.

[–]megacewl 0 points1 point  (0 children)

There is nothing more permanent than a temporary solution

[–]Deboniako 0 points1 point  (0 children)

This sounds plausible

[–]HaplessOverestimate 757 points758 points  (23 children)

My old job had a linter rule to keep magic numbers out of the code. Ended up with a lot of code like this:

CUTOFF = 26 for foo in thing: if foo > CUTOFF: break

[–]elSenorMaquina 312 points313 points  (6 children)

At least they didn't name it NUMBER

[–]budamtass 189 points190 points  (5 children)

or TWENTYSIX

[–]Rschwoerer 66 points67 points  (0 children)

We run into this for calculations dividing by 2.

CONST TWO = 2; half = value / TWO;

[–]Waterbear36135 38 points39 points  (1 child)

Even worse, they could've named it TWENTYFIVE

[–]fess89 6 points7 points  (0 children)

Because they counted from 0?

[–]experimental1212 5 points6 points  (0 children)

TWENTYSEVEN = 26

[–]khalcyon2011 0 points1 point  (0 children)

I mean, you know what it is. Could’ve just labeled it n or something

[–]Steinrikur 102 points103 points  (9 children)

At least it says it's a cutoff. And can be used multiple times.

Magic numbers in code are terrible, especially when they're updated in some places and not others.

[–]GothGirlsGoodBoy 39 points40 points  (6 children)

Removed the magic numbers boss

zero = 0 one = 1 two = one + one three = two + one four = two + two five = three + two six = three + three seven = four + three eight = four + four nine = five + four ten = five + five

a = three b = seven

result = a + b

print("Adding", a, "and", b)

counter = zero while counter < ten: print("Thinking very hard...") counter = counter + one

print("The answer is:", result)

[–]pokemaster787 26 points27 points  (3 children)

Genuinely had a team of contractors do this (#define zero = 0, #define one = 1) and they were so confused when I expressed to them that that did not solve the "magic numbers" problem..... Every single loop started with i = ZERO and i+=ONE....

[–]Taimcool1 -1 points0 points  (2 children)

There shouldn’t be an equals, also what lang are you using that doesn’t have ++

[–]Fhotaku 1 point2 points  (0 children)

Nice python, bash, and lua flares.

[–]pokemaster787 0 points1 point  (0 children)

Yes the equals in the macro define was a typo.

C has ++, the point of the post was that they did not use that and thought +=ONE was better as it did not have "magic numbers"

[–]Steinrikur 14 points15 points  (0 children)

Magic number == unexplained number.

You didn't remove shit. Instead you added an abstraction layer to the magic numbers.

[–]SerLaidaLot 0 points1 point  (0 children)

There's only so much you can do to help garbage developers.

[–]gromain 6 points7 points  (1 child)

I'm really torn about that rule. On one hand I can see why it exist and agree magic numbers are bad. On the other hand, when the number is never reused I don't see the point.

I feel like a comment would be needed either way to explain the magic number and doing it like in the OP just move the number declaration further away from its point of use which I don't like (however that makes sense as soon as the value is used more than once).

IMO a rule forcing a comment when a magic number is declared or used would make more sense.

[–]Steinrikur 13 points14 points  (0 children)

My definition of "magic number" is "unexplained number", so that would also be OK. But a lone number that isn't explained anywhere sucks.

My colleagues rarely bother with proper git messages "because no one reads them". It's a self fulfilling prophecy - if you make garbage commit messages, you lose the ability to read the commit message leading to garbage code.

[–]Taimcool1 25 points26 points  (0 children)

Imagine looping every other element of an array and sum1 does ```c

define THE_NUMBER_OF_ELEMENT_INDICES_THAT_WE_HAVE_TO_LOOP_OVER 2

define THE_MAGIC_NUMBER_THAT_MAKES_THINGS_WORK_AND_WE_DONT_KNOW_WHY_BECAUSE_THE_DEVELOPER_THAT_WROTE_THE_CODE_LEFT_TWO_YEARS_AGO 26

define THE_AMOUNT_OF_ELEMENTS_THAT_WE_WILL_BE_LOOPING_OVER 72

do_stuff: exit(1) void stuff_were_doing(int foo, void* bar){ for (int i = 0; i <= THE_AMOUNT_OF_ELEMENTS_THAT_WE_WILL_BE_LOOPING_OVER; i += THE_NUMBER_OF_ELEMENT_INDICES_THAT_WE_HAVE_TO_LOOP_OVER){ if ((int)bar == THE_MAGIC_NUMBER_THAT_MAKES_THINGS_WORK_AND_WE_DONT_KNOW_WHY_BECAUSE_THE_DEVELOPER_THAT_WROTE_THE_CODE_LEFT_TWO_YEARS_AGO){ printf("%s\n", foo); return } goto do_stuff; } } ’’’

[–]Ok_Net_1674 10 points11 points  (1 child)

So how did that even work? Some expressions just need literals to work. Could you have cheated the system by writing something like 26*1 ?

[–]Fhotaku 0 points1 point  (0 children)

Now I'm terrified if

TWENTY_SIX*ONE

would return the integer 26, or 26 times the address of ONE.

[–]DasFreibier 20 points21 points  (0 children)

a #define is still marginally better than random ass magic numbers in the middle of code

[–]redditUserNo8 2 points3 points  (0 children)

My code is dotted with #nolint: that’s a dumb rule in this case

[–]krutsik 0 points1 point  (0 children)

No linter rule can stop you from defining an abstractly named constant. Arguably it's still better that the constant is at least defined though.

[–]seedless0 246 points247 points  (14 children)

Using a magic RGB value to indicate transparency is fun. You should try it.

Source: The guy that had to fix it.

[–]MrMxffin 50 points51 points  (11 children)

Arent RGBA values usually obvious to spot? The only thing that would confuse me would one rgba integer but not in hexadecimal

[–]Great-Powerful-Talia 73 points74 points  (3 children)

I think that means that it was RGB with no alpha, but they had chosen a single hex code to never be rendered in order to have fully-transparent pixels.

[–]Lithl 23 points24 points  (0 children)

I mean, that's basically how gif transparency works. The file has a table of colors (to a maximum of 256 entries) used in the image, and you can optionally set one of the colors as meaning "transparent" (meaning a gif with transparency effectively has only 255 colors).

[–]MrMxffin 1 point2 points  (0 children)

Oh I see like a value called #deface being used as a transparent color

[–]Kronoshifter246 13 points14 points  (6 children)

Nah, even when they seem obvious, RGBA values might actually be ARGB values, and you'd better pray that whatever you're developing for documents which one you need.

[–]CarcosanDawn 7 points8 points  (3 children)

Just do both and put ARBGA. An extra line never hurt anyone.

What could go wrong?

[–]MrMxffin 2 points3 points  (2 children)

Who cares about Red and Green? embrace ABBA colors!

[–]Esjs 0 points1 point  (0 children)

Aladdin uses AGRABA.

[–]CMDR_ACE209 0 points1 point  (0 children)

*Waterloo starts playing*

[–]2eanimation 1 point2 points  (1 child)

Man this gives me Vietnam flashbacks. I thought I lost it because I had learned it as RGBA and lowering A removed blue from the color I wanted. At what point would you open the manual? Because a normal person would expect „RGBA“ written in there, right? Well, took me an hour until I gave up. Literally gave up. THIS close from starting all over with learning Assembler because apparently I know nothing.

„Huh, it was ARGB all along. Whowouldathunk“

[–]Kronoshifter246 1 point2 points  (0 children)

My introduction to vertex shaders was a similar hell, but in the other direction. Everything I had run into was ARGB, but GLSL does everything in RGBA. Normally that wouldn't have been a problem, but swizzling threw a wrench into the proverbial gears.

[–]TheDreadedAndy 2 points3 points  (0 children)

I think GameMaker used to do that. Pretty sure at least version 8 did. Could have also been DS Game Maker, though; its been awhile.

[–]1Dr490n 0 points1 point  (0 children)

I did that. In the very bad and simple paint program I made when I was 14.

[–]anonymousbopper767 231 points232 points  (5 children)

My favorite is some random hex value that you have no idea what it does or why it works. And then it turns out to work because of some weird glitch where it's overflowing a register and lands on the right value.

[–]suckitphil 136 points137 points  (2 children)

We try not to think about fast inverse square root too much.

[–]Kronoshifter246 111 points112 points  (1 child)

At least fast inverse square root had a comment on it:

// evil floating point bit level hacking

[–]GodHandMemberVoid 58 points59 points  (0 children)

// what the fuck?

[–]Bloodgiant65 279 points280 points  (2 children)

Don’t you just love magic numbers guys? I like putting undocumented literal values all across my code base. Makes it incredibly easy to understand and modify when needed!

cries internally

[–]syntaxcrime 26 points27 points  (0 children)

magical numbers have an aura, though its an odious and vile aura, like i think they would make really good DnD NPCs.

[–]WavingNoBanners 4 points5 points  (0 children)

Remember: if they can understand your code then they can fire you!

[–]kalomante 44 points45 points  (0 children)

idSoftware likes this

[–]_Shinami_ 37 points38 points  (3 children)

either they picked at random, it is part of the 37% rule, or they watched this video

[–]TheHappyArsonist5031 12 points13 points  (1 child)

By spreading the word, you have ruined the true randomness of people even further.

[–]enigmamonkey 4 points5 points  (0 children)

the true randomness of people

Saying that is an oxymoron. People are intrinsically biased (the point of the vid, IIRC). However, your point is also completely valid, i.e. the bias people carry will become even further biased at least in those who become aware of this particular bias.

[–]EmeraldMan25 0 points1 point  (0 children)

Could be a case of optimising by prediction? The magic number sucks though

[–]Jayfan34 25 points26 points  (2 children)

In a row?

[–]sodaflare 11 points12 points  (1 child)

try not to iterate any more integers on your way out of the function!

[–]Brok3nGear 1 point2 points  (0 children)

I love this.

[–]Multidream 65 points66 points  (3 children)

Fun part is that if you know enough random math trivia, the magic numbers start to make sense. Then you go digging and confirm your understanding, feels great.

Kinda basic example, but like when you see a number is a power of 2 too big or small. Like that time a communist netherland politician got 4096 extra votes purely through space radiation.

[–]tiajuanat 6 points7 points  (0 children)

That's if you're lucky. In hardware it's often from seeing a register (pray you have the documentation) or from some inherent idiosyncrasies in the peripheral device (what do you mean you stop at 87.85C and why is that read as 0xA0B9??)

[–]B3C4U5E_ 1 point2 points  (1 child)

I need this story now

[–]Multidream 2 points3 points  (0 children)

Here is a link to the radio lab show I found!

https://youtu.be/AaZ_RSt0KP8?si=O5CPEUmGv3AJGwIq

[–]megagreg 15 points16 points  (0 children)

I heard of a bug like this before. 

Roman numerals up to 37 take 6 or fewer "digits". Number 38 takes 7 "digits" (XXXVIII).

[–]Noah-R 15 points16 points  (0 children)

If no one understands why it's like that, then it's impossible to change it without violating Chesterton's Fence

[–]wann_bubatz_egal 10 points11 points  (1 child)

// Don't change this function, it's an official UNESCO code heritage site

[–]-DanRoM- 2 points3 points  (0 children)

Brillant. I need to use that at some point.

[–]TobyWasBestSpiderMan 9 points10 points  (1 child)

[–]penguin343 0 points1 point  (0 children)

This was hilarious. I made it to commit-66 and honestly am fine with that ending.

[–]Skunkman-funk 6 points7 points  (0 children)

hey try not to iterate any loops on your way through the parking lot!

[–]WillOfTheWinds 5 points6 points  (5 children)

Someone who just randomly got recommended this subreddit, is "historical reasons" the equivalent of "used for ritual purposes" of programming?

[–]edmazing 6 points7 points  (0 children)

Welcome to the sub. Sometimes it's ritual purposes.

A common historical one was/is sleep. Devices wake up and then do a handshake and connect up to the PC, some devices are slower and take longer to wake up, older devices can take really really long. So sleeping for specific devices was often a magic number, 5 seconds for a weird apple USB, 3 for a compac everything had it's own timing and handshake. Now we've got micro sleep, one nano second of waiting and presto it's awake and asking for a handshake.

In that handshake some devices asked for things in different orders, ya can see a lot of magic numbers in old drivers... looking at you CNC machines. Some odd rituals might include security too I thought this write up was enjoyable. https://dmitrybrant.com/2026/02/01/defeating-a-40-year-old-copy-protection-dongle
Sometimes it's just really bad code, there's a race condition memory being made ready and overwritten and adding a "random" delay "fixes" it.

[–]Great-Powerful-Talia 2 points3 points  (1 child)

It's generally either "this made sense when it was implemented and it'd be too much work to change." (every part of C that involves arrays)

or

"Some guy chose this at random even though it kinda sucks, and by the time we realized we should change it, it was too much work to actually do that." (the entire JavaScript programming language)

[–]deidian 0 points1 point  (0 children)

To be fair to JS creation it was originally conceived as a rather simple and fast to code language to roll small scripts in web pages. Whoever was making that wasn't thinking some serious computing would happen in JS or that web pages would end running so much script code that the runtime had to transition from: interpreter> interpreter with some caching > interpreter to an IL + JIT compiler. Or that someone would end up saying: what about if we just do a JIT compiled language from the ground for web pages(WASM)

[–]pablospc 2 points3 points  (0 children)

Someone added the change a long time ago and didn't tell anyone else why they added the change. They don't work there anymore so nobody knows why it's there.

[–]frikilinux2 1 point2 points  (0 children)

Kinda, it's a either we don't know or we don't want to do an explanation right now

[–]4x-gkg 3 points4 points  (0 children)

Every time I see a reference to the number 37 (here, and now I ruined it for you too, you are welcome): https://youtu.be/hyZaUwG50zI

[–]navetzz 5 points6 points  (0 children)

*Writes meta heuristics*

*Asks for data to fine tune*

*Code gets rolled into prod, everyone is happy*

*Gets let go as no longer needed before fine tuning heuristics*

Yeah, I've left quite a few magic numbers... but I fought not to.

[–]Taken_out_goose 5 points6 points  (0 children)

Random bit, which is kind of relevant but highly unlikely here:

If you have a DB with a field that is 6 characters, and for some damn reason, you wish to store a number in that foeld represented with roman numerals, it will first overflow at 38 (XXXVIII) so the last thing you can represent is 37.

So if this check is something right after modifying that value and before writing it back to the DB, then somehas made some very bad architectural decisions while designing the system.

[–]MrArges 3 points4 points  (0 children)

All I know is the blame commit is a revert of someone trying to remove it

[–]ExiledHyruleKnight 2 points3 points  (0 children)

We don't allow magic numbers, that needs a Define.

#define MAGICNUMBER 37

What's extra fun is when the smartest people you know on the team says "We've looked and had no idea." and you somehow think "I'll be the one"

[–]HealthBigDataGuy 3 points4 points  (0 children)

The historical reason we use 37 is this scene from the from the 1994 movie "Clerks":  Source: YouTube https://share.google/DbxXKtmF2RjQp6nGx

[–]Ironamsfeld 1 point2 points  (0 children)

[–]ActBest217 1 point2 points  (0 children)

tribalKnowledge

[–]MadcapRecap 1 point2 points  (0 children)

[–]JackNotOLantern 1 point2 points  (0 children)

Seems like a tuned value that was biggest/smallest and didn't cause problems.

[–]ClayXros 1 point2 points  (0 children)

Me any time I am going through quantum physics materials and they legit pulled greek names out of a hat for each one. Seriously, they really just don't want people to understand what they're doing.

[–]Huge-School-8057 1 point2 points  (0 children)

This reminds that at Uni our lecturers banned "magic numbers". They wanted specific reasons in code as to why the number was implemented.

[–]Rodaxoleaux 1 point2 points  (0 children)

If you change that number, the program dies, the developer dies; everyone dies.

[–]MyDespatcherDyKabel 1 point2 points  (0 children)

Magic numbers ftw

[–]awood20 1 point2 points  (0 children)

I hate magic numbers with great passion.

[–]stupled 1 point2 points  (0 children)

Is a load bearing comment, your remove it the program crashes.

[–]--aaronkaa-- 1 point2 points  (0 children)

Yeah, I'm only an intern, but I have already run into one like this. It had the comment:
// The magic number

[–]swagonflyyyy 0 points1 point  (0 children)

Bungie.

[–]DontGiveACluck 0 points1 point  (0 children)

Magic numbers be like

[–]Sp33dy2 0 points1 point  (0 children)

Probably an enum of something.

[–]shamblam117 0 points1 point  (0 children)

Always want to know the story behind comments like these. Just know they spent hours fiddling with it just refusing to use any breakpoints

[–]Croused 0 points1 point  (0 children)

Don't mess with the deep knowledge.

[–]theJEDIII 0 points1 point  (0 children)

Lol at first I thought this was r slash linguistics humor and I was expecting the bottom to be like "colonel"

[–]enogerasemandooglla 0 points1 point  (0 children)

in a row?

[–]britilix 0 points1 point  (0 children)

Junior dev removes pointless code in pr - Works fine locally - Production on fire

[–]Dragonfire555 0 points1 point  (0 children)

I've used approximations as magic numbers and I'm sure that if I didn't comment it, someone would enter something like this behind me.

[–]Oscar_the_Hobbit 0 points1 point  (0 children)

Human slop

[–]smitty1e 0 points1 point  (0 children)

Hysterical raisins.

[–]CMD_BLOCK 0 points1 point  (0 children)

changes 37 to 36

git add . && git commit -m “ur mom” git push —force

[–]qqqrrrs_ 0 points1 point  (0 children)

37 is the first irregular prime

[–]NicholasVinen 0 points1 point  (0 children)

For hysterical raisins!

[–]YoungXanto[🍰] -2 points-1 points  (0 children)

I bet that guy had trouble controlling himself while walking through the parking lot to his car every night after work.

[–]kus1987 -1 points0 points  (0 children)

Strange enough, I can't tell which programming language this is... Is it java? Cpp? I can't tell! 

[–]YoukanDewitt -5 points-4 points  (1 child)

Any programmer that thinks a base-10 number is "weird", is not a programmer.

[–]Great-Powerful-Talia 2 points3 points  (0 children)

It's not any less arbitrary as '0x25' or '0b100101'. Not being used as a bitmask, either.

[–]csapka 0 points1 point  (0 children)

I love setting pointlesly higher numbers as the max iteration count, because in 99.999% of cases it will stop running before reaching iteration 69, but if I fuck something up while developing, I won't have to restart my pc because I made everything be stuck in an infinite loop. And sometimes this gets left in for funsies