March 2017
Intermediate to advanced
226 pages
5h 13m
English
The Rule of Joshua (courtesy of Joshua Weinberg, an Apple engineer who first introduced me to this style) requires space padding in colinear (single-line) bracing, as in the following example:
| | if x > y {return z} // no |
| | if x > y { return z } // yes |
Adopting this rule allows single-line clauses to breathe. They add visual whitespace that helps move the embedded statement or statements away from the control structure that surrounds them. Limit single-line clauses to statements that are quick and uncomplicated.
It’s most common to use single-line clauses when chaining functions. In the following example, single-line scopes are passed to chained filter and map functions. The first selects items that are divisible ...
Read now
Unlock full access