Question

Using a tab width of 4 spaces has emerged as the primary choice in programming. So why doesn't Python see a tab as 4 spaces instead of 8?

Is there a (technical, historic, other) reason for this design decision? It feels like that could have saved developers from struggling with inconsistent indentation a lot.

Was it helpful?

Solution

Because the default tab size in Linux console is 8 spaces, and therefore most CLI text editors in Linux also default to 8 spaces. Most are also configurable, but it's been the default for ages.

Some older (C) code uses mixed indention to fake a 4 space tab - 1 indent == 4 spaces, 2 indents == 1 tab, 3 indents == 1 tab + 4 spaces, etc..... it was awful. Not sure if it was done intentionally in order to make the code easier to read, or if some editor did this automatically to simulate 4 space tabs. All I know is that I was using pico and it was a PITA working with those, especially when you needed to indent/dedent a whole block. :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top