Hacker News new | ask | show | jobs
by huhtenberg 2024 days ago
Compare this -

  * Just a few spaces per indent level *

  To make this work, and yet allow a few indent 
  levels, the code basically have to have small 
  indent-levels, so I prefer to have it set to 
  two spaces per level.
To this, courtesy of the "Linux kernel coding style" [1] -

  1) Indentation

  Tabs are 8 characters, and thus indentations 
  are also 8 characters. There are heretic 
  movements that try to make indentations 4 (or 
  even 2!) characters deep, and that is akin to 
  trying to define the value of PI to be 3.

  Rationale: [snip]

  Now, some people will claim that having 8-
  character indentations makes the code move 
  too far to the right, and makes it hard to 
  read on a 80-character terminal screen.

  The answer to that is that if you need more 
  than 3 levels of indentation, you’re screwed 
  anyway, and should fix your program.
Having used 8-char tabs for a very long time, I now find looking at smaller tab'ed code a somewhat unpleasant experience. It feels like the code lacks enunciation. As if it mumbles.

[1] https://github.com/torvalds/linux/blob/master/Documentation/...

3 comments

The linux version is overly emotional/rage-y and strongly overstates its cause.

The first version is calm and honest, does not pretend preference is actually somehow objective universal statement.

The latter came from Linus, so yeah it's, erm, opinionated (and what you read as "rage-y" is actually humorous).

His point still stands though - if you ever need one too many indent levels, the code could almost certainly use simplification.

In no way it is like "trying to define the value of PI to be 3". That is just nonsense.

> The answer to that is that if you need more than 3 levels of indentation, you’re screwed anyway, and should fix your program.

Maybe in context of old C, but in java you have two nestings just for being in class method. So as a general point, it does not stand anyway.

And screens are bigger than they used to be, so you conveniently have more tabs to make up for it. I think it evens out
How does bigger screen imply that three levels of nesting are bad programming? It just does not.
> Maybe in context of old C, but in java you have two nestings just for being in class method. So as a general point, it does not stand anyway.

In reference to your above point. You’re saying modern Java makes you start out at 2 levels of indentation. I’m saying your modern monitor’s width compensates.

>overly emotional/rage-y

Really? I can't read it as anything but tongue-in-cheek.

I default to the idea everything is potentially-insincere, especially online. Do you not?

No I do not.

Plus, I don't see a reason to attempt to mind read. If you write something angry for fun, the result is angry text. It is ok to interpret it as such.

Ok asked us to contrast two arguments. That is what I did.

Being able to understand context and intent in written language isn't mind reading. Its just normal reading.
Fixing the width of a tab is akin to trying to define the value of x to be 3.
I have no idea what you mean.

  set tabsize 4
Sure, you can set it to 4 and a properly formatted code will just adjust. That's granted, but irrelevant. The question is in usability of different tab sizes.
This comment on a mobile/small screen looks horribly wrong.

Exactly like 80-width code on a similar small editor.