Indentation style

(Redirected fromIndent style)

Incomputer programming,indentation styleis aconvention,a.k.a.style,governing theindentationofblocksofsource code.An indentation style generally involves consistent width ofwhitespace(indentation size) before each line of a block, so that the lines of code appear to be related, and dictates whether to usespaceortabcharacters for the indentation whitespace.

Overview

edit

This article primarily addresses styles forfree-formprogramming languages.As the name implies, such language code need not follow an indentation style. Indentation is asecondary notationthat is often intended to lowercognitive loadfor a programmer to understand the structure of the code. Indentation can clarify the separation between the code executed based oncontrol flow.

Structured languages, such asPythonandoccam,use indentation to determine the structure instead of using braces or keywords; this is termed theoff-side rule.In such languages, indentation is meaningful to the language processor (such ascompilerorinterpreter). A programmer must conform to the language's indentation rules although may be free to choose indentation size.

This article focuses oncurly-bracket languages(that delimit blocks withcurly brackets, a.k.a. curly braces, a.k.a. braces) and in particular C-family languages,but a convention used for one language can be adapted to another language. For example, a language that usesBEGINandENDkeywords instead of braces can be adapted by treatingBEGINthe same as the open brace and so on.

Indentation style only applies to text-based languages.Visual programming languageshave no indentation.

Research

edit

Despite the ubiquitous use of indentation styles, little research has been conducted on its value. First experiments, conducted by Weissman in 1974, did not show any effect.[1] In 2023, an experiment by Morzeck et al.[2]showed a significant positive effect for nestedifstatements where non-indented code required on average 179% more time to read than indented code. A follow up-experiment by Hanenberg et al.[3]confirmed a large effect (although in that experiment non-indented code just took 113% more time to read) and revealed that the differences in reading times can be explained by the code that can be skipped (for indented code). In another experiment on JSON objects[4]non-indented code took even 544% more time to read.

Notable styles

edit

The table below includes code examples of various indentation styles. For consistency, indentation size for example code is 4 spaces even though this varies by coding convention.

Example Name
while(x==y)
{
foo();
bar();
}
Allman
while(x==y)
{
foo();
bar();
}
GNU
while(x==y)
{
foo();
bar();
}
Whitesmiths
while(x==y){
foo();
bar();
}
K&R
while(x==y){
foo();
bar();
}
Ratliff
while(x==y)
{foo();
bar();
}
Horstmann
while(x==y)
{foo();
bar();}
Pico
while(x==y)
{foo();
bar();}
Lisp
#define W(c,b) {while(c){b}}
W(x==y,f();b();)
APL

C/C++ styles

edit

Attributes ofC,C++and othercurly-brace programming languagecoding style include but are not limited to:

  • Placement ofbracesrelative to other code elements
  • Use oftabsorspaces
  • Wrapping single-statement blocks in braces. Advocates cite the advantage that resulting code is safer since inserting a statement cannot result in control flow that disagrees with indentation. A cited disadvantage is that the code is longer since one line is needed for the closing brace of a block (except for theelse ifconstruct and ado{}whileblock).

The Kernighan & Ritchie (K&R) style is commonly used for C and C++ code and is the basis for many derivative styles. It is used in the original Unix kernel,KernighanandRitchie'sbookThe C Programming Language,as well as Kernighan andPlauger's bookThe Elements of Programming Style.

AlthoughThe C Programming Languagedoes not explicitly define this style, it follows it consistently. From the book:

The position of braces is less important, although people hold passionate beliefs. We have chosen one of several popular styles. Pick a style that suits you, then use it consistently.

In this style, a function has its opening and closing braces on their own lines and with the same indentation as the declaration, while the statements in the body of the function are indented an additional level. A multi-statement block inside a function, however, has its opening brace on the same line as its control clause while the closing brace remains on its own line unless followed by a keyword such aselseorwhile.

Example code:

intmain(intargc,char*argv[])
{
while(x==y){
do_something();
do_something_else();
if(some_error)
fix_issue();// single-statement block without braces
else
continue_as_usual();
}
final_thing();
}

Egyptian braces

edit

The non-alignedbraces of the multi-line blocks are nicknamed "Egyptian braces" (or "Egyptian brackets" ) for their resemblance to arms in some fanciful poses of ancient Egyptians.[5][6][7]

Single statements

edit

A single-statement block does not have braces, which is a cause of easy-to-miss bugs such as thegoto fail bug.

One True Brace

edit

TheOne True Brace Style[8](abbreviated 1TBS or OTBS[9]) is like the K&R style, but functions are formatted like multi-statement blocks with the opening brace on the same line as the declaration, and braces arenotomitted for a single-statement block.[10]

boolis_negative(intx){
if(x<0){
returntrue;
}else{
returnfalse;
}
}

Although not required by languages such as C/C++, using braces for single-statement blocks ensures that inserting a statement does not result in control flow that disagrees with indenting, as seen for example in Apple's infamousgoto fail bug.

Cited advantages include shorter code (than K&R) since the starting brace needs no extra line, that the ending brace lines up with the statement it conceptually belongs to, and the perceived stylistic consistency of using the same brace style in both function bodies and multi-line statement blocks.[11]

Sources disagree as to the meaning of One True Brace Style. Some say that it is the variation specified here,[10]while others say it is "hacker jargon" for K&R.[12]

Linux kernel

edit

TheLinux kernelsource tree is styled in a variant of K&R.[13]Linus Torvaldsadvises contributors to follow it. Attributes include:

  • Usestab charactersfor indentation (not spaces) and assumestab stopsevery 8 spaces
  • Brace layout matches K&R, with the braces of function definitions on their own lines and the opening brace of compound statements on the same line as the control clause, separated by a space
  • Labels in aswitchstatement are aligned with the enclosing block (there is only one level of indents)
  • Maximum line length is 100 characters although the pre-2020 limit of 80 characters is preferred.[14]
  • A single-statement body of a compound statement (such as if, while, and do-while) does not need to be surrounded by curly braces. If, however, one or more of the substatements in anif-elsestatement require braces, then both substatements should be wrapped in braces:
intpower(intx,inty)
{
intresult;

if(y<0){
result=0;
}else{
result=1;
while(y-->0)
result*=x;
}
returnresult;
}

Java

edit

A significant body ofJavacode uses a variant of the K&R style in which the opening brace is on the same line not only for the blocks inside a function, but also for class or method declarations. This style is widespread largely becauseSun Microsystems's original style guides[15][16][17]used this K&R variant, and as a result, most of the standard source code for theJava APIis written in this style. It is also a popular indentation style forActionScriptandJavaScript,along with theAllman style.

Stroustrup

edit

Bjarne Stroustrupadapted the K&R style for C++ in his books, such asProgramming: Principles and Practice using C++andThe C++ Programming Language.[18]

Unlike the variants above, Stroustrup does not use a "cuddled else". Thus, Stroustrup would write[18]

if(x<0){
puts("Negative");
negative(x);
}
else{
puts("Non-negative");
nonnegative(x);
}

Stroustrup extends K&R style for classes, writing them as follows:

classVector{
public:
// construct a Vector
Vector(ints):elem(newdouble[s]),sz(s){}
// element access: subscripting
double&operator[](inti){returnelem[i];}
intsize(){returnsz;}
private:
// pointer to the elements
double*elem;
// number of elements
intsz;
};

Stroustrup does not indent the labelspublic:andprivate:.Also, in this style, while the opening brace of a function starts on a new line, the opening brace of a class is on the same line as the class name.

Stroustrup allows writing short functions all on one line. Stroustrup style is a named indentation style available in the editorEmacs.Stroustrup encourages a K&R-derived style layout with C++ as stated in his modernC++ Core Guidelines.[19]

BSD KNF

edit

TheBerkeley Software Distribution(BSD) operating systems uses a style that is sometimes termedkernel normal form(KNF). Although mostly intended for kernel code, it is also widely used inuserlandcode. It is essentially a thoroughly documented variant of K&R style as used in the Bell Labs version 6 & 7Unixsource code.[20]

The SunOS kernel and userland uses a similar indentation style.[20]Like KNF, this also was based on AT&T style documents and is sometimes termed Bill Joy Normal Form.[21]The SunOS guideline was published in 1996; ANSI C is discussed briefly. The correctness of the indentation of a list of source files can be verified by thecstyleprogram written by Bill Shannon.[20][21][22]

In this style, the hard tabulator (ts invi) is kept at eight columns, while a soft tabulator is often defined as a helper also (sw in vi), and set at four. The hard tabulators are used to indent code blocks, while a soft tabulator (four spaces) of additional indentation is used for all continuing lines that must be split over multiple lines.

Moreover, function calls do not use a space before the parenthesis, although C-language native statements such asif,while,do,switchandreturndo (in the case wherereturnis used with parens). Functions that declare no local variables in their top-level block should also leave an empty line after their opening block brace.

Examples:

while(x==y){
something();
something_else();
}
final_thing();
if(data!=NULL&&res>0){
if(JS_DefineProperty(cx,o,"data",
STRING_TO_JSVAL(JS_NewStringCopyN(cx,data,res)),
NULL,NULL,JSPROP_ENUMERATE)!=0){
QUEUE_EXCEPTION("Internal error!");
gotoerr;
}
PQfreemem(data);
}else{
if(JS_DefineProperty(cx,o,"data",OBJECT_TO_JSVAL(NULL),
NULL,NULL,JSPROP_ENUMERATE)!=0){
QUEUE_EXCEPTION("Internal error!");
gotoerr;
}
}
staticJSBool
pgresult_constructor(JSContext*cx,JSObject*obj,uintNargc,
jsval*argv,jsval*rval)
{

QUEUE_EXCEPTION("PGresult class not user-instantiable");

return(JS_FALSE);
}

Allman

edit

The Allman style is named afterEric Allman.It is also sometimes termedBSD stylesince Allman wrote many of the utilities forBSDUnix (although this should not be confused with the different "BSD KNF style"; see above).

This style puts the brace associated with a control statement on the next line, indented to the same level as the control statement. Statements within the braces are indented to the next level.[12]

while(x==y)
{
something();
something_else();
}

final_thing();

This style is similar to the standard indentation used by thePascallanguages andTransact-SQL,where the braces are equivalent to the keywordsbeginandend.

(* Example Allman code indentation style in Pascal *)
proceduredosomething(x,y:Integer);
begin
whilex=ydo
begin
something();
something_else();
end;
end;

Consequences of this style are that the indented code is clearly set apart from the containing statement by lines that are almost allwhitespaceand the closing brace lines up in the same column as the opening brace. Some people feel this makes it easy to find matching braces. The blocking style also delineates the block of code from the associated control statement. Commenting out or removing a control statement or block of code, orcode refactoring,are all less likely to introduce syntax errors via dangling or missing braces. Also, it is consistent with brace placement for the outer-function block.

For example, the following is still correct syntactically:

// while (x == y)
{
something();
something_else();
}

As is this:

// for (int i=0; i < x; i++)
// while (x == y)
if(x==y)
{
something();
something_else();
}

Even like this, with conditional compilation:

intc;
#ifdef HAS_GETCH
while((c=getch())!=EOF)
#else
while((c=getchar())!=EOF)
#endif
{
do_something(c);
}

Variant: Allman-8

edit

Allman-8 uses the 8-space indentation tabs and 80-column limit of the Linux Kernel variant of K&R. The style purportedly helps improve readability on projectors. Also, the indentation size and column restriction help create a visual cue for identifying excessive nesting of code blocks. These advantages combine to help provide newer developers and learners implicit guidance to manage code complexity.[citation needed]

Whitesmiths

edit

The Whitesmiths style, also sometimes termed Wishart style, was originally used in the documentation for the first commercial C compiler, theWhitesmithsCompiler. It was also popular in the early days of Windows, since it was used in three influential Windows programming books,Programmer's Guide to WindowsbyDurant,Carlson&Yao,Programming WindowsbyPetzold,andWindows 3.0 Power Programming TechniquesbyNorton& Yao.

Whitesmiths, along withAllman,were claimed to have been the most common bracing styles in 1991 by theJargon File,with roughly equal popularity at the time.[12][23]

This style puts the brace associated with a control statement on the next line, indented. Statements within the braces are indented to the same level as the braces.

Like Ratliff style, the closing brace is indented the same as statements within the braces.[24]

while(x==y)
{
something();
something_else();
}

final_thing();

The advantages of this style are similar to those of theAllman style.Blocks are clearly set apart from control statements. The alignment of the braces with the block emphasizes that the full block is conceptually, and programmatically, one compound statement. Indenting the braces emphasizes that they are subordinate to the control statement. The ending brace no longer lines up with the statement, but instead with the opening brace.

An example:

if(data!=NULL&&res>0)
{
if(!JS_DefineProperty(cx,o,"data",STRING_TO_JSVAL(JS_NewStringCopyN(cx,data,res)),NULL,NULL,JSPROP_ENUMERATE))
{
QUEUE_EXCEPTION("Internal error!");
gotoerr;
}
PQfreemem(data);
}
elseif(!JS_DefineProperty(cx,o,"data",OBJECT_TO_JSVAL(NULL),NULL,NULL,JSPROP_ENUMERATE))
{
QUEUE_EXCEPTION("Internal error!");
gotoerr;
}

else ifare treated as statement, much like the#elifpreprocessor statement.

Like theAllmanandWhitesmithsstyles,GNUstyle puts braces on a line by themselves, indented by two spaces, except when opening a function definition, where they are not indented.[25]In either case, the contained code is indented by two spaces from the braces.

Popularised byRichard Stallman,the layout may be influenced by his background of writingLispcode.[26]In Lisp, the equivalent to a block (a progn) is a first-class data entity, and giving it its own indentation level helps to emphasize that, whereas in C, a block is only syntax. This style can also be found in someALGOLandXPLprogramming language textbooks from the 1960s and 1970s.[27][28][discuss]

Although not indentation per se, GNU coding style also includes a space after a function name – before the left parenthesis of an argument list.[25]

staticchar*
concat(char*s1,char*s2)
{
while(x==y)
{
something();
something_else();
}
final_thing();
}

This style combines the advantages ofAllmanandWhitesmiths,thereby removing the possible Whitesmiths disadvantage of braces not standing out from the block. One disadvantage is that the ending brace no longer lines up with the statement it conceptually belongs to. Another possible disadvantage is that it might waste space by using two visual levels of indents for one conceptual level, but in reality this is unlikely because, in systems with single-level indentation, each level is usually at least 4 spaces, same as 2 * 2 spaces in GNU style.

TheGNU Coding Standardsrecommend this style, and nearly all maintainers ofGNU projectsoftware use it.[citation needed]

TheGNU Emacstext editor and the GNU systems'indentcommand will reformat code according to this style by default.[29]Those who do not use GNU Emacs, or similarly extensible/customisable editors, may find that the automatic indentation settings of their editor are unhelpful for this style. However, many editors defaulting to KNF style cope well with the GNU style when the tab width is set to two spaces; likewise, GNU Emacs adapts well to KNF style by simply setting the tab width to eight spaces. In both cases, automatic reformatting destroys the original spacing, but automatic line indenting will work properly.

Steve McConnell,in his bookCode Complete,advises against using this style: he marks a code sample which uses it with a "Coding Horror" icon, symbolizing especially dangerous code, and states that it impedes readability.[24]TheLinux kernelcoding style documentation also recommends against this style, urging readers to burn a copy of the GNU coding standards as a "great symbolic gesture".[11]

Horstmann

edit

The 1997 edition ofComputing Concepts with C++ Essentialsby Cay S. Horstmann adaptsAllmanby placing the first statement of a block on the same line as the opening brace. This style is also used in examples in Jensen and Wirth'sPascal User Manual and Report.[30]

while(x==y)
{something();
something_else();
//...
if(x<0)
{printf("Negative");
negative(x);
}
else
{printf("Non-negative");
nonnegative(x);
}
}
final_thing();

This style combines the advantages ofAllmanby keeping the vertical alignment of the braces for readability, and identifying blocks easily, with the saving of a line of the K&R style. However, the 2003 edition now uses Allman style throughout.[31]

Pico

edit

This is the style used most commonly in the languagePicoby its designers. Pico lacks return statements, and uses semicolons as statement separators instead of terminators. It yields this syntax:[32]

stuff(n):
{ x: 3 * n;
y: do_stuff(x);
y + x }

The advantages and disadvantages are similar to those of saving screen real estate with K&R style. An added advantage is that the starting and closing braces are consistent in application (both share space with a line of code), relative to K&R style, where one brace shares space with a line of code and one brace has a line alone.

Ratliff

edit

In the bookProgrammers at Work, [33] C. Wayne Ratliff, the original programmer behind the populardBase-II and -IIIfourth-generation programming languages, discussed a style that is like 1TBS but the closing brace lines up with the indentation of the nested block. He indicated that the style was originally documented in material fromDigital ResearchInc. This style has sometimes been termedbannerstyle,[34]possibly for the resemblance to a banner hanging from a pole. In this style, which is toWhitesmithsas K&R is to Allman, the closing control is indented the same as the last item in the list (and thus properly loses salience)[24]The style can make visual scanning easier for some, since theheadersof any block are the only thing exdented at that level (the theory being that the closing control of the prior block interferes with the visual flow of the next block header in the K&R and Allman styles). Kernighan and Plauger use this style in the Ratfor code inSoftware Tools.[35]

// In C
for(i=0;i<10;i++){
if(i%2==0){
do_something(i);
}
else{
do_something_else(i);
}
}

C derived language styles

edit

The following styles are common for various languages derived from C that are both significantly similar and dissimilar. And, they can be adapted to C as well. They might be applied to C code written as part of a projectmostlywritten in one of these other languages, where maintaining a consistentlook and feelto the project's core code overrides considerations of using more conventional C style.

Lisp style

edit

WhileGNU styleis sometimes characterized as C code indented by a Lisp programmer, one might even go so far as to insert closing braces together in the last line of a block. This style makes indentation the only way to distinguish blocks of code, but has the advantage of containing no uninformative lines. This could easily be called the Lisp style because this style is very common in Lisp code. In Lisp, the grouping of identical braces at the end of expression trees is meant to signify that it is not the user's job to visually track nesting levels, only to understand the structure of the tree.

The traditional Lisp variant of this style prefers extremely narrow levels of indentation (typically two spaces) because Lisp code usually nests very deeply since Lisp features onlyexpressions,with no distinct class ofstatements;function arguments are mostly indented to the same level to illustrate their shared status within the enclosing expression. This is also because, braces aside, Lisp is conventionally a very terse language, omitting even common forms of simple boilerplate code as uninformative, such as theelsekeyword in anif: then | elseblock, instead rendering it uniformly as(if expr1 expr2 expr3).

// C
for(i=0;i<10;i++)
{if(i%2==0)
{do_something(i);}
else
{do_something_else(i);
do_third_thing(i);}}

;; Lisp
(dotimes(i10)
(if(=(remi2)0)
(do-somethingi)
(progn
(do-something-elsei)
(do-third-thingi))))

Note:prognis a procedure for evaluating multiple sub-expressions sequentially foreffects,while discarding all but the final (nth) return value. If all return values are desired, thevaluesprocedure would be used.

Haskell style

edit

Haskelllayout can make the placement of braces optional, although braces and semicolons are allowed in the language. [36] The two segments below are equally acceptable to the compiler:

braceless=do
text<-getContents
let
firstWord=head$wordstext
bigWord=maptoUpperfirstWord
putStrLnbigWord

braceful=do
{text<-getContents
;let
{firstWord=head$wordstext
;bigWord=maptoUpperfirstWord
}
;putStrLnbigWord
}

In Haskell, layout can replace braces. Usually the braces and semicolons are omitted forproceduraldosections and the program text in general, but the style is commonly used for lists, records and other syntactic elements made up of some pair of parentheses or braces, which are separated with commas or semicolons.[37]If code following the keywordswhere,let,orofomits braces and semicolons, then indentation is significant.[38]

APL style

edit

For an example of how terse APL typically is, here is the implementation of the step function for the Game of Life:

life{1.34=+/+¯101∘.¯101¨}

APLstyle C resembles the terse style of APL code, and is commonly used in their implementations.[39]This style was pioneered byArthur Whitney,and is heavily used in the implementation ofK,Arthur's own project. TheJprogramming language is implemented in this style as well. Notably, not all implementations of APL use this style of C, namely: GNU APL and Dyalog APL.

In addition to APL style C indentation, typically the names are shortened to either single or double characters: To reduce the amount of indentation, and expressions spanning multiple lines.[40]

Indentation size

edit

Typically, programmers use the same width of whitespace to indent each block of code with commonly used widths varying from 1 to 4 spaces.

An experiment performed on PASCAL code in 1983, found that indentation size significantly affected comprehensibility. Indentation sizes between 2 and 4 characters proved optimal.[41]

Although they both affect the general layout of code, indentationsizeis independent of the indentationstylediscussed here.

Tab vs. space

edit

Typically, a programmer uses a text editor that provides tab stops at fixed intervals (a number of spaces), to assist in maintaining whitespace according to a style. The interval is called thetab width.Sometimes the programmer stores the code with tab characters – one for each tab key press or they store a sequence of spaces equal in number to the tab width.

Storingtab charactersin code can cause visual misalignment when viewed in different contexts, which counters the value of the indentation style.

Programmers lack consensus on storing tab characters. Proponents of storing tab characters cite ease of typing and smaller text files since a single tab character serves the purpose of multiple spaces. Opponents, such asJamie Zawinski,state that using spaces instead increasescross-platformportability. [42]Others, such as the writers of theWordPresscoding standards, state the opposite: that hard tabs increase portability.[43]A survey of the top 400,000 repositories onGitHubfound that spaces are more common.[44]

Many text editors, includingNotepad++,TextEdit,Emacs,vi,andnano,can be configured to either store tab characters when entered via the tab key or to convert them to spaces (based on the configured tab width) so that tab characters are not added to the file when the tab key is pressed. Some editors can convert tab to space characters and vice versa.

Sometext file pagers,such asless,can be configured for a tab width. Some tools such asexpand/unexpandcan convert on the fly via filters.

Style automation

edit

A tool can automate formatting code per an indentation style, for example theUnixindentcommand.

Emacsprovides commands to modify indentation, including hittingTabon a given line.M-x indent-regionindents code.

Elastic tabstopsis a tabulation style which requires support from the text editor, where entire blocks of text are kept automatically aligned when the length of one line in the block changes.

Losing track of blocks

edit

In more complicated code, the programmer may lose track of block boundaries while reading the code. This is often experienced in large sections of code containing many compound statements nested to many levels of indentation. As the programmer scrolls to the bottom of a huge set of nested statements, they may lose track of context – such as the control structure at the top of the block.

Long compound statements can be acode smellofover complexitywhich can be solved byrefactoring.

Programmers who rely on counting the opening braces may have difficulty with indentation styles such as K&R, where the starting brace is not visually separated from itscontrol statement.Programmers who rely more on indentations will gain more from styles that are vertically compact, such as K&R, because the blocks are shorter.

To avoid losing track of control statements such asfor,a large indentation can be used, such as an 8-unit-wide hard tab, along with breaking up large functions into smaller and more readable functions. Linux is done this way, while using the K&R style.

Some text editors allow the programmer to jump between the two corresponding braces of a block. For example,vijumps to the brace enclosing the same block as the one under the cursor when pressing the%key. Since the text cursor'snextkey (viz., thenkey) retained directional positioning information (whether theupordownkey was formerly pressed), thedot macro(the.key) could then be used to place the text cursor on the next brace,[45]given a suitable coding style. Instead, inspecting the block boundaries using the%key can be used to enforce a coding standard.

Another way to maintain block awareness, is to use comments after the closing brace. For example:

for(inti=0;i<total;i++){
foo();
}//for (i)
if(x<0){
bar();
}//if (x < 0)

A disadvantage is maintaining the same code in multiple locations – above and below the block.

Some editors provide support for maintaining block awareness. Afolding editorcan hide (fold) and reveal (unfold) blocks by indentation level. Some editors highlight matching braces when thecursoris positioned next to one.

See also

edit

References

edit
  1. ^Weissman, Laurence Mark (1974).A Methodology For Studying The Psychological Complexity of Computer Programs.CSRG-37(Technical report). Computer Systems Research Group,University of Toronto.OCLC1085612768.technicalreportc37univ – viaInternet Archive.
  2. ^Morzeck, Johannes; Hanenberg, Stefan; Werger, Ole; Gruhn, Volker (2023).Indentation in Source Code: A Randomized Control Trial on the Readability of Control Flows in Java Code with Large Effects.Proceedings of the 18th International Conference on Software Technologies - ICSOFT.Rome,Italy. pp.117–128.doi:10.5220/0012087500003538.ISBN978-989-758-665-1– via Stefan Hanenberg onGoogle Drive(preprint).
  3. ^Hanenberg, Stefan; Morzeck, Johannes; Gruhn, Volker (9 August 2024)."Indentation and reading time: a randomized control trial on the differences between generated indented and non-indented if-statements".Empirical Software Engineering.29(5): 134.doi:10.1007/s10664-024-10531-y.ISSN1573-7616.
  4. ^Hanenberg, Stefan; Morzeck, Johannes; Werger, Ole; Gries, Stefan; Gruhn, Volker (2024)."Indentation and Reading Time: A Controlled Experiment on the Differences Between Generated Indented and Non-indented JSON Objects".In Fill, Hans-Georg; Domínguez Mayo, Francisco José; van Sinderen, Marten; Maciaszek, Leszek A. (eds.).Software Technologies.Communications in Computer and Information Science. Vol. 2104. Cham: Springer Nature Switzerland. pp.50–75.doi:10.1007/978-3-031-61753-9_4.ISBN978-3-031-61753-9.
  5. ^"Java Style Guide".Archived fromthe originalon 12 July 2018.Using either "Egyptian" curly braces or C-style curly braces is acceptable
  6. ^"Egyptian brackets".Foldoc.A humourous [sic] term for K&R indent style, referring to the "one hand up in front, one down behind" pose
  7. ^"Google JavaScript Style Guide".Braces follow the Kernighan and Ritchie style ( "Egyptian brackets" ) for nonempty blocks and block-like constructs
  8. ^Darwin, Ian F. (1988).Checking C programs with Lint.California: O'Reilly and Assosciates. p. 51.ISBN9780937175309.
  9. ^"1TBS".
  10. ^ab"Brace styles and JavaScript".7 January 2013.Retrieved8 November2018.
  11. ^ab"Linux kernel coding style".Retrieved1 January2017.
  12. ^abc"The Jargon File".4.4.7. 29 December 2003.Retrieved18 August2014.
  13. ^A detailed description of the style is given atkernel.org.
  14. ^Larabel, Michael."The Linux Kernel Deprecates The 80 Character Line Coding Style".Phoronix.Phoronix Media.Retrieved1 May2022.
  15. ^Reddy, Achut (30 March 2000)."Java Coding Style Guide"(PDF).Sun Microsystems. Archived fromthe original(PDF)on 28 February 2006.Retrieved30 May2008.
  16. ^"Java Code Conventions"(PDF).Sun Microsystems. 12 September 1997. Archived fromthe original(PDF)on 13 May 2008.Retrieved30 May2008.
  17. ^"Code Conventions for the Java Programming Language".Sun Microsystems. 20 March 1997.Retrieved30 May2008.
  18. ^abStroustrup, Bjarne (September 2010)."PPP Style Guide"(PDF).
  19. ^Stroustrup, Bjarne."C++ Core Guidelines".GitHub.Retrieved3 November2018.
  20. ^abcShannon, Bill (19 August 1996)."C Style and Coding Standards for SunOS"(PDF).1.8. Sun Microsystems, Inc.Retrieved15 June2019.
  21. ^abGregg, Brendan."DTraceToolkit Style Guide".Retrieved6 February2015.
  22. ^Shannon, Bill (9 September 1998)."cstyle.pl".illumos-gate.1.58. Sun Microsystems, Inc.Retrieved6 February2015.
  23. ^"The Jargon File (Version 2.4.3)".2.4.3. 23 January 1991.Retrieved14 May2024.
  24. ^abcMcConnell, Steve(2004).Code Complete: A practical handbook of software construction.Redmond, WA: Microsoft Press. pp.746–747.ISBN978-0-7356-1967-8.
  25. ^ab"Formatting Your Source Code".GNU Coding Standards.Retrieved6 June2016.
  26. ^Stallman, Richard (28 October 2002)."My Lisp Experiences and the Development of GNU Emacs (Transcript of speech at the International Lisp Conference)".Retrieved6 June2016.
  27. ^Baumann, Richard[in German];Feliciano, Manuel;Bauer, Friedrich Ludwig;Samelson, Klaus(1964).Introduction to ALGOL – A primer for the non-specialist, emphasizing the practical uses of the algorithmic language.Series in Automatic Computation. Englewood Cliffs, New Jersey, USA:Prentice-Hall, Inc.ISBN0-13-477828-6.LCCN64-10740.ark:/13960/t6qz35p37.Retrieved23 October2022.
  28. ^W. M. McKeeman, J. J. Horning, and D. B. Wortman,A Compiler Generator,1970,https://archive.org/details/compilergenerato00mcke
  29. ^Tested on the sample source code above on Ubuntu 18.04 with GNU indent 2.2.11 and GNU Emacs 25.2.2 started withemacs --no-init-file.
  30. ^Jensen, Kathleen; Wirth, Niklaus (1974).PASCAL User Manual and Report.Springer-Verlag.
  31. ^Horstmann Style Guide
  32. ^Ohno, Asako (2013). "A methodology to teach exemplary coding style considering students' coding style feature contains fluctuations".2013 IEEE Frontiers in Education Conference (FIE).pp.1908–1910.doi:10.1109/fie.2013.6685167.ISBN9781467352611.S2CID28385526.
  33. ^Lammers, Susan (1986).Programmers at Work.Microsoft Press.ISBN978-0-914845-71-3.
  34. ^Pattee, Jim."Artistic Style 2.05 Documentation".Artistic Style.Retrieved24 April2015.
  35. ^Kernighan, Brian W.; Plauger, P. J. (1976).Software Tools.Addison-Wesley.ISBN9780201036695.
  36. ^"The Haskell 98 Report".haskell.org.Retrieved3 March2016.
  37. ^Lipovača, Miran."Making Our Own Types and Typeclasses".learnyouahaskell.com.Retrieved3 February2016.
  38. ^Haskell Report 1.2 (1992), p.131 B.4 "Layout"
  39. ^"The J Incunabulum".jsoftware.com.Retrieved19 May2022.
  40. ^"The J source code".github.com.Retrieved12 September2024.
  41. ^Miara, Richard J.; Musselman, Joyce A.; Navarro, Juan A. & Shneiderman, Ben (November 1983)."Program Indentation and Comprehensibility"(PDF).Communications of the ACM.26(11):861–867.doi:10.1145/182.358437.S2CID11767796.Retrieved3 August2017.
  42. ^Zawinski, Jamie (2000)."Tabs versus Spaces: An Eternal Holy War".Retrieved6 June2016.
  43. ^"WordPress Coding Standards".Retrieved6 June2016.
  44. ^Hoffa, Felipe (26 July 2017)."400,000 GitHub repositories, 1 billion files, 14 terabytes of code: Spaces or Tabs?".Medium.Retrieved9 July2019.
  45. ^Lamb, Linda (1998).Learning the vi editor.O'Reilly.ISBN9781565924260.
edit

Tabs and spaces

edit