9 ms·
The Decade of Swift
- hajile 7y agoCan someone sell me on Swift over dart or kotlin? They seem to be direct competitors. Since we're talking about the future of programming, can someone sell me on Swift instead of ocaml, SML, or F#? I don't see a good reason to pick it outside of targeting Apple devices.
- zozbot234 7y agoThe nice thing about Swift is that many broad programming patterns will ultimately be shared between Swift and Rust, and Swift has better support on Apple platforms. That's quite nice if everything you've had available before was Objective C or Objective/C++.
- tambourine_man 7y agoAt the moment, there isn’t.
- pjmlp 7y agoMany developers focus on a single platform, so for those living on Apple world, Swift is an welcomed improvement over Objective-C. Outside of Apple platforms it is pretty much WIP.
- biggestdecision 7y agoI mean, that is the only reason. It's a first party language in the Apple ecosystem. If you are working outside that ecosystem, there are better choices.
- RandallBrown 7y agoOutside of targeting Apple devices, the biggest upside would probably be that way more people are using and writing about Swift than those other languages.
- rb808 7y ago> dart or kotlin? ... ocaml, SML, or F# + scala, go, rust, elixir/erlang Yeah its so much time to learn all this stuff. Its a good reason they probably will all fade, better stick to js/python/java/C#/C++ like everyone else and wait.
- leonidasv 7y ago> better stick to js/python/java/C#/C++ like everyone else I would change Java to Kotlin here, since Kotlin has a 1:1 interop with Java while having goodies like null safety, type inference and functional programming without the academicism of Scala (and its slow compilation time). If you also account for the smooth learning, Kotlin is probably the safest bet from these 9 mentioned. A lot of businesses with Java codebases are already messing with it (and not only for Android).
- twblalock 7y ago> Since we're talking about the future of programming, can someone sell me on Swift instead of ocaml, SML, or F#? I don't think the industry is likely to adopt functional languages. What people in the industry seem to want are safer programs with better null handling (e.g. optionals), friendly handling of async programming (e.g. futures/promises/async await), map/filter/reduce, immutable data types, and similar features that make programs safer and easier to write. Yet, the industry does not want to give up the object-oriented paradigm or the ability to do non-functional-programming stuff. I think the future of programming languages is going to be hybrid languages rather than functional languages, simply because they are easier to adopt. In some cases, existing languages are absorbing those new features, so many companies are benefitting from them without switching languages. Of the alternatives you mentioned, F# is the closest to being a hybrid language because of its integration with the .NET platform. Similar languages include Scala, JavaScript, Java since Java 8, Swift, Kotlin, etc. Python now has some of this stuff too. On the other hand, Go is notable for rejecting functional features and it is also growing in popularity.
- leonidasv 7y agoExcuse me, but what makes you think of OCaml, SML and F# as "future of programming"? As much as I like OCaml, for example, I don't see it being mass-adopted in the near future, nor its tooling reaching the state of more established languages. All those languages you mentioned are most likely to continue being just niche ones. The only mostly-functional language I can see being mass-adopted right now is Elixir, and it still has a long way to go.
- lostmsu 7y agoWhat is Elixir?
- Gibbon1 7y agoOne of Swift's design goals is a stable ABI. That's worth something.
- m_ke 7y agoWith Chris Lattner's move to Google and the state of Java it would interesting to see Google embrace Swift and add official support for it to Android.
- innagadadavida 7y agoGoogle will be making making it easier for devs to write portable mobile apps. But it will also need android deva to learn new language.
- 3fe9a03ccd14ca5 7y agoFrom what I understand they’ve put their chips on Kotlin.
- lostmsu 7y agoThe fight of single platform gardens?
- 6700417 7y agoThis seems very unlikely to me. They would need it to interoperate with their existing stack. They chose Kotlin where they reasonably could have chosen Swift and then worked to extend it to work with their existing stack. Judging by what I would argue has been a lukewarm reception to Swift for Tensorflow, I think it would a very hard sell to convince people within Google to support Swift as a first-class language in the rest of their ecosystem. They could for example start by adopting Swift for server-side programming for Google cloud and they seem to be putting no effort into that, at least public-facing effort.
- m_ke 7y agoI'm pretty sure they went with Kotlin before Swift was open sourced, but I agree with you that the likelihood of them doing it is very low. Swift for Tensorflow hasn't gotten much traction because the overlap between programmers who know swift and machine learning engineers is super tiny. Making the core language differentiable sounds very promising though .
- ardit33 7y agoI hate to say this, but Swift is to Objective-c, what Scala is to Java.... It was very exiting and promising at first, but it became bogged down due to its sheer run-away complexity and over-academic approach to programming.... To an outsider, or iOS new comer, Swift looks much better than Objective-c, (due to Objective-c weird syntax), but to many insiders, Swift seems like a huge missed opportunity... The use of Swift, outside Apple's ecosystem is going to be limited.
- shmerl 7y agoI think Rust supersedes it in most aspects, especially in not being Apple driven.
- skohan 7y agoI would kill for a language with Swift's productivity and usibility and Rust's tooling and ecosystem.
- zozbot234 7y agoRust can be quite usable and productive if you know the right shortcuts. The tradeoff is somewhat lowered performance (and Rust makes sure that you're aware of where you're choosing that tradeoff) but that's just the way it goes. It's not like Swift is any different.
- skohan 7y agoI think Rust is a fine language, but it's undeniable that it involves more tedium than other languages to use. If there is some tradeoff between safety, performance, and usability, Rust has prioritized safety and performance, where swift has chosen safety and usability. And that's perfectly fine. I am glad that Rust exists for those use-cases where the performance is important, but there are also cases where it's more important to be able to write a lot of code quickly with less friction. It doesn't devalue Rust to admit that there are places where it is not the optimal choice.
- dmitriid 7y ago> That’s why Swift’s expressive and very lightweight syntax And a few paragraphs later: extension Array { func sorted<T: Comparable>( by keyPath: KeyPath<Element, T> ) -> Self { sorted { $0[keyPath: keyPath] < $1[keyPath: keyPath] } } } I can't say this is lightweight any longer. My greatest gripe with Swift comes not from Swift itself but from its standard library. When most new languages start with their own standard libraries that are usually interfaces towards C APIs or POSIX, Swift's Foundation is half of MacOS and then some. I recently needed to read some data from a file in Swift, and it took me quite some time to realise there was no fopen equivalent. Read/write files is a function on String? And getting a file handle is an excercise in figuring out proper dir names and user enums? [1] There are a few other weird things in the language itself like guards which IMO are an entirely unnecessary construct that can be as easily solved with regular ifs. Or Optionals that have no way of working with them except unwrapping them (either with ! or via guards). SwiftUI, however, is a very interesting approach, and I hope there are more frameworks (especially UI frameworks) like this. [1] https://twitter.com/dmitriid/status/1201441652507844608 https://twitter.com/dmitriid/status/1201441652507844608
- saagarjha 7y ago> I can't say this is lightweight any longer. Swift optimizes for lightness at the call site, but even the definition is quite short for the constraints it imposes. > I recently needed to read some data from a file in Swift, and it took me quite some time to realise there was no fopen equivalent. You can import Darwin or Glibc to get direct access to fopen. It’s a bit unergonomic to use, though. > Read/write files is a function on String? NSString, as a deprecated holdover from Foundation. > There are a few other weird things in the language itself like guards which IMO are an entirely unnecessary construct that can be as easily solved with regular ifs. That’s the whole point of syntactic sugar and constructs which make your intent clear. > Or Optionals that have no way of working with them except unwrapping them (either with ! or via guards). There’s also the nil-coalescing operator, but the whole point is that you can’t sweep an Optional under the rug.
- dmitriid 7y ago
- cableshaft 7y agoSwift has come a long way. I remember first trying it and XCode acting like it couldn't figure anything out in Swift, and you could almost never bring up an autocomplete or search for references or jump to definitions or any nice feature in an IDE that worked just fine with Objective-C. I decided to give it another shot years later, and I'm working on a simple game in Swift right now, and it's been a much, much smoother experience. Although admittedly there's still some bizarre behavior. Like this morning while iterating over a simple for loop, XCode decided it was just going to stay on the final item in the collection and keep looping until my memory ran out, over and over again, and I couldn't find anyone talking about this online, but eventually decided to do a "Clean Build Folder" and then Build, and that fixed it (but why did it happen in the first place? So odd!). And it still doesn't always think a class I wrote or renamed is valid when referencing it in another class, but a rebuild or quitting and restarting tends to fix that. Still, I'm liking it a lot, and having a lot of fun with Swift now. SpriteKit is great for making games, except for the lack of cross-platform capability, but if the game somehow manages to take off, I can write some wrapper classes to have the same behavior as most of the SpriteKit classes I use and port it easily enough.
- Andrex 7y agoMost of these all sound like improvements to XCode, not Swift?
- cableshaft 7y agoI guess I should say "My experience in working with Swift has come a long way", because XCode being so crap with it made it a pain in the ass to code in Swift back then, for me, especially considering how rock solid Visual Studio is in comparison. To be more specific about Swift, though, there used to be a ton of things you had to bridge to Objective-C in order to do back then, and now it seems like there's almost nothing you have to bridge to Objective-C to do unless you want to work with your legacy code (all of their libraries now have Swift support, at least those that I use), and there's now a cool new SwiftUI framework that is very easy to use and very powerful.
- saagarjha 7y ago
- ncmncm 7y agoI can't really imagine Swift ever breaking out of Apple's walled garden. It's a pretty big garden, but the language concedes so much to Objective-C compatibility, it is hard to see any role for it where Objective-C never got a foothold. Where am I wrong?
- OberstKrueger 7y agoIs this necessarily a bad thing? ObjC did fine as a mostly Apple-centric language. Swift is generally a lot nicer to use than ObjC, even if it wasn't a clean break from backwards compatibility.
- gnachman 7y agoOne of my projects is pure Swift and I haven’t felt any Objective-C-based pain. Mostly this is because it doesn’t have a UI. When you touch UIKit then the legacy stuff rears its head and you have to deal with selectors and NSObject and such. I think SwiftUI is supposed to be the answer to that. We ought to know whether it works out in a decade or so :). But as long as you’re looking for a general-purpose programming language, Swift is a good choice. The type system is excellent and makes a lot of things easier. I like ARC better than GC, which is the biggest selling point in my opinion.
- willyt 7y agoTo install swift on a raspberry pi: curl -s <https://packagecloud.io/install/repositories/swift-arm/release/script.deb.sh> https://packagecloud.io/install/repositories/swift-arm/relea... | sudo bash sudo apt-get install swift5=5.0.2-v0.4 [0] https://lickability.com/blog/swift-on-raspberry-pi/ https://lickability.com/blog/swift-on-raspberry-pi/
- wlesieutre 7y agoHN truncates long URLs, you’ll need to indent with spaces for a code block to show the whole thing
- willyt 7y ago
- sys_64738 7y ago> due to Objective-c weird syntax Objective-C is simply regular C with Smalltalk objects added. If you know Smalltalk and you know C then you're golden.
- lazyjones 7y agoSwift doesn't seem to be a bad language, but during my brief adventures with it I encountered a major drawback: differences between versions are so great, that searching the web for examples is problematic and you end up with many fruitless attempts and compiler errors. Apple's documentation isn't nearly as useful and readable as that of the Go team.
- cableshaft 7y agoThis was definitely true in the past, and might still be true now, I'm not sure, but XCode does a good job of catching Swift errors now and can fix several of them for you, and for those that don't, there mostly seems to be useful StackOverflow answers for the error messages online now. I took a long break from working with Swift and just started diving into it again, and even though there was two major versions since I last messed with it, it was pretty easy to settle into it, and I've only had to look up how to do things on a case by case basis periodically. Maybe that's just my experience, though, and others have a harder time with it.
- skohan 7y agoThis is not nearly as much of a problem as it once was. Especially with ABI stability, a lot of the language feels much more "nailed down" and language changes now tend to be additive rather than breaking.
- geophile 7y agoI like a lot about Swift: strong typing, good support for closures, reasonable abstractions. But there's a lot that I dislike too. A lot. In general, I find the language to be far too trendy and fussy. I get the impression the design was guided by the goal of streamlining snippets of code meant to highlight cool features, gaining undesirable complexity as a result. One example: Do we really need $n function parameters? In just about every other language, a function has parameters, period. Those names are used inside the function. Depending on the language they may be used outside the function too. Swift separates those inside and outside views, permitting different names for both. And then allows for no names at all! I don't care. $n parameters seem to come from primitive languages like sh, and should have stayed there. get/set/didSet introduces ridiculous complications just so we can pretend that a large number of function invocations look like assignment statements. This was a cool idea in C++, briefly, and then we discovered that having arbitrary code hide behind what looks like an ordinary assignment statement was a bad idea. Extensions also remind me of C++ excesses. It is difficult to look at a piece of code involving a variable some type and be sure that I understand how that type works. The problem is that the code implementing the type is not in one place. There is the type definition, but then there are extensions. Possibly many of them. Defined all over the place. I really dislike the irregularity surrounding let. In one context in unwraps an Optional. In another context it does not. Why? I got off the Swift train at the release in which associated types were introduced. I'm sure it solves some actual problem, but it sure wasn't clear at the time. (The project ended -- it's not that I decided to go back to Objective C.) Reference counting is far too intrusive, and it is easy to get it wrong in subtle ways. I find Java's (!) memory model relatively simple, and that's saying something. I understand why reference counting was chosen over GC. I don't have a good answer, but reference counting is just ugly. I actually think I prefer the C/C++ model of explicitly freeing memory.
- setpatchaddress 7y agoI certainly don't disagree that there's too much C++ in Swift (the Swift architects write C++ for a living, not ObjC, so it's hardly surprising) but it's not due to trendiness. Most of the features you mention derive from direct experience with Objective-C. Function arguments, property accessors (get/set/didSet), extensions (categories), etc. Every one of these things solves a real problem in the field. I don't understand your comment about reference counting being intrusive. Apple's implementation, ARC, used in Swift and modern ObjC, is essentially invisible to you if you're using native objects.
- bsaul 7y agoI’ve recentried tried google trends to see if swift was gaining popularity overall : https://trends.google.com/trends/explore?date=all&q=%2Fm%2F010sd4y3,%2Fm%2F0_lcrx4,%2Fm%2F09gbxjr,%2Fm%2F0h52xr1,%2Fm%2F0n50hxv https://trends.google.com/trends/explore?date=all&q=%2Fm%2F0... Imho There’s definitely an issue in the strategy for this language ( or for ios native development since the two are tied). My guess is cross platform development is eating mobile, and swift has nothing in that area.
- carlhung 7y agoI love swift. but i think it is getting lack of traction.