Re: OT: Swift Code Autoformatter?
Re: OT: Swift Code Autoformatter?
- Subject: Re: OT: Swift Code Autoformatter?
- From: Quincey Morris <email@hidden>
- Date: Thu, 14 Jan 2016 12:57:36 -0800
- Feedback-id: 167118m:167118agrif8a:167118s7tz4SP1UQ:SMTPCORP
On Jan 14, 2016, at 12:36 , Charles Jenkins <email@hidden> wrote:
>
> I keep eyeing a program that you can install to work with Xcode and autoformat source code. You know, things like automatically fixing spacing around arithmetic operators and other important types of punctuation. This is oddly important in Swift, where the compiler can’t interpret things like “let half = numerator /2”
I don’t understand. (That is, I do understand, but I’m pretending for the rhetorical purposes of this post not to understand.) You type “let half = numerator /2”, which produces an inline compiler error, which you ignore, along with all the other inline compiler errors from omitting spaces when typing in the same file, then you (want to) use a utility some time later that inserts the spaces to make the errors go away? Why can’t you just type the spaces when you see the error? Sounds easier to me.
[To clarify for lurkers, Swift requires a space after the “/“ in “numerator / 2” because spaces aren’t just lexical white noise in Swift, they have semantic significance too. In particular, a binary operator such as “+” or “-“ must be surrounded by spaces to distinguish them from unary prefix/postfix operators. For example, “number +2” means the same thing as “number 2” — which is missing an operator between the subexpressions. To add 2, you need either “number + 2” or — redundantly — “number + +2”.
Note that there’s always been a smidgin of this in C/Obj-C. If you write “a ++b” it’s a syntax error, not “a + +b”, even though “a+b” is fine. Swift has just taken this a bit further, so that user-defined operators can be recognized consistently.]
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden