Skip to content

Commit

Permalink
Add a principles and guidelines section
Browse files Browse the repository at this point in the history
Includes discussion of trailing commas which closes #42
  • Loading branch information
nrc committed Nov 15, 2017
1 parent 7fa076e commit 7359b66
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
2 changes: 2 additions & 0 deletions guide/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ struct CRepr {
}
```

## [Guiding principles and rationale](principles.md)

## [Non-formatting conventions](advice.md)

## [Cargo.toml conventions](cargo.md)
51 changes: 51 additions & 0 deletions guide/principles.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Guiding principles and rationale

When deciding on style guidelines, the style team tried to be guided by the
following principles (in rough priority order):

* readability
- scan-ability
- avoiding misleading formatting
- accessibility - readable and editable by users using the the widest
variety of hardware, including non-visual accessibility interfaces
- readability of code when quoted in rustc error messages

* aesthetics
- sense of 'beauty'
- consistent with other languages/tools

* specifics
- compatibility with version control practices - preserving diffs,
merge-friendliness, etc.
- preventing right-ward drift
- minimising vertical space

* application
- ease of manual application
- ease of implementation (in Rustfmt, and in other tools/editors/code generators)
- internal consistency
- simplicity of formatting rules


## Overarching guidelines

Prefer block indent over visual indent. E.g.,

```
// Block indent
a_function_call(
foo,
bar,
);
// Visual indent
a_function_call(foo,
bar);
```

This makes for smaller diffs (e.g., if `a_function_call` is renamed in the above
example) and less rightward drift.

Lists should have a trailing comma when followed by a newline, see the block
indent example above. This choice makes moving code (e.g., by copy and paste)
easier and makes smaller diffs.

0 comments on commit 7359b66

Please sign in to comment.