Re: OT: Swift Code Autoformatter?

2016-01-15 Thread Jens Alfke

> On Jan 15, 2016, at 10:47 AM, Quincey Morris 
>  wrote:
> 
> — You have a utility that assists conversion from (say) Obj-C to Swift by 
> reformatting at least the easy things according to the destination language 
> syntax. This is the use case that the other Charles added to the discussion 
> last night.

FYI, I wrote such a thing last year — Swiftier: https://github.com/snej/swiftier

It’s a Ruby script that reads Objective-C source files and does a bunch of 
regex matching and other hacky stuff to output something that’s a lot more like 
Swift source code. It’s definitely not going to compile without work, unless 
you’re very lucky, but it’ll save you a lot of grunt work.

(Oh, I wrote this before Swift 2, so it doesn’t convert NSError** parameters 
into “throws” clauses or anything like that. You can use Xcode’s updater tool 
to do that afterwards…)

—Jens
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread Charles Jenkins
Quincey,

That’s a fantastic suggestion! I work in VS all day, and I’m quite happy with 
how I can set up formatting rules in it. If VS Code is as rich for Swift, I’ll 
be able to do most of what I want automatically within it.

-- 

Charles

On January 15, 2016 at 13:47:47, Quincey Morris 
(quinceymor...@rivergatesoftware.com) wrote:

take a look at Visual Studio Code
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread Quincey Morris
On Jan 15, 2016, at 04:49 , Charles Jenkins  wrote:
> 
> so I’m sorry I picked an example that bothered you. It’s not that it’s too 
> much trouble for me to manually fix a typo like “let half = numerator /2”; I 
> just wanted a completely innocuous example


And I’m sorry I gave offense (and to the other Charles too, apparently). I was 
trying to answer the question you actually asked, which (I now suspect) was not 
the question you intended to ask (though I’m not sure).

I can understand use cases like these:

— You have a utility that you run on source files to reformat them according to 
a set of coding standards. This is sort of your use case, I suspect, or maybe 
not.

— You have a utility that assists conversion from (say) Obj-C to Swift by 
reformatting at least the easy things according to the destination language 
syntax. This is the use case that the other Charles added to the discussion 
last night.

In such cases, you’re talking about a one-time operation directly on the source 
files. (You may enforce coding standards periodically, of course, but not 
continuously with a freestanding utility.) Xcode isn’t involved — you’re 
changing text files directly.

Here’s what you actually said:

On Jan 14, 2016, at 12:36 , Charles Jenkins  wrote:
> 
> I keep eyeing a program that you can install to work with Xcode and 
> autoformat source code.

You want something installable and to “work with” Xcode and to do its work 
automatically. I can’t interpret that to mean anything but that you’re looking 
for an Xcode plug-in, or perhaps some kind of global system text enhancer, that 
updates your formatting *live* in an Xcode editing pane as you type.

In that context, your example of the space following an operator seemed a bit 
odd, since that does in fact produce an error that’s hard to ignore (and easy 
to correct as you go). That was what I chose to respond to.

I didn’t respond to any other part of your question, because you didn’t tell us 
what kinds of non-error formatting (the kind that might creep in, as you type, 
without being noticed) you wanted, nor what rules your prospective “program” 
failed to provide, and because of the uncertainty of whether you wanted 
something interactive or one-shot.

In fact, I was going to suggest you take a look at Visual Studio Code (which is 
basically the IDE editor portion of Visual Studio, but running on OS X and 
other platforms). I haven’t tried it, so I don’t know how far along it is, but 
given Microsoft’s obsession with making things customizable you might find the 
formatting rules you want in its text editor.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread sqwarqDev
> On 15 Jan 2016, at 17:38, sqwarqDev  wrote:
> 
> tell application "Xcode"
>   tell source document 1
>   set _sourceCode to contents
>   
>   -- do shell script //do all your formatting here


BTW, please don’t put a ‘do shell script’ inside a tell block like I did there; 
that's a cardinal AppleScript sin  (careless pseudocoding, sorry). Better 
structure:



set _sourceCode to ""
set _formattedCode to ""

tell application "Xcode"
tell source document 1
set my _sourceCode to contents
end tell
end tell

set _formattedCode to (do shell script somethingOrOther & _sourceCode) # 
operate on the _sourceCode here

tell application "Xcode"
tell source document 1
set contents to my _formattedCode
end tell
end tell






Best

Phil
@sqwarqdev










___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread Charles Jenkins
Thank you, squarqDev and Charles! I’ll give sed/awk a go!

Quincey, your responses are normally very helpful, so I’m sorry I picked an 
example that bothered you. It’s not that it’s too much trouble for me to 
manually fix a typo like “let half = numerator /2”; I just wanted a completely 
innocuous example that wouldn’t open up a debate leading to unhelpful noise 
like “your formatting ideas are stupid, so clearly you don’t need the formatter 
you’re looking for.”

However, considering that the compiler allows “let half = numerator/2,” 
complaining about the spacing in my example is either an inline compiler bug or 
someone at Apple just being an ass. If spaces are optional, then either space 
should be optional. There is no unary division operator to create any possible 
confusion about what the statement means. (And if I create my own unary 
division operator to do some insane thing, then I get what I deserve, right?)

-- 

Charles

On January 15, 2016 at 05:40:11, sqwarqDev (sqwarq...@icloud.com) wrote:

> On 15 Jan 2016, at 03:36, Charles Jenkins  wrote:
>  
> there’s no way for the end user to create them.


A combination of AppleScript, sed and awk will pretty much do anything you can 
imagine in terms of text formatting, and they’re all included on you mac 
already; no need for 3rd party apps.

With a project and source document already open, doing this in the 
(Apple)Script Editor will get your code into the editor, where you can then 
transform it any way you like before sending it back:


tell application "Xcode"
tell source document 1
set _sourceCode to contents

-- do shell script //do all your formatting here



-- replace the original code with your formatted changes
set contents to _sourceCode
end tell
end tell



Best


Phil
@sqwarqdev
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/cejwork%40gmail.com

This email sent to cejw...@gmail.com
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread sqwarqDev
> On 15 Jan 2016, at 03:36, Charles Jenkins  wrote:
> 
> there’s no way for the end user to create them.


A combination of AppleScript, sed and awk will pretty much do anything you can 
imagine in terms of text formatting, and they’re all included on you mac 
already; no need for 3rd party apps.

With a project and source document already open, doing this in the 
(Apple)Script Editor will get your code into the editor, where you can then 
transform it any way you like before sending it back:


tell application "Xcode"
tell source document 1
set _sourceCode to contents

-- do shell script //do all your formatting here



-- replace the original code with your formatted changes
set contents to _sourceCode
end tell
end tell



Best


Phil
@sqwarqdev
___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-15 Thread Charles Srstka
> On Jan 14, 2016, at 2:57 PM, Quincey Morris 
>  wrote:
> 
> On Jan 14, 2016, at 12:36 , Charles Jenkins  > 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.

Clearly, that one error-causing issue was the one and only style issue that he 
would ever be fixing with the linter he was asking for recommendations on, and 
he wasn’t planning to do anything else with it at all other than fix instances 
of /2.

I certainly can’t imagine any reason why anyone would ever want to use a linter.

Charles

P.S. Even for style issues that do cause errors, if you’re converting C/ObjC 
code to Swift, any tool that can cut down on the huge number of things you 
already have to fix by hand is welcome.

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-14 Thread Quincey Morris
On Jan 14, 2016, at 17:15 , Graham Cox  wrote:
> 
> That’ll shut them up …

Unfortunately not. I got in a huge fight with someone in the developer forums a 
year ago over this. This person was of the opinion that the inability to 
tolerate missing spaces was characteristic of Pascal-era compilers (that is, 
the 1970s), and any self-respecting modern compiler should be able to figure it 
out. My attempt to explain that the presence or absence of spaces carried 
semantic information … didn’t go well.


___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-14 Thread Eric E Dolecki
The compiler barks when you try things like that. You are your best code 
formatter :)

Sent from my iP6+

> On Jan 14, 2016, at 8:15 PM, Graham Cox  wrote:
> 
> 
>> On 15 Jan 2016, at 7:57 AM, Quincey Morris 
>>  wrote:
>> 
>> To clarify for lurkers, Swift requires a space after the “/“ in “numerator / 
>>  2” because spaces aren’t just lexical white noise in Swift
> 
> 
> 
> Hooray. I feel vindicated - I’ve always insisted on this as a matter of 
> style, but people always whinge about it. That’ll shut them up even though 
> it’s always been for their (and my) own good (i.e. readability).
> 
> —Graham
> 
> 
> 
> ___
> 
> Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)
> 
> 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:
> https://lists.apple.com/mailman/options/cocoa-dev/edolecki%40gmail.com
> 
> This email sent to edole...@gmail.com

___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-14 Thread Graham Cox

> On 15 Jan 2016, at 7:57 AM, Quincey Morris 
>  wrote:
> 
> To clarify for lurkers, Swift requires a space after the “/“ in “numerator /  
> 2” because spaces aren’t just lexical white noise in Swift



Hooray. I feel vindicated - I’ve always insisted on this as a matter of style, 
but people always whinge about it. That’ll shut them up even though it’s always 
been for their (and my) own good (i.e. readability).

—Graham



___

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Re: OT: Swift Code Autoformatter?

2016-01-14 Thread Quincey Morris
On Jan 14, 2016, at 12:36 , Charles Jenkins  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 (Cocoa-dev@lists.apple.com)

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:
https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com