liveBook · Manning

Indentation

As explained in Fabulous Adventures in Data Structures and Algorithms

Indentation is horizontal whitespace used to indicate nesting or structural level in formatted source code.

Indentation uses horizontal spacing to make source-code structure visible. In pretty printing, it helps readers follow nesting while competing with line width and vertical compactness. section 9.1

A pretty printer treats indentation as part of a wider layout policy:

  • Keep lines within a chosen width, commonly 80 or 100 characters, unless breaking is impractical. section 9.1
  • Insert line breaks where expressions can separate, then indent the material following a break. section 9.4.2
  • Balance readable structure against fewer line breaks and less vertical scrolling; these goals can conflict. section 9.1

Indenting a call argument list

A call that exceeds an 80-character limit can place each argument on a new line and indent the list. Nested expressions may receive further indentation, producing a layout such as Frobozz.Frobulator.Frobulate( followed by indented arguments and a closing parenthesis. section 9.4.2

Frobozz.Frobulator.Frobulate(
    (Blob.Width + Cob.Width) * Glob.Length,
    Qbert.Quux.Qix)

Shows indentation in a generated C#-style call, including a nested expression aligned beneath its argument list. section 9.4.2

How Fabulous Adventures in Data Structures and Algorithms covers it

How deep it goes
Defines indentation through formatting goals and implements it in grouped expression and parenthesis-list documents.
Examples
Uses conditional statements, comments, nested member access, and comma-separated call arguments to compare indentation choices.
What it assumes
Assumes parse trees and expression visitors, while deferring lexer and parser construction.
What you can do after
Builds indentation rules into a C# document visitor that formats parse-tree expressions at a selected width.
How it connects
Connects indentation with pretty printing, parse trees, line breaks, grouping, document models, and line-width limits.

Also explained in

Compare how 6 books explain indentation →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Fabulous Adventures in Data Structures and Algorithms. The section links point to the parts of the book it draws on.