Live data from Hacker News

`three = 1` in the linux sourcecode

github.com

21–30 of 83 posts

Re: `three = 1` in the linux sourcecode

#21

https://github.com/torvalds/linux/blob/d158fc7f36a25e19791d2... Variables `three`, `five` and `seven` are better described as `next_power_of_three`, `next_power_of_five` and `next_power_of_seven`. Since the `ext4_list_backups` function should iterate through 1 (= 3^0 = 5^0 = 7^0), 3, 5, 7, 3^2, 5^2, 3^3, 7^2, ... and 1 should not repeat three times, the initial value of `next_power_of_three` (or any of others) should…

A perfect example of a missing code-comment.

More like a terribly named variable.

Re: `three = 1` in the linux sourcecode

#23

> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton

I've always thought that the "naming things" refers to the more subtle problem of giving things unique identifiers in distributed systems, rather than coming up with variable names. "Naming things" includes systems like MAC address allocation, IP address allocation, DNS, URLs for documents, process IDs, name to inode mapping in filesystems, autoincrement primary keys in databases, etc. Any ideas on what Karlton reall…

Let me overthink this a little bit:

It seems to me that this quote makes a rather standard usage of the "Zeugma" [1] figure of speech. It consists in putting next to each other two things of very different nature. In that case we have the very technical problem of invalidating caches on the one hand, and the much higher level problem of naming things on the other hand.

That produces a rather stylish quote.

But if Phil Karlton was actually referring to the technical problem of assigning unique identifier as you suggest, the figure of speech is lost and the quote becomes less stylish.

So I prefer tho read "naming things" as the very general problem of naming things.

[1] http://en.wikipedia.org/wiki/Zeugma

Re: `three = 1` in the linux sourcecode

#24

> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton

I've always thought that the "naming things" refers to the more subtle problem of giving things unique identifiers in distributed systems, rather than coming up with variable names. "Naming things" includes systems like MAC address allocation, IP address allocation, DNS, URLs for documents, process IDs, name to inode mapping in filesystems, autoincrement primary keys in databases, etc. Any ideas on what Karlton reall…

I always assumed it was the more general "coming up with names" - for variables, hostnames, project names etc.

The non-human-readable things like MACs, IPs and auto-increment keys are easy. But when I have to come up with a short, memorable and non-confusing name for something like a script that can take me longer than writing the code.

Re: `three = 1` in the linux sourcecode

#25
post #3

Read the comment above ext4_list_backups right above: https://github.com/torvalds/linux/blob/d158fc7f36a25e19791d2... /* * Iterate through the groups which hold BACKUP superblock/GDT copies in an * ext4 filesystem. The counters should be initialized to 1, 5, and 7 before * calling this for the first time. In a sparse filesystem it will be the * sequence of powers of 3, 5, and 7: 1, 3, 5, 7, 9, 25, 27, 49, 81, ... * F…

If I'm not mistaken, the first number (1) is not considered a power of three, hence the initial (seemingly strange) three=1.

See http://www.nongnu.org/ext2-doc/ext2.pdf#page15 for a slightly more detailed explanation.

"The first version of ext2 (revision 0) stores a copy at the start of every block group, along with backups of the group descriptor block(s). Because this can consume a considerable amount of space for large filesystems, later revisions can optionally reduce the number of backup copies by only putting backups in specific groups (this is the sparse superblock feature). The groups chosen are 0, 1 and powers of 3, 5 and 7."

(Edit: Yes, I know that 3^0=1, but the wording "0, 1 and powers of 3, 5" does not imply 3^0. Thanks!)

Re: `three = 1` in the linux sourcecode

#27

Earlier quoted context omitted.

A perfect example of a missing code-comment.

More like a terribly named variable.

Agreed, comments are generally a way to compensate failure to express ourselves in the code (in this case bad naming).

Re: `three = 1` in the linux sourcecode

#29

Wasn't there a similar thread a few months back about "two" being corrected to equal 2?

Speaking of...

  kernel/sysctl.c

  #ifdef CONFIG_LOCKUP_DETECTOR
  static int sixty = 60;
  #endif
  
  static int __maybe_unused neg_one = -1;
  
  static int zero;
  static int __maybe_unused one = 1;
  static int __maybe_unused two = 2;
  static int __maybe_unused three = 3;
  static unsigned long one_ul = 1;
  static int one_hundred = 100;
  #ifdef CONFIG_PRINTK
  static int ten_thousand = 10000;
  #endif
Post reply on HN