Pitch: an Official Style Guide and Formatter for Swift

A couple examples do come to mind:

  • You have a multi-language code base, like Objective-C and Swift, but your IDE only supports one global setting for line length and indentation size (like Xcode). In that case, if the two languages have different guidelines on those characteristics, editing your code can be a frustrating experience.

  • Similar to the case above, your code is sent to or rendered on systems other than your IDE, such as code review systems, where certain formatting settings might pose difficulties. For example, GitHub's side-by-side PR diff rendering doesn't handle wide lines very well unless you have an extremely wide browser window.

And possibly others. So there are practical reasons why there may need to be some level of choice, and I do think it's important to identify those as part of this process.

switch case indentation is not an IDE bug. If I remember the history correctly, it was inherited from the LLVM code base, and the reason it was done there is because switch blocks, unlike other curly brace blocks, do not introduce a new scope, so there was a semantic meaning behind that decision. Now to be fair, that meaning does not apply to Swift per se, and it's fair to debate whether or not the same decision should be made for Swift, but whether someone agrees or disagrees with it, let's make sure the origins aren't just brushed off as a "bug".

6 Likes