News for hackers. Stuff that matters.
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by jen20 on Monday September 20, 2021 @09:29PM (#28601114)
A useful time for a quote from the Linux Kernel coding standards [1] - exactly the first item in fact:

"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: The whole idea behind indentation is to clearly define where a block of control starts and ends. Especially when you’ve been looking at your screen for 20 straight hours, you’ll find it a lot easier to see how the indentation works if you have large indentations.

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.

In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep. Heed that warning."

[1]: https://www.kernel.org/doc/html/v4.10/process/coding-style.h...

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by sk0g on Monday September 20, 2021 @09:39PM (#28601176)
That's all well and good for Linux-style C programming maybe, but it would be painful in languages like C#.

EG the simplest function in a Unity game, that prints "hello world" for the player only would be something like:

  namespace Something 
  {
          class SomeClass 
          {
                  void Awake()
                  {
                          if (CompareTag("Player"))
                          {
                                  print("Hello, world")
                                  print("This line's closing bracket is at # 80")
                          }
                  }
          }
  }
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by catmanjan on Monday September 20, 2021 @10:03PM (#28601297)
The new C# 6 templates don't require namespace or class blocks - for this reason I suppose.
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by fingerlocks on Monday September 20, 2021 @10:11PM (#28601350)
Pretty much every language with a class that contains a function with a loop that breaks on an inner condition would be 4 levels deep. I suppose Objective-C would only be 3 deep, but I can't think of any others off the top of head.
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by kragen on Monday September 20, 2021 @11:01PM (#28601665)
2 levels in Smalltalk, unless I'm missing something?

    !SomeClass methodsFor: ''something'' stamp: ''kks 6/30/2018 16:11''!
    find: key
            1 to: self items length do: [:i |
                    (key = self keys at: i) ifTrue: [^i]
            ]
    ! !
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by Cyph0n on Monday September 20, 2021 @10:55PM (#28601619)
C++, if the method is implemented outside of its header file.
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by sk0g on Monday September 20, 2021 @10:11PM (#28601348)
I do like having the namespace there, if only to gently nudge you towards better architecture.

As a temp fix I have overridden Rider's code formatting to not indent within the namespace, but C# 10 will bring file scoped namespaces. You can just declare the namespace between the imports and the classes, and everything in the file will be namespaced automatically.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by SmooL on Monday September 20, 2021 @10:32PM (#28601461)
I've heard this "no more than 3 levels of indentation" thing before, but isn't that somewhat language specific? If in coding in python, I have 1 level for being inside a class, 1 level for being inside a function, and that gives me only 1 level to write actual program flow with. I find it hard to believe that a double nested for loop, having 4 levels of indentation, is in-itself a sign that I have to "fix my program".
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by asciimov on Monday September 20, 2021 @11:17PM (#28601755)
The 3 levels of indentation, is about being mindful of runtime complexity. For example, do you really need four or more levels of for loops in a function.

This "rule" is very domain specific.

If you are writing for the Linux Kernel. You should rethink your strategy if you need something that is very nested.

However there are places that where such nesting might be the favorable way to do a task so that the code maintains long term readability. Most often this is for something that runtime complexity isn't a important factor. I've seen this most often in document and report generation.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by smnrchrds on Monday September 20, 2021 @10:52PM (#28601600)
List comprehensions in Python allow you to avoid having to add another level of indentation. If the feature did not exist, a lot of Python code would be one more level deep. Language features definitely have an effect on the number of indentation levels you need. Map and reduce reduce the number, Node-style callbacks increase it, etc.

Although I suppose a Linux kernel developer would consider having to write Node JS code as 'being screwed'.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by 0xdeadb00f on Monday September 20, 2021 @10:52PM (#28601601)
Personally I agree with the sentiment of no more than three indentations, but I don't take it as a hard rule (mostly because I'm not writing kernel code).

I think it is very language specific. In Python I'd probably ignore the "rule" outright.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by omegalulw on Tuesday September 21, 2021 @02:56AM (#28602631)
4 character indents are already too big. 8 character indented code is vomit inducing. 2 character indents and any modern monospace font is enough for readability.

I concede that reading 2 indented is hard when you begin braces on a new line - but then your problem is beginning braces on a new line, not the indent.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by FiggyPudding on Tuesday September 21, 2021 @09:28AM (#28604819)
I'm one of the monsters that prefers 2 space tabs for my small monitor, 2 files side by side.

Like you said and other comments, no newline opening braces, don't mix tab and space for OCD trailing comment and argument alignment.

On the other hand, I don't code for 20 hours straight because I need to do laundry and dishes and family stuff.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by hyperjeff on Tuesday September 21, 2021 @01:25AM (#28602282)
This presumes one isn't using real tab characters in their code. (No idea why they claim tabs are 8 spaces, as they're their own character.) The rest of these arguments are just curious decisions by a certain community. The point is for the visual indentation to be up to the end user, seasoned to taste. Requiring some code viewer to stick to n spaces is unfriendly. (I'd sooner quit programming altogether than follow the above rules.)
Re:What's the deal with tab size (8 spaces) in the GitHub UI? by rurban on Tuesday September 21, 2021 @12:21PM (#28606629)
That's certainly true for spaghetti kernel or firmware code, but certainly not true for application code, with a much higher abstraction.

8 char indentation also doesn't make your code easier to read, on the contrary. Your eyes need to move much further.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by Waterluvian on Monday September 20, 2021 @10:52PM (#28601602)
I have a hard time believing these opinions are correct because they were heavily constrained based on column size and monitors of the old days.

So it’s not like the community freely came to this conclusion after a lot of informed experimentation.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by kazinator on Tuesday September 21, 2021 @01:21AM (#28602262)
Just because you have an ultra-wide, 8K monitor in 2021 doesn't mean it's a good idea to write 400 character lines. This argument is specious.

In fact 80 columns is as much related to readability as it is to hardware limitations of yore.

100-something columns for code can be a pretty big relaxation over 80, but beyond that it gets into diminishing returns.

Re:What's the deal with tab size (8 spaces) in the GitHub UI? by Waterluvian on Tuesday September 21, 2021 @11:34AM (#28606080)
I generally agree. I once played with 130 and found that to be crazy. Settled on 100 (when it's my own project).

My point is that it's not like they came up with these opinions based on a sandbox of experimentation. The opinions on line length, indentation, etc. are all results of constraints at the time. Which makes the opinions on things like "80 chars, 8 char tabs" feel like retcons.