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")
}
}
}
} !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]
]
! !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.
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.
Although I suppose a Linux kernel developer would consider having to write Node JS code as 'being screwed'.
I think it is very language specific. In Python I'd probably ignore the "rule" outright.
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.
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.
8 char indentation also doesn't make your code easier to read, on the contrary. Your eyes need to move much further.
So it’s not like the community freely came to this conclusion after a lot of informed experimentation.
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.
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.
"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...