Live data from Hacker News

`three = 1` in the Linux sourcecode (2014)

github.com

51–60 of 105 posts

Re: `three = 1` in the Linux sourcecode (2014)

#51

Earlier quoted context omitted.

Why is the reason for doing this obvious? I can't see any benefit. I get why you would prefer to name constants for their use, like `numIterations=3` or whatever, but renaming every integer seems senseless.

> but renaming every integer seems senseless. When the integer itself is self-explainatory but you can't just assign the integer as a name. For example: constexpr int 42 = 42; // compiler error So instead: constexpr int fourtytwo = 42; // yay! However the obviousness of what 42 means is debatable. int universe = fourtytwo; // why? int sum = fourtytwo; // sum... of what? int magic = fourtytwo / 7;

"What do you get if you multiply six by nine?" = 42

Re: `three = 1` in the Linux sourcecode (2014)

#52
Magic numbers are a horrible pattern (and I don't mean elf/obj IDs).

*ANY* time you use a non-obvious constant (like start of a loop that isn't 0), good practice to comment immediately at the source, or pull it into a well-named variable/macro.

Don't agree? Spend 35 years programming and you'll see this pop up again and again and again and again... SO much time wasted figuring out magic #s.

Re: `three = 1` in the Linux sourcecode (2014)

#54
It was done that way on purpose to cause hundreds of people a year to freak out and discuss it ad nauseum. But really a social experiment designed to show everyone is all talk and no follow through... That being that no one actually tried to change open source but just talk about it.

Re: `three = 1` in the Linux sourcecode (2014)

#55

Many years ago in an age of klocs and flowcharts, at a large three-letter computer company, there were iron-clad coding rules that must be obeyed, no questions allowed. In general you could see their reasoning, but such bureaucratic reasoning doesn't pay off. One example of this was that all numeric values used in a program must be factored out as symbolic constants. The reason for doing this is obvious, but it faile…

I would do this:

    #define I     1
    #define II    2
    #define III   3
    ...
    #define XIII 13
There is no zero in roman numerals, but you can use NULL for extra fun! (yes, I am a bad person)

Re: `three = 1` in the Linux sourcecode (2014)

#57

Many years ago in an age of klocs and flowcharts, at a large three-letter computer company, there were iron-clad coding rules that must be obeyed, no questions allowed. In general you could see their reasoning, but such bureaucratic reasoning doesn't pay off. One example of this was that all numeric values used in a program must be factored out as symbolic constants. The reason for doing this is obvious, but it faile…

Why is the reason for doing this obvious? I can't see any benefit. I get why you would prefer to name constants for their use, like `numIterations=3` or whatever, but renaming every integer seems senseless.

The use case I'm familiar with is when the fn you're calling requires a pointer. Common for ioctl(..., &one) calls.

If you look later in the code that's exactly what is happening here.

Re: `three = 1` in the Linux sourcecode (2014)

#58

It was done that way on purpose to cause hundreds of people a year to freak out and discuss it ad nauseum. But really a social experiment designed to show everyone is all talk and no follow through... That being that no one actually tried to change open source but just talk about it.

that's interesting, is there a source?

Re: `three = 1` in the Linux sourcecode (2014)

#59
post #55

Many years ago in an age of klocs and flowcharts, at a large three-letter computer company, there were iron-clad coding rules that must be obeyed, no questions allowed. In general you could see their reasoning, but such bureaucratic reasoning doesn't pay off. One example of this was that all numeric values used in a program must be factored out as symbolic constants. The reason for doing this is obvious, but it faile…

I would do this: #define I 1 #define II 2 #define III 3 ... #define XIII 13 There is no zero in roman numerals, but you can use NULL for extra fun! (yes, I am a bad person)

Using NULL for the integer 0 requires a cast in C (because NULL may have a pointer type). That doesn't break the GP's rule, however neither does `!I` or `I-I`.

Re: `three = 1` in the Linux sourcecode (2014)

#60
post #55

Many years ago in an age of klocs and flowcharts, at a large three-letter computer company, there were iron-clad coding rules that must be obeyed, no questions allowed. In general you could see their reasoning, but such bureaucratic reasoning doesn't pay off. One example of this was that all numeric values used in a program must be factored out as symbolic constants. The reason for doing this is obvious, but it faile…

I would do this: #define I 1 #define II 2 #define III 3 ... #define XIII 13 There is no zero in roman numerals, but you can use NULL for extra fun! (yes, I am a bad person)

For extra fun, put it into the code like this, including the `...` instead of the actual values. (Make it compile by commenting that line out.) Then define IV somewhere else but make sure to use III before every use IV so someone unfamiliar with these constants see the “right” definitions first.
Post reply on HN