Questions tagged [indentation]
27 questions
239
votes
14 answers
How can a code editor effectively hint at code nesting level - without using indentation?
I've written an XML text editor that provides 2 view options for the same XML text, one indented (virtually), the other left-justified. The motivation for the left-justified view is to help users 'see' the whitespace characters they're using for…

pgfearo
- 944
- 4
- 11
- 19
85
votes
12 answers
What are the drawbacks of elastic tabstops?
Look here: a typical holy war on tabs vs spaces.
Now look here: elastic tabstops. All problems solved, and a bunch of very useful new behaviours added.
Are elastic tabstops even mentioned in that tabs vs spaces discussion? Why not? Are there…

Roman Starkov
- 4,469
- 3
- 31
- 38
84
votes
22 answers
Tabs versus spaces—what is the proper indentation character for everything, in every situation, ever?
The coding standards for the code hosted in drupal.org suggest to use two spaces to indent the code; other sites suggest to use tabs to indent the code.
What is the proper indentation character for everything, and in every situation? Please explain…

apaderno
- 4,014
- 8
- 42
- 53
57
votes
3 answers
What is the difference between K&R and One True Brace Style (1TBS) styles?
I have read the Wikipedia article on Indent Styles, but I still don't understand. What is the difference between K&R and 1TBS?

GavinR
- 673
- 1
- 5
- 7
31
votes
3 answers
Origins of code indentation
I am interested in finding out who introduced code indentation, as well as when and where it was introduced.
It seems so critical to code comprehension, but it was not universal. Most Fortran and Basic code was (is?) unindented, and the same goes…

Daniel Mahler
- 581
- 3
- 7
25
votes
6 answers
Reformatting and version control
Code formatting matters. Even indentation matters. And consistency is more important than minor improvements. But projects usually don't have a clear, complete, verifiable and enforced style guide from day 1, and major improvements may arrive any…

l0b0
- 11,014
- 2
- 43
- 47
23
votes
8 answers
At what point is it taboo to have loops within loops?
Just curious. The most I have ever had was a for loop within a for loop, because after reading this from Linus Torvalds:
Tabs are 8 characters, and thus indentations are also 8 characters.
There are heretic movements that try to make indentations…

Anon
- 3,565
- 3
- 27
- 45
22
votes
5 answers
What are the downsides of mixing tabs and spaces?
The advantage of using tabs for indentation is that people can configure their editor to use the tab width they are comfortable with. The only argument against this seems to be that people don't want their code to look differently based on editor…

Overv
- 1,170
- 1
- 9
- 15
17
votes
9 answers
How to prevent deep indentations?
What steps and measures can I take to prevent deep indentations in my code?

Tamara Wijsman
- 8,259
- 14
- 58
- 94
15
votes
5 answers
Keep indentation level low
I hear a lot that you should not write functions larger than one screen size, that you should extract things into functions if you call things very often and all these coding guidelines. One of them is also keep your indentation level low. Some…

reox
- 283
- 2
- 6
15
votes
7 answers
Should I write compact code or code with lots of spaces?
I have two friends that have completely different schools of thought on how to lay out their code.
The first says that code should be well-indented and use lots of spaces and to name variables judiciously in order to organize things in a way so…

Peter Olson
- 1,042
- 1
- 12
- 20
13
votes
8 answers
Styling compound AND / OR if statements
How do you style complex compound AND / OR if statements for maximum readability? How do you indent and where do you place the line breaks? My particular situation is something like the following. It's definitely better than smashing everything into…

JoJo
- 1,475
- 2
- 14
- 21
13
votes
5 answers
Why do some languages recommend using spaces rather than tabs?
Maybe I'm alone in this, but few things annoy me like people indenting using spaces rather than tabs. How is typing SpaceSpaceSpaceSpace easier and more intuitive than typing Tab? Sure, tab width is variable, but it's much more indicative of…

Naftuli Kay
- 1,601
- 2
- 16
- 23
9
votes
4 answers
How strict should you be about indentation/white space?
Our development process is as follows
code the task -> someone else QAs code and documentation -> task is merged into trunk.
Recently a colleague is refusing to pass the code QA due to issues with indentation and whitespace.
Here are examples of…

dwjohnston
- 2,543
- 6
- 29
- 49
8
votes
3 answers
Indentation in a multi-language file
In files that contain multiple languages (ie. template files), are there any best practises regarding indentation?
I mostly use this:
IF FOO
END FOO
Indent for every new…contents>

Celos
- 267
- 1
- 5