Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'docs/dev/style.md')
| -rw-r--r-- | docs/dev/style.md | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md index 7954ae8ec6..6131cdcbdc 100644 --- a/docs/dev/style.md +++ b/docs/dev/style.md @@ -257,6 +257,25 @@ if idx >= len { **Rationale:** it's useful to see the invariant relied upon by the rest of the function clearly spelled out. +## Control Flow + +As a special case of the previous rule, do not hide control flow inside functions, push it to the caller: + +```rust +// GOOD +if cond { + f() +} + +// BAD +fn f() { + if !cond { + return; + } + ... +} +``` + ## Assertions Assert liberally. |