March 2017
Intermediate to advanced
226 pages
5h 13m
English
Unlike bracing, Swift parentheses want to hug their contents. In Swift, most coders eliminate spaces next to parentheses and square brackets. There’s no loss in readability because the parentheses act as the differentiating whitespace between successive elements.
| | print("x:", x) // yes |
| | print( "x:", x ) // uncommon |
| | let paddedCount = String(count).pad(to: 8) // yes |
| | let paddedCount = String( count ).pad( to: 8 ) // uncommon |
Some developers, like those influenced by jQuery, prefer space-padded parentheses. This is known as liberal spacing. Spaces emphasize the separation between internal components and their surrounding construct. It’s an uncommon style for Swift, but it is not an unreasonable one.
Braces ...
Read now
Unlock full access