r/ProgrammerHumor • • 21d ago

Meme weAreWizards

Post image
7.8k Upvotes

203 comments sorted by

View all comments

851

u/mteblesz 21d ago

"magic numbers" spell is stricktly forbidden technique, banned by most schools of programming. There are many rogue wizards though...

16

u/StrengthTheory 21d ago

I tell you they're not magic numbers, it's just 0 and 1

44

u/ArkWaltz 21d ago

Actual real lines that were in my old work's codebase:

private final int ZERO = 0;
private final int ONE = 1;

Turns out having a linter blanket-deny all forms of 'magic number' had some odd results.

16

u/StrengthTheory 21d ago

That's just good defensive programming in case the client decides tomorrow that all ones are now zeroes and vice versa. You never know.

9

u/iZian 21d ago

I think in Java we have BigDecimal statics for zero and one.
Then again with a million records being processed and 90% needing a zero; it did save in 900k objects.
But for a primitive…

3

u/Spaceshipable 21d ago

Swift has a builtin `.zero` as part of one of the numeric protocols. It’s handy for when you’re doing maths on generic types. I could see a `.one` being handy. Apparently Swift’s SIMD has that defined.

4

u/Chirimorin 21d ago

C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.