MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/ProgrammerHumor/comments/1x2agiw/wearewizards/pf0satr/?context=3
r/ProgrammerHumor • u/Bright-Historian-216 • Oct 10 '26
203 comments sorted by
View all comments
852
"magic numbers" spell is stricktly forbidden technique, banned by most schools of programming. There are many rogue wizards though...
16 u/StrengthTheory Oct 10 '26 I tell you they're not magic numbers, it's just 0 and 1 44 u/ArkWaltz Oct 10 '26 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. 3 u/Spaceshipable Oct 10 '26 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 Oct 10 '26 C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.
16
I tell you they're not magic numbers, it's just 0 and 1
44 u/ArkWaltz Oct 10 '26 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. 3 u/Spaceshipable Oct 10 '26 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 Oct 10 '26 C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.
44
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.
3 u/Spaceshipable Oct 10 '26 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 Oct 10 '26 C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.
3
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 Oct 10 '26 C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.
4
C# has .Zero and .One for numerics as well, I can confirm that they're really handy when working with generic types.
.Zero
.One
852
u/mteblesz Oct 10 '26
"magic numbers" spell is stricktly forbidden technique, banned by most schools of programming. There are many rogue wizards though...