Hacker News new | past | comments | ask | show | jobs | submit login
What's new in Swift 3.1 (hackingwithswift.com)
111 points by ihsw on Jan 26, 2017 | hide | past | favorite | 40 comments



Great language-level features (especially the concrete extensions, finally), but I'm most interested in whether the compiler still crashes, whether it can correctly report error messages in code using type inference and closures, and whether incremental compilation works properly.


Yeah I agree. I've been using Swift for about 2 years, and my major issue is the tooling (Xcode, CocoaPods, etc.).

I've been trying plugins for every editor I like (emacs, sublime text, VS Code), and all the code completion sucks. I've researched it a bit, and it all appears to be issues with SourceKit itself. I think Swift would do much better on Linux with proper tooling - when I look at Go and Rust tools everything seems to work (I've never tried them - just going off the project readme.md and videos). I wish this was a bigger priority, but it doesn't appear to be.

It seems like this will all probably get better when the Swift Package Manager supports iOS/tvOS/watchOS. Most completion tools don't parse the Xcode project for frameworks, so you don't get completions outside of UIKit/Foundation and what's declared in your file. I imagine when SPM is ready it'll make it much easier to parse dependencies and include completions for them.


CocoaPods isn't an official tool so it's not really the Swift team's fault that it's bad. SPM should certainly have been "done" by now though, Carthage was put together quicker by a team of volunteers without access to Apple's resources and generally works perfectly (yes, deferring most of the work to xcodebuild).


For me, the amount of pleasure I derive from using Swift instead of Objective-C far outweighs the downside of crashes and bad error messages. At this point I think I'd stop working on iOS/macOS if I had to go back to working in Objective-C again. Though I do hope they make fixing the compiler crashes a priority soon.


We fixed a lot of bugs while working on the new generics features in Swift 3.1 (and also recursive protocol constraints, which didn't quite make it in but a lot of the plumbing was done for it).

For example, in practicalswift's fuzzer collection, 260 cases were fixed between 3.0 and 3.1, for a total of 5426 fixed (with 39 still open).


Thanks Slava, that's great news!


There were some improvements to type inference with closures in 3.1. Do you have example snippets that are giving you trouble?


The original statement regarding Swift 4 was "the primary goals are to deliver on the promise of source stability from 3.0 on, and to provide ABI stability for the standard library." I hope this statement is still true. The Swift 3 upgrade was painful, I hope to see more stability out of the language from here on out.


It was a bit of work but I would say that it was worth all the changes. I like Apple's preference to make breaking changes to make the language better.

Apple wrote a decent conversion tool for 2.x -> 3.x; yes it is far from perfect.

Btw, I documented most of my changes on my blog, in the hopes that the next person would be able to make their changes in half the time:

https://h4labs.wordpress.com/2016/09/17/my-ios-10-and-swift-...

Everyone using Swift will soon be on version 3.x. Compare this to languages like Python where there will need to be a major 2020 conversion to 3.x because many developers are dragging their feet.

The community needs to accept a little pain or pay for past language design mistakes for decades.


> Compare this to languages like Python where there will need to be a major 2020 conversion to 3.x because many developers are dragging their feet.

That's not a very fair comparison. Python is 25 years old and this migration is being requested after 20 years in existence. There is no way a successful language can perform this kind of migration at that age without pain. Swift will be no exception if it's still around and popular in 20 years.


Yes, I understand that the conversion is in some ways more difficult because there's a larger legacy code base. However, the conversion has already been extended 5 years:

https://news.ycombinator.com/item?id=7581434

A decade long conversion is fine if that is what the community wants. There are certain drawbacks to this.

I simply like the aggressiveness that Apple has taken. The community can put "all its wood behind one arrow".


I like the aggressiveness too but it's pretty common for very young languages because the cost is so low. Swift is not doing anything new there.


Really? I've been programming for almost 35 years and I can't think of many languages that made such big changes. Java, for example, is still compatible with 1.0.


Java is one language among hundreds that have come out these past twenty years.


Yes, I know that. You could provide your examples of some other popular languages that we all know about. Sure, it's easy to change a language no one uses, but when you've got hundreds of thousands of users, it's much harder.


pain(x) = Language upgrade pain after x years of development. That seems like a somewhat objective concept -- about which it is fairly hard to make guesses ... If I _had_ to guess though, because of the static type system and the process guiding swift's evolution, I would hazard that Swift 23 -> Swift 24 will be significantly easier than python 2 -> python 3 ...


> Xcode 8.3 drops support for Swift 2.3. So, if you were holding back on your migration to Swift 3.x, now is the time to make the switch!

Python 2.x keeps working pretty well for many large backend-service codebases that need a lot of stability.

Swift 2.x is used for iOS and macOS client/UI apps that get significant UI "enhancements" every year. The stability desire is much less, in every sense.


iOS developers are also (for better or worse) already used to things breaking every year when a new iOS release rolls around.


Migration isn't that hard, and it's worthwhile.


Nice to see features I'm pumped about in a decimal version.


Concrete constrained extensions and nested generics are great. These were pretty big holes in the previous versions, and will help simplify a bunch of real code.


My exact thoughts. These were like 30% of the things I was looking forward to in Swift 4 so the fact that I don't have to wait is nice.


They should finish the free Foundation implementation[1] already which is the true standard library. Swift is not very useful without it, and they're talking about 4.0. It seems like Apple's giving their minimum to the community

https://github.com/apple/swift-corelibs-foundation/blob/mast...


I have always considered this a weird effort. Foundation is not Swifty (delegate protocols with optional methods, etc.). Why do we need a Swift implementation of NSMutableArray or NSNumber? Just use Array or Int/Double!

Of course, a core Swift library for URL handling is important! And on macOS/iOS it can be implemented on top of Foundation. But I don't think that library should come with a bunch of geometry, collections, or number formatting types as well. µframeworks are Swifty. The SPM documentation says something like "in general more modules is better than fewer modules", so it's weird to have a giant framework as an official core library.


No networking OR file system access in the free implementation.

You'd be hard pressed to find a Swift project that doesn't depend on Apple's proprietary Foundation because Swift needs it to talk to the world!

I don't understand what IBM is thinking.


Why are you referring to IBM ?


They are the face of Swift on Linux.


What does Kitura use for threading and IO in Linux?

Is there any library for cross platform asynchronus IO?


Good question.

For networking, Kitura uses Kitura-net, which uses BlueSocket, which in turn uses C library's sockets[1]. On GNU/Linux, this is the GNU C Library, for which a package (Glibc) is provided by the Swift port[2].

For asynchrony they seem to be using libdispatch despite it being "early in the development"[3], but I've also noticed they're wrapping epoll and curl (see 1.B again), so it's hard to gauge the real extent of the hack.

[1]: https://github.com/IBM-Swift/Kitura/blob/master/Package.swif...

https://github.com/IBM-Swift/Kitura-net/blob/master/Package....

https://github.com/IBM-Swift/BlueSocket/blob/master/Sources/...

[2] https://swift.org/blog/swift-linux-port/

[3] https://github.com/apple/swift-corelibs-libdispatch


The most recent episode of the podcast ATP has Chris Lattner discussing why trade offs such as this where made and how they prioritised. It's worth a listen. He really is/was a great ambassador for the language.



I'd say it's far better strategically to make sure swift on iOS is the official mainstream way of developping an app ( which isn't the case yet) before you start to advocate using it on a totally new territory.

How much credibility would you have if you were to say to backend developpers " swift is such a great language, you'll love coding with it on the server side", and they hear that iOS still can't include the stdlib because the language is still not stable enough ? I've tried, and the answer is none.


It's been foolish to develop iOS apps in anything but Swift since at least 2.0. Far more productive than Objective C.


Apple putting minimal effort into developer tools? Surely not! /s


I find myself now thinking in Swift and coding in ES6... looks like SwiftJS is dead [0] but notice the Cocos2D folks just released a Swift-to-Android feature [1]. I really wouldn't mind Swift uber alles... someday.

[0] https://github.com/shift-js/shift-js [1] http://forum.cocos2d-objc.org/t/swift-version-is-ported-to-a...


I'm coding all my apps in Swift and I am never going back. Server, desktop, mobile, tv, watch, linux, embeded, etc. One language to rule them all.


Any news on android development using swift ? The android folder in the swift.org project has always intrigued me.


The Android port is maintained by a volunteer, Brian Gesiak. You can ask him about it on Twitter: https://twitter.com/modocache


I hope that after swift 4 new changes are non breaking


Swift 4 has a -swift-version flag. When set to 3, all valid Swift 3 code should compile.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: