-
The parenthesis in if statements are optional in Swift. Should that be a thing, or should we stick with them?
This is a very style-oriented question. Style differs from person to person, and is very organic. Since no "style rules" have been put in place, do whatever you are most comfortable with.
Other languages also have this option, such as Ruby or Scala. Quoting from Elements of Ruby Style:
Ruby allows you to leave out parenthesis, in general, resist this temptation.
Parenthesis make the code easier to follow. General Ruby style is to use them, except in the following cases:
- Always leave out empty parentheses
- The parentheses can be left out of a single command that is surrounded by ERb delimiters -- the ERb markers make sure the code is still readable
- A line that is a single command and a single simple argument can be written without the parenthesis. Personally, I find that I do this less and less, but it's still perfectly readable. I tend not to like single lines in regular ruby code that have multiple arguments and no parentheses.
- A lot of Ruby-based Domain Specific Languages (such as Rake) don't use parenthesis to preserve a more natural language feel to their statements.
I feel like these "style rules" are very transferable to Swift as well, and should be applied in a similar fashion.
-