11 ms·
Great. Great great great. A thousand times great. We've been slowly converting our iOS projects over to Swift over the past year and the results have been treme
by ruddct 10y ago
Great. Great great great. A thousand times great. We've been slowly converting our iOS projects over to Swift over the past year and the results have been tremendous (a ~40% drop in LOC from ObjC, among many other benefits). Really the only language-level feature that feels missing for server development is first-class support for asynchronous/concurrent operations, but that's coming.
Swift is truly a 'best of most worlds' language. Typed, but without the boilerplate seen in a lot of typed languages. Syntax that makes sense and is consistent. Immutability strongly encouraged, but not required. OO if you want it. First class functions. Etc, etc, etc. It's truly a dream to work in, can't wait for server-side to get a little more mature.
- sacheendra 10y agoI think most languages thatare popular today are 'best of most worlds' for their users. For example, Scala has all the features you specified and has an even larger ecosystem of libraries for the server side. I am still happy that this has been done as I know having a common API to program against does ease development and creates a great ecosystem as evidenced by node.JS.
- tormeh 10y agoSwift was influenced by Scala, so that's no surprise.
- desdiv 10y agoObligatory comparison: https://leverich.github.io/swiftislikescala/ https://leverich.github.io/swiftislikescala/
- tormeh 10y agoWow. They're basically identical. Scala has a bit less boilerplate sometimes, but it's also older, so I guess Swift will get syntactical sugar to catch up in time.
- melling 10y agoNo, it's a lot like Groovy: http://glaforge.appspot.com/article/apple-s-swift-programming-language-inspired-by-groovy http://glaforge.appspot.com/article/apple-s-swift-programmin... No, it's a lot like C#: http://swiftcomparsion.qiniudn.com http://swiftcomparsion.qiniudn.com
- vorg 10y agoNeither Scala nor Apache Groovy are listed in the 8 languages Swift was influenced by on its Wikipedia page. That Groovy link was written by the Apache's Groovy PMC chairperson, and is more wishful thinking that fact.
- melling 10y agoYeah, I already knew what Wikipedia said. My point was that a lot of languages look similar. Scala might have influenced Swift. Zip you go to the author's blog, he says lists those languages and says many more that he doesn't name: http://nondot.org/sabre/ http://nondot.org/sabre/
- chris_7 10y agoSome of these comparisons aren't great. The "Variable Number Of Arguments" example is better expressed in Swift with "reduce", and it's really comparing "summing an array", the varargs aspect is a minor detail of the example. The "Idiomatic Scala" example doesn't even declare a function with varargs! (yes, it uses one, but that's not really the point) The Swift function in the protocols example doesn't need to be generic, as the protocol doesn't have any associated types, and really ought to be a protocol extension regardless.
- yvsong 10y agoThe comparison should be updated to Swift 3. Swift syntax is more intuitive and readable than Scala. A common mistake in language design is to depart from C syntax, without substantial gain. For example, replacing {}, &&, || with other things. Swift strikes a great balance between intuition and innovation.
- premium-concern 10y ago> Swift syntax is more intuitive and readable than Scala Example?
- manojlds 10y agoAnd scala doesn't have {}, &&, || ?
- Cyph0n 10y agoOne benefit Swift has over Scala is that it compiles down to LLVM and is statically linked. I still love Scala though, hands-down my favorite language to work with.
- paulddraper 10y agoScala compiles to LLVM too. https://github.com/scala-native/scala-native https://github.com/scala-native/scala-native Though it's experimental (and will likely remain that way for a while).
- erichocean 10y agoWoah! That's badass. :)
- Cyph0n 10y agoI am aware of that, but it's not a fair comparison.
- paulddraper 10y agoAlso, most Scala deployments are "statically linked", i.e. all JAR/class files are together.
- Cyph0n 10y agoYes, but you need to bundle a JRE and the Scala library (~5 MB).
- trevor-e 10y agoI don't know a whole lot about any of this, but isn't Swift's library bundled with iOS apps? Or is that for a different purpose, such as iOS being able to run apps that target different versions of Swift?
- 10y ago
- hota_mazi 10y agoThe problem with Scala is not that it has all the features of Swift, it's that it has way more. Scala developers see this as an advantage, everybody else sees that as a liability. Swift and Kotin manage to capture the perfect amount of "a few new features but not too many" of all languages I've played with these past ten years. They are both the perfect example of languages that hit the right compromise in many dimensions.
- threeseed 10y agoI am terrified of working with experienced Scala developers. The code they write is less about implementing some business functionality in the most elegant way possible. But rather it's an exercise in who can use the most obscure parts of the language. And unfortunately there are far too many obscure parts.
- premium-concern 10y agoI have never seen this.
- threeseed 10y agoThe levels of enlightenment: http://www.scala-lang.org/old/node/8610 http://www.scala-lang.org/old/node/8610 Most Scala developers are in the A bracket. The experts are in the L. The code written by either is so different they could almost be different languages. You don't get this sort of split in Swift, Java etc.
- premium-concern 10y agoThis is more of a split between techniques for programming-in-the-small vs. programming-in-the-large. All languages have this. You could write more or less the same list for Swift or Java with minimal changes. Again, do you have any actual experience with this, or is this just your assumption? Because I have never seen this issue in the wild.
- deleted 10y ago[deleted]
- ahmedk92 10y agoAlso a significant drop in null dereferencing issues. The `if-let` syntax is brilliant.
- tomjakubowski 10y agoNot as general or useful as Rust's "if let", though. Rust's "if let" affords fallible pattern matching on arbitrary types, not just on "nullable pointer types" (in Safe Rust, a "nullable pointer" is simply a regular reference wrapped in Option<>).
- austinz 10y agoSwift has "if case let" for that use case. (Admittedly, the syntax is a bit esoteric.)
- steveklabnik 10y agoWorth noting that we got the idea for if let from Swift :)
- trevor-e 10y agoThese are the little things I love seeing on HN. :)
- ahmedk92 10y agoYou can use `as?`: if let string = thing as? String
- duaneb 10y agoHow is the memory management? That was always the downside of objective-c. Does it allow aliasing memory? If not, I don't see a huge amount that it actually improved over C++. Why should I use swift for server stuff over c++/go/rust?
- adamnemecek 10y ago> How is the memory management? Swift has both, reference types (heap allocated, refcounted) and value types (stack allocated (mostly)). Collections are copy on write which is actually really dank. You don't really think about memory management much (compared with Obj-C). And if you do, I usually wrap it in some sort of abstraction so that I can write it and forget it. The only modern language out of the three you mention is Rust. Swift is very similar to Rust but a bit higher level (but it seems like the languages will converge, a lot of the planned feature are creeping into Rust space). Swift is also simpler, but this is due to the fact that it's for a somewhat different purpose. A lot of the concepts are the same modulo the syntax. Rust was a major source of inspiration after all. Writing it feels like writing this C++, JS, Python, Haskell hybrid. It's like the first language I actually enjoy writing (Rust is a better language but I'm not quite fluent). That being said Swift isn't perfect but I things are getting fixed really quickly.
- deleted 10y ago[deleted]
- pcwalton 10y agoI wouldn't say Swift is simpler than Rust. The complexity is just in different places. For instance, Swift leans on OO quite heavily (as it has to for compatibility with Objective-C), and as a result its typechecker is quite a bit more complex: it's a full constraint solver as opposed to Rust's typechecker, which has a much simpler "expansion/contraction" heuristic. Of course, on the other hand, Rust has the whole lifetime system that complicates things.
- Gankro 10y agoYeah totally agreed. Swift is rife with way more special behaviours/magic to try to smooth over sloppy programming and just make stuff work. There's even a standard term for pushing a problem into the compiler: compiler heroics. Where heroics fall down, the language needs extra annotations to help the compiler out (@escaping closures is the most obvious). Swift also has a lot of slightly more ergonomic but otherwise largely unnecessary features: initializers vs static funcs, guards vs ifs, throws vs returning an enum, fileprivate vs private. Moving to working on Swift from Rust has led to me really appreciating how simple a lot of Rust really is. There's a lot of "oh it's literally just X". But the lifetime thing is a huge empowerer of Rust being simpler everywhere else. It means a lot more stuff can be "just X", because X can be made safe.
- mahyarm 10y agoSwift lines of code take about 10x more time to compile compared to obj-c too. I wished for obj-c when our project started passing the ~70 kloc mark.
- melling 10y agoI don't think it's 10x slower but it's definitely slower. If you have lots of "complicated" type inferencing the compiler does have problems: https://spin.atomicobject.com/2016/04/26/swift-long-compile-time/ https://spin.atomicobject.com/2016/04/26/swift-long-compile-... https://thatthinginswift.com/debug-long-compile-times-swift/ https://thatthinginswift.com/debug-long-compile-times-swift/
- favorited 10y agoRemember that the Swift compiler is way smarter than Objective-C's. Given how dynamic the language is compared to Swift, Objective-C can make very few decisions at compile-time (inlining, static binding, de-virtualization, strict type checking, etc.). It can definitely get faster than it is now, but it is always going to be doing much more work than an Objective-C compiler.
- mahyarm 10y agoMost of the compile time issues comes from type inference (exponential algo!), a really simple file based incremental compilation logic system and generic / struct specialization. If you could make a version of swift that turns off those two features and improves incremental compilation then it would probably be pretty good. Compile speeds go into the seconds when you try simple things like append 10 array variables with a + operator because of type inference!! Swift if a nice language otherwise. Most iOS devs & tooling are small teams creating projects that are around 30-50 kloc of code total. It works ok then, but when you get to 100kloc sizes, all of that fancy stuff is a relative waste in comparison to compile speed and xcode's indexer crashing and dying all the time. Backend server projects usually have codebases that are far larger than clients after a while, so I worry about using it in the backend like that.
- 10y ago