Re: Need for Swift

2019-10-14 Thread Carl Hoefs via Cocoa-dev

> On Oct 12, 2019, at 9:24 AM, Charles Srstka via Cocoa-dev 
>  wrote:
> 
>> On Oct 12, 2019, at 10:55 AM, Pier Bover via Cocoa-dev 
>>  wrote:
>> 
>> Yeah I think Apple saw Obj-C as a barrier for developer adoption. I don't
>> think that's too far from the truth considering the emphasis on teaching
>> Swift to young devs, Playgrounds, the marketing about teenagers making
>> their first app, etc.
>> 
>> Swift has its quirks but most people around me prefer it over Obj-C too,
>> even experienced devs. From StackOverflow trends and other metrics as soon
>> as Swift was announced the popularity of Obj-C declined steadily even when
>> it was clear Swift was still not ready for production:
>> 
>>  - https://www.tiobe.com/tiobe-index/objective-c/ 
>> 
>>  - https://insights.stackoverflow.com/trends?tags=objective-c 
>> 
> Swift’s first few versions were awful, but the community has been very 
> responsive in responding to developer feedback and what we have now is really 
> quite a nice language, possibly the nicest I’ve used. The string nil checks, 
> in particular, are something I’ve become a believer in, especially when 
> spending a bunch of time trying to debug an issue while writing projects in 
> other languages that turns out to be a nil showing up somewhere where we 
> didn’t expect it.
> 
> The main quibble I have with it is the Objective-C bridge, which contains 
> much more magic than I’d prefer, and of course certain legacy issues that 
> come along with having to use the Objective-C frameworks (hello, autorelease 
> pools). When writing cross-platform code on Linux or something, these 
> complaints are of course moot. I hope they release a Windows version at some 
> point; I’d really like to see Swift gain more acceptance as a general-purpose 
> programming language.



With respect to Swift/Obj-C preference, I think it may ultimately come down to 
a mindset issue.

I see Computer Science students here falling into two groups. The group that 
likes Swift generally likes scripting languages, Python, and the like. The 
group that likes Obj-C sees Swift as being "arbitrarily syntactical" with the 
syntax of the language getting in the way of programming. (There is a third 
group that likes both languages, but it is very small.)

I can understand where both camps are coming from. A psychologist explained 
this difference in orientation as one of "convergent vs divergent" thinking, 
and most people are mostly one way or the other.

-Carl
 

___

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: Need for Swift

2019-10-14 Thread Jens Alfke via Cocoa-dev


> On Oct 14, 2019, at 11:25 AM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> I see Computer Science students here falling into two groups. The group that 
> likes Swift generally likes scripting languages, Python, and the like.

Whoa, I completely disagree. Objective-C is much, much closer to scripting 
languages than Swift, with all of its dynamic features:

* It has the 'id' type that represents any type of object
* you can send a message to an arbitrary object whether or not its class 
declares it
* you can intercept unhandled messages and do arbitrary things to handle them
* you can add, remove or override methods at runtime
* you can even create classes at runtime

Swift is very strongly-typed and less dynamic: it's very strict and nit-picky 
about types, protocol conformance, etc. Much more like C++.

Are you lumping Swift in with scripting languages simply because its 
method-call syntax is more normal looking? Or because compiler type inference 
sometimes allows you to omit variable types?

> (There is a third group that likes both languages, but it is very small.)

Most experienced iOS/Mac developers I know like both.

—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: Need for Swift

2019-10-14 Thread Charles Srstka via Cocoa-dev
> On Oct 14, 2019, at 2:30 PM, Jens Alfke  wrote:
> 
>> On Oct 14, 2019, at 11:25 AM, Carl Hoefs via Cocoa-dev 
>> mailto:cocoa-dev@lists.apple.com>> wrote:
>> 
>> I see Computer Science students here falling into two groups. The group that 
>> likes Swift generally likes scripting languages, Python, and the like.
> 
> Whoa, I completely disagree. Objective-C is much, much closer to scripting 
> languages than Swift, with all of its dynamic features:
> 
> * It has the 'id' type that represents any type of object
> * you can send a message to an arbitrary object whether or not its class 
> declares it
> * you can intercept unhandled messages and do arbitrary things to handle them
> * you can add, remove or override methods at runtime
> * you can even create classes at runtime
> 
> Swift is very strongly-typed and less dynamic: it's very strict and nit-picky 
> about types, protocol conformance, etc. Much more like C++.
> 
> Are you lumping Swift in with scripting languages simply because its 
> method-call syntax is more normal looking? Or because compiler type inference 
> sometimes allows you to omit variable types?

It’s kind of a funny dichotomy; Swift is a strictly typed language under the 
hood, but it *looks* like a scripting language on the surface, what with its 
type inference, JavaScript-looking-like “let” and “var” declarations, implicit 
closure parameters, and whatnot. Objective-C, on the other hand, is like one 
step down from Ruby on the dynamism scale under the hood, but on the surface it 
looks like a statically-typed language, thanks to the mandatory types on every 
variable declaration, even if the type is just ‘id’—although it usually isn’t, 
since in common practice we specify object types even though it’s not strictly 
necessary, and some of them can be kind of obnoxious (hello, block syntax).

Swift, on the other hand, can actually *be* a scripting language if you want it 
to; put #!/usr/bin/env swift at the top of a source file, give it execute 
permissions, and voilà, it’ll run just like a script.

>> (There is a third group that likes both languages, but it is very small.)
> 
> Most experienced iOS/Mac developers I know like both.


I’d agree with that.

Charles

___

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: Need for Swift

2019-10-14 Thread Jens Alfke via Cocoa-dev


> On Oct 14, 2019, at 5:02 PM, Charles Srstka  wrote:
> 
> Swift, on the other hand, can actually *be* a scripting language if you want 
> it to; put #!/usr/bin/env swift at the top of a source file, give it execute 
> permissions, and voilà, it’ll run just like a script.

*Anything* can be a scripting language in that sense, in Unix. I could write a 
two-line script called "run_c" containing*:
#! /bin/bash
cc "$1" -o /tmp/a.out && /tmp/a.out
and put it somewhere in my path; then I can put "#! /usr/bin/env/run_c" at the 
top of any C source file and run it as a script.

To me, "scripting language" strongly implies a CLI, plus dynamic typing, and no 
boilerplate (so I can write one-line programs.)

—Jens

* Typed in Mail. Should work, but I haven't tested it.
___

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: Need for Swift

2019-10-14 Thread Charles Srstka via Cocoa-dev
> On Oct 14, 2019, at 7:21 PM, Jens Alfke  wrote:
> 
>> On Oct 14, 2019, at 5:02 PM, Charles Srstka > > wrote:
>> 
>> Swift, on the other hand, can actually *be* a scripting language if you want 
>> it to; put #!/usr/bin/env swift at the top of a source file, give it execute 
>> permissions, and voilà, it’ll run just like a script.
> 
> *Anything* can be a scripting language in that sense, in Unix. I could write 
> a two-line script called "run_c" containing*:
>   #! /bin/bash
>   cc "$1" -o /tmp/a.out && /tmp/a.out
> and put it somewhere in my path; then I can put "#! /usr/bin/env/run_c" at 
> the top of any C source file and run it as a script.
> 
> To me, "scripting language" strongly implies a CLI, plus dynamic typing, and 
> no boilerplate (so I can write one-line programs.)
> 
> —Jens
> 
> * Typed in Mail. Should work, but I haven't tested it.

Yeah, but Swift actually has first-party support for it, unlike that rather 
hacky solution. Its syntactical similarity to scripting languages was also a 
big part of the promotional materials that Swift launched with (see: 
https://www.apple.com/ne/newsroom/2015/12/03Apple-Releases-Swift-as-Open-Source/
 

 - "Introduced in 2014, Swift is the fastest growing programming language in 
history and combines the performance and efficiency of compiled languages with 
the simplicity and interactivity of popular scripting languages.”) It seems 
clear that the intention is to blur the lines a bit, although 
implementation-wise Swift is certainly very much on the compiled, static-typed 
side of the fence.*

Charles

* Unless, of course, you put `dynamic` on everything, on an Apple platform. 
Then, you’re basically writing Objective-C with a different syntax.

___

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: Need for Swift

2019-10-14 Thread Alex Zavatone via Cocoa-dev


> On Oct 14, 2019, at 1:25 PM, Carl Hoefs via Cocoa-dev 
>  wrote:
> 
> The group that likes Obj-C sees Swift as being "arbitrarily syntactical" with 
> the syntax of the language getting in the way of programming. (There is a 
> third group that likes both languages, but it is very small.)

I am in this group.  The syntax of Swift just feels so arbitrary and to look 
deeper to solve more problems… if it weren’t for those compiler messages, it 
would be a mess.  I, for one shuddered when I saw “if let x = y” being 
something that people are expected to use and that damn, “you must unwrap this 
optional”, simply ends up making things that were simple in Objective-C, 
completely cumbersome in Swift.  

And this “everything is an extension”?  That is hell.  I love classes adopting 
protocols where the class definition of the variable must be weak, because you 
can’t do it in the protocol and oh, whar?  This proticol needs to be class 
backed?  

So much clunk to do what we could already do with ease.

But then again, my team is using VIPER and in none of the code reviews did the 
lead call in to question that every var was strong.  And they wonder why we had 
3410 memory leaks.

I’m not yet a fan.


___

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: Need for Swift

2019-10-14 Thread Pier Bover via Cocoa-dev
>
> I, for one shuddered when I saw “if let x = y” being something that people
> are expected to use and that damn, “you must unwrap this optional”, simply
> ends up making things that were simple in Objective-C, completely
> cumbersome in Swift.
>

Totally agree... I've only used Swift on one project and those optionals
are quite annoying.

Swift looks nice when reading simple examples but once you start using the
Apple frameworks the head scratching is strong.

On Mon, Oct 14, 2019 at 9:43 PM Alex Zavatone via Cocoa-dev <
cocoa-dev@lists.apple.com> wrote:

>
>
> > On Oct 14, 2019, at 1:25 PM, Carl Hoefs via Cocoa-dev <
> cocoa-dev@lists.apple.com> wrote:
> >
> > The group that likes Obj-C sees Swift as being "arbitrarily syntactical"
> with the syntax of the language getting in the way of programming. (There
> is a third group that likes both languages, but it is very small.)
>
> I am in this group.  The syntax of Swift just feels so arbitrary and to
> look deeper to solve more problems… if it weren’t for those compiler
> messages, it would be a mess.  I, for one shuddered when I saw “if let x =
> y” being something that people are expected to use and that damn, “you must
> unwrap this optional”, simply ends up making things that were simple in
> Objective-C, completely cumbersome in Swift.
>
> And this “everything is an extension”?  That is hell.  I love classes
> adopting protocols where the class definition of the variable must be weak,
> because you can’t do it in the protocol and oh, whar?  This proticol needs
> to be class backed?
>
> So much clunk to do what we could already do with ease.
>
> But then again, my team is using VIPER and in none of the code reviews did
> the lead call in to question that every var was strong.  And they wonder
> why we had 3410 memory leaks.
>
> I’m not yet a fan.
>
>
> ___
>
> 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/pierbover11%40gmail.com
>
> This email sent to pierbove...@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: Need for Swift

2019-10-14 Thread Laurent Daudelin via Cocoa-dev
I’ve been wondering the same thing. I thought that maybe because I was biased 
toward Obj-C. But if it wasn’t for the editor, damn, I don’t know how many 
times I would have to go back to unwrap one of those optionals. Are people 
supposed to know instinctively when you unwrap with “?” and when you do with 
“!”? I’m not there yet, even though I’ve been doing almost a year of Swift so 
far...

-Laurent.
-- 
Laurent Daudelin
laur...@nemesys-soft.com 
Skype: LaurentDaudelin  
Logiciels Némésys Software  
http://www.nemesys-soft.com/ 

> On Oct 14, 2019, at 22:43, Alex Zavatone via Cocoa-dev 
>  wrote:
> 
> 
> 
>> On Oct 14, 2019, at 1:25 PM, Carl Hoefs via Cocoa-dev 
>>  wrote:
>> 
>> The group that likes Obj-C sees Swift as being "arbitrarily syntactical" 
>> with the syntax of the language getting in the way of programming. (There is 
>> a third group that likes both languages, but it is very small.)
> 
> I am in this group.  The syntax of Swift just feels so arbitrary and to look 
> deeper to solve more problems… if it weren’t for those compiler messages, it 
> would be a mess.  I, for one shuddered when I saw “if let x = y” being 
> something that people are expected to use and that damn, “you must unwrap 
> this optional”, simply ends up making things that were simple in Objective-C, 
> completely cumbersome in Swift.  
> 
> And this “everything is an extension”?  That is hell.  I love classes 
> adopting protocols where the class definition of the variable must be weak, 
> because you can’t do it in the protocol and oh, whar?  This proticol needs to 
> be class backed?  
> 
> So much clunk to do what we could already do with ease.
> 
> But then again, my team is using VIPER and in none of the code reviews did 
> the lead call in to question that every var was strong.  And they wonder why 
> we had 3410 memory leaks.
> 
> I’m not yet a fan.
> 
> 
> ___
> 
> 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/laurent%40nemesys-soft.com
> 
> This email sent to laur...@nemesys-soft.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: Need for Swift

2019-10-14 Thread Quincey Morris via Cocoa-dev
OK, apologies in advance for toes trodden on or sensibilities offended, but it 
sounds like it’s time for my anti-optional-whining rant. :)

The really important thing about using Swift is that you *have to* learn to 
change the way you think about dealing with nil values. It’s not quite 
literally true (but it’s close) that in Obj-C you want to defer dealing with 
nil values *as long as possible*, while in Swift you want to deal with nil 
values *immediately*.

Putting this another way, the rule you should live and breathe is, “Don’t let 
optionals propagate through your code.”

There are some exceptions to this principle. For example, if you’re parsing a 
name string for first, middle and last name, and the middle name is optional, 
you might well choose to carry the middle name forward as `String?` (an 
optional string). But you should typically start by writing your code as if 
there are no optionals, and eliminate/resolve them as they appear.

For example, it’s a really bad idea to write code like this:

let url = URL(string: “some string”)
/* … things involving `url?` … */

It’s much better to deal with the optional right away. For example:

let url = URL(string: “some string”)! // no more optional, when your 
URL string is known good

Or, if your string can be genuinely an invalid URL string:

guard let url = URL(string: “some string”) else { /* deal with the 
error condition and … */; return } // or break or whatever

Not only does it take practice to remember to do things this way round, but 
also I *guarantee* you that it will throw your tried and trusted Obj-C code 
design patterns into chaos. You must, I’m afraid, suffer through this, long 
enough until your brain “flips” and starts pouring out code that is Swift-like 
in Swift, not Obj-C-like in Swift.

It actually took me about a year, back in the Swift 2 days, to figure out that 
I needed to write Swift like Swift, not like Obj-C, and a year or two to get 
comfortable with that. But I was slow and stupid: it shouldn’t really need to 
take that long. It just takes a willingness to spend time writing and rewriting 
sections of code until you get to that “Aha!” moment. That’s when you will 
become a Swift fan.

There’s nothing truly wrong with Obj-C as a language, and there’s no need to 
diss it in order to appreciate Swift. But the two have different coding 
patterns, and if you want to use Swift professionally you will need to learn 
and practice its natural coding patterns. (If you don’t, that’s fine too!)

People have been offering opinions all day of what Swift is like, compared to 
other languages. One point that doesn’t get mentioned is that Swift was 
intended to fill the hole where (so to speak) Obj-C 3.0 or 4.0 would go. A lot 
of its syntax and philosophy is intended to do what we did comfortably in 
Obj-C, but with more efficiency in the task of actual code writing. It’s 
evolved away from Obj-C in some fairly weird ways, but I’ll happily defend my 
belief that it *is* a more efficient way to write code.

I loved Obj-C for 15 years (or so). Now I write Swift almost exclusively.

/end rant

> On Oct 14, 2019, at 20:44 , Laurent Daudelin via Cocoa-dev 
>  wrote:
> 
> I’ve been wondering the same thing. I thought that maybe because I was biased 
> toward Obj-C. But if it wasn’t for the editor, damn, I don’t know how many 
> times I would have to go back to unwrap one of those optionals. Are people 
> supposed to know instinctively when you unwrap with “?” and when you do with 
> “!”? I’m not there yet, even though I’ve been doing almost a year of Swift so 
> far...

___

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