by ruddct · 10y ago · 0 comments
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.
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.
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.
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.
I think it's rather more likely that you simply don't understand why they're using the more obscure parts of the language on any given problem. They're probably trying to rule out certain invalid uses as type errors, which is typically encouraged in the more advanced typed languages.
The features are great for people writing libraries, but general purpose code should usually only need a subset.
In the case of Scala:
If you ever browse the standard collections library you'll run into a lot of different variance rules and implicit constraints. It is quite hard to really understand the collections library if you don't get your head around those.
If you want to use Spray for anything more complex than they spell out in their examples, then you need to understand their magnet pattern.
If you want to be able to debug a problem in Slick then you'll need to understand shapeless.
If you ever go anywhere near scalaz then you'll need to understand every esoteric symbol and operator in Scala, as well as be able to read and understand Haskell (because the patterns and types in Scalaz are often explained by reference to the Haskell equivalent)
Yes, I can set rules for my own team about what features we use internally, but I want my team to at least broadly understand the syntax and patterns used in the APIs that they interface with, which means you need to either read & understand most of the features that you aren't using internally, or avoid a very large percentage of the scala ecosystem.
Most reasonable people will agree on using a subset of the language but few will agree on what goes into that subset :)
Please have a serious look at Swift. I don't think this claim stands up to any kind of scrutiny.
Swift is more like C++ than anything else in terms of features, Kotlin has roughly the same amount of features as Scala but more special-cased ones. Kotlin solves one problem well, and only that one: If you want to write Java, but want it to be a bit less verbose, then Kotlin is perfect.
Well for it's intended audience it's exactly what they want I guess, same could be said for Swift IMO. That said, Swift definitely has boarder appeal.
You almost never need to deal with Java except if you want to.
Plus, unlike C/Ruby/Python/.NET you get a JS backend that actually works¹ (unlike mess like GWT, or various other languages).
¹ In the sense of: Scala.js is stable, mature and production-ready. You can use it, save a lot of time, share a lot of code, use mny of the libraries you already know, enjoy great IDE and tooling support, use it in real projects and make money with it.
https://github.com/scala-native/scala-native
Though it's experimental (and will likely remain that way for a while).
Not so sure, the alt-Scala train is moving fast (i.e. Dotty, Scala Meta, and Scala Native).
Scala.js is already production ready; come 2019 I'd consider present day Scala deprecated, replaced by Dotty with Scala.js and Scala Native compile targets.
In fact, initial release of the Scala to Dotty Migration Tool[1] is now available
It's happening ;-)
There are quite a few commercial JDKs with option to AOT compile to native code.
Of course, if one wants to stay in the realm of free, the existing options aren't that great.
With compiled languages like Go or Swift, that same application now is 2 MB or so. On top this, the application runs natively on the OS since it is compiled to LLVM.
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.
if let string = thing as? String
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?
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.
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.
One advantage, from the point of view of someone that likes using C++, is being a safer programming language.
C++ has several features that allow to write safe code, but they only work when working solo, or in a team that accepts and makes use of modern C++.
If you cannot control the team on how they write C++, or the libraries being used, than there is a high probability of the code base just look like "C compiled with C++".
Of course this also applies to Go and Rust vs C++.
How so? Last I checked swift doesn't have garbage collection (but does have refcounting, which is nearly as good, but still requires modifying algorithms with cycles), and only offer syntactic sugar over existing null pointer semantics (as opposed to the memory ownership guarantees provided by rust). Isn't this the exact same feature set offered by modern C++ with owned_ptr and shared_ptr?
Go + rust both have guaranteed memory safety unless you go out of your way to disable safeguards. How hard is it to shoot yourself in the foot with swift, memory wise? Do you still have to fall back on autorelease pools for tight inner loops, like in objective-c?
I personally cringe whenever I have to go back to a GC and relinquish all control over object lifecycle.
If you work in a team or use libraries, specially binary ones, you have zero guarantees that the code quality and how the memory is managed.
In Swift, RC is compulsory and manually managing memory requires asking the compiler for permission all the time, so there are minimal set of guarantees how the memory will be managed.
Modern C++ is great, and many in the community do push a lot for improving the quality, unfortunately I keep seeing the working enterprise developers just outputting C code compiled with a C++ compiler instead.
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.
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.
That said, I'm in love with the language and I'd rather wait for a compile to finish than have a server blow up because of a null pointer exception. After working on a large Python backend, it's been really nice having a compiler to watch my back.
https://spin.atomicobject.com/2016/04/26/swift-long-compile-...
https://thatthinginswift.com/debug-long-compile-times-swift/