Swift language opinions

11 views
Skip to first unread message

John H

unread,
Aug 8, 2014, 11:53:19 AM8/8/14
to san-diego-iph...@googlegroups.com
Hello everyone,

I've been interested in iOS programming for some time but Objective-C was never an appealing language to me. For this reason, I was happy to see Apple announce Swift. I would like to know what the group thinks of Swift. Any serious limitations compared to OC? Advantages? 

Thanks
John

Randy Hsiao

unread,
Aug 11, 2014, 7:39:05 PM8/11/14
to san-diego-iph...@googlegroups.com
I've only played with Swift a bit, but so far I like it more than Obj-C.

1. Simpler syntax. In general function/variable/constant/class names not as verbose. Easier to read.

2. Safer. Type can be inferred, but not implicitly converted. People say it's annoying peppering code with "let" and "var". I think it'll actually prevent a lot of unintentional value assignments and make developer really think if something only needs to be assigned once or should be variable.

3. Switch, struct, and enum are very powerful with a lot of dynamic features. Might lead to misuse or abuse, but you know what comes with great power.

4. Has modern language features like closure, generic, extension. Closure and extension were somewhat available in Obj-C (as block and category), but Swift's versions are more powerful and resembling similar features in other languages.

5. Function and class got some nice new built-in features like returning multiple values and property observer. Finally there's no difference between ivar and property, yay!

Also, not specifically Swift but more Xcode, but Playground is fantastic. Great way to prototype or test. REPL is another very useful tool. I haven't verified Apple's speed improvement claim, but I can't imagine Swift slower than Obj-C. Also, I haven't mixed Swift and Obj-C. Would like to see how well that works performance-wise.

Swift is really an evolution of Obj-C. I've always liked Apple's approach with Obj-C: statically typed, but has dynamic features; ARC provides the convenience of managed memory system as well as the performance of MRR environment. Apple always seems to strive for the best of both worlds, and Swift looks to be a great result of that approach.

Ray Fix

unread,
Aug 11, 2014, 9:02:31 PM8/11/14
to san-diego-iph...@googlegroups.com
That’s a good list.  

One of my favorite things about Swift is that it allows for very clean, lightweight, and affordable abstractions.  Things that you just can’t do in Obj-C.  Before, a way to get around it was to write C++ code, but I was never a big fan of ObjC++ as the tools support for it were always slightly lagging.

An amazing thing about Swift is how a large portion of the language is defined in terms of itself.  For example, open a playground, type in “Int" and then command-click on it.  This will take you to the definition of a Swift Int which you can see conforms to the SignedIntegerType protocol, etc.

Now suppose you want to represent complex numbers in your program.  It is possible for you to create a clean Complex abstraction that run just as efficiently as Swift’s Ints.  Pretty awesome.

While the language still has some rough edges, as I follow the discussions in the developer forums, it seems that the Swift team is moving in the correct direction, striking a balance between performance, safety, teachability, and pragmatism.

Ray


--
You received this message because you are subscribed to the Google Groups "San Diego iOS Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to san-diego-iphone-de...@googlegroups.com.
To post to this group, send email to san-diego-iph...@googlegroups.com.
Visit this group at http://groups.google.com/group/san-diego-iphone-developers.
For more options, visit https://groups.google.com/d/optout.

Randy Hsiao

unread,
Aug 11, 2014, 9:36:43 PM8/11/14
to san-diego-iph...@googlegroups.com
Haha, ya, that's why the first time I saw this (from the Swift book), my mind was blown:

extension Int {
     func repetitions(task: () -> ()) {
          for i in 0..<self {
               task()
          }
     }
}

500.repetitions {
     println("Hello!")
To unsubscribe from this group and stop receiving emails from it, send an email to san-diego-iphone-developers+unsub...@googlegroups.com.

John H

unread,
Aug 12, 2014, 12:03:40 PM8/12/14
to san-diego-iph...@googlegroups.com
Ray, Randy,

Thanks for your list of Swift features. My other question would have been about a Linq equivalent, so I searched and found this:

https://github.com/mythz/swift-linq-examples

Linq is incredibly useful in the .Net language suite. Hopefully the github project will be useful to others in the group.

John


To unsubscribe from this group and stop receiving emails from it, send an email to san-diego-iphone-de...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages