> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton
`three = 1` in the linux sourcecode
11–20 of 83 posts
Re: `three = 1` in the linux sourcecode
#12> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton
Re: `three = 1` in the linux sourcecode
#13> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton
there are two hard things in computer science: cache invalidation, naming things, and off-by-one errors
Re: `three = 1` in the linux sourcecode
#14Re: `three = 1` in the linux sourcecode
#15Re: `three = 1` in the linux sourcecode
#16That deserves an explanation in the code comments...
Re: `three = 1` in the linux sourcecode
#17Read 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…
See this comment: https://news.ycombinator.com/item?id=7296586 Good commenting is no substitute for good naming. For a variable containing the number 1, "three" is a shitty name.
The function being called is directly above this declaration. It's a static function not used outside of this file. What are the chances that someone would edit this code without understanding what "three" is used for in this context? Pretty slim I wager.
It's good that people are auditing the linux source code but if you stumble upon some weird looking code (which again, is not the case here in my opinion) the right way to deal with it is not to post it on hacker news. Contact the maintainer (look at the MAINTAINER file at the root of the kernel) if possible with a patch to fix the issue.
Re: `three = 1` in the linux sourcecode
#18https://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…
Re: `three = 1` in the linux sourcecode
#19> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton
"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 really meant with the quote?
Re: `three = 1` in the linux sourcecode
#20> There are only two hard things in Computer Science: cache invalidation and naming things. > -- Phil Karlton
there are two hard things in computer science: cache invalidation, naming things, and off-by-one errors