518 points · by OberstKrueger · 10y ago · 172 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.
The features are great for people writing libraries, but general purpose code should usually only need a 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.
https://github.com/scala-native/scala-native
Though it's experimental (and will likely remain that way for a while).
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.
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.
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?
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.
https://spin.atomicobject.com/2016/04/26/swift-long-compile-...
https://thatthinginswift.com/debug-long-compile-times-swift/
It seems there's a bit of a trend back toward compiled languages (Go, Rust, Swift) that don't rely on the JVM or .NET CLR to run. I think that these are all great languages, though I almost wish for something like a better, more modern, cross-platform COM to easily share libraries among the languages.
I've only had to work with COM very, very occasionally though. If I'd had to work with it for any extended period of time, I probably wouldn't be wishing for it, or anything like it. Perhaps sharing functionality between languages is better accomplished by separate services communicating via something like 0MQ.
The best thing about it, was that it also supported metaclasses Smalltalk style. So one could go crazy with OO metaprogramming.
Sadly it died with OS/2.
Then there was the other multi-platform OO ABI project from Apple, Sun and IBM, Taligent. Also not that successful.
COM is ok to work with, when done from .NET or now UWP point of view. C++/CX and the recently announced C++/WinRT are still ok, even if a bit more wordy.
The real pain starts increasingly with C++ WTL, C++ ATL, C++ MFC or for the real masochists pure C with COM related macros and the COM IDL compiler.
Then there was that other thing called CORBA, which makes the initial versions of Java EE feel like being in heaven.
At one point, we were having issues with a COM DLL we were using from .NET, so I thought it might be fun and useful to dive in and learn more about COM. I bought Don Box's COM book, and tackled COM in Plain C: http://www.codeproject.com/Articles/13601/COM-in-plain-C
It was somewhat less fun than I'd hoped it would be.
XPCOM seems to be (somewhat) alive and kicking: https://developer.mozilla.org/en-US/docs/Mozilla/Tech/XPCOM ; Firefox and VirtualBox are the only apps I've seen that use it, though I imagine at least a few others do as well.
Another interesting book by Mr Box and co-authored by Chris Sells, purely from a historical perspective now as it's fairly ancient, is Essential .NET Vol. 1[0]. Sadly they never got around to writing a second volume.
As a humourous aside, who remembers Don's lecture he did from a bath tub?:
https://blog.mattmags.com/2011/05/19/don-box-the-bathtub-lec...
Some open source implementations are incomplete, but work continues.
https://en.wikipedia.org/wiki/OPC_Unified_Architecture
https://github.com/open62541/open62541
https://github.com/OPCFoundation
You may also find Woopsa interesting, depending on your use cases.
I suppose it wouldn't be insanely difficult to use the C interop facilities in each language plus a bit of C as glue code to share things between them. But it would be interesting to be able to say "here's my library, and here's the interface it exports. Import it and have fun!". Though I'm sure there are lots of fun details and edge cases I'm completely failing to consider.
I'm looking forward to the .NET Core to C++ compilation! There are plenty of interesting things happening in the .NET world right now.
Or Mono.
But I am with you, when Java and .NET came out, in both cases I thought it was a missing opportunity not having a full set AOT/JIT options similar to other languages.
You could get them, but NGEN required the framework to be present anyway and on Java's case the only good AOT compilers have always been commercial.
So I would remember Turbo Pascal, Delphi, Eiffel and many others with some envy.
Yeah, I think that people don't want to get back from these. The setup is more complex (as in you have to write a bunch of code) but the coupling is a lot looser.
If you're interested, please email jaybuff@apple.com with [Swift Server] in the email subject line.
Last time I played with Swift I stopped after XCode crashed 2 times in an hour for me. It is also very slow. But none other editors seem to support auto completion which is a deal-breaker for me. Without it it's hard to consume all the APIs.
I hope Apple can follow Rust's path by making a language server[0] for Swift, if Apple is serious about providing cross-platform support for it. This will enable better support in editors such as find definition, refactor and auto completion.
[0]: https://internals.rust-lang.org/t/introducing-rust-language-...
It will be interesting to see where swift goes with all this. I know Rust has a lot of traction now with cross-platform support and language features, but I think swift is poised to offer a much different experience for server-side development.
I too am excited to see where this goes; Swift is a great language.
Pretty much every part of the entire toolchain has been a pain, from Xcode being Xcode, to compiler bugs and crashes, crappy package management and bad language design.
Having built servers in Java/C#/Scala/Haskell, I'd pick Haskell over those options and Swift every single time.
First thing is that with the build tool Stack and now with recent versions of Cabal the process of having a nice repeatable consistent build is pretty smooth. I also used a tool called ghcid to get sub-second feedback on my changes as I make them.
Haskell has started at the opposite end of the spectrum to most programming languages, as in "How do I represent functions mathematically?" rather than "How do I flip this bit in the accumulator register?". Which is probably somewhat to your point about oddities, for me coming from an OOP background there was a huge mental shift that had to happen to "get it". I've found that things tend to just slot together so much more easily as a result. Curried functions for example was a revelation for me, being able to pass (== 10) to a list filter isn't some special case syntactic sugar it just falls out by default.
Now much more people have gotten to grips with it there are amazing things like the servant libraries which allow you to define a HTTP service(url, query params, request method, etc.) with a type. You can implement a service against that type and get all the appropriate checks, which is great. But then the incredible part is that you can get it to create functions for each endpoint in that service totally automatically at compile time: https://hackage.haskell.org/package/servant-client#readme
Or does Cocoa work on Linux too(last time I checked this is highly not plausible)?
Also, are there any good tutorials/courses to get started with Swift & iOS development? (having programmed in other languages, I can pick up fast, and I've lost interest in tutorials that start out very slowly and take time to get to the point.)
[0] http://thenextweb.com/dd/2016/04/07/google-facebook-uber-swi...
I'm a Swift developer, I'm learning Elixir & I love OTP's model. In my opinion Apple or anyone else won't go in that direction is because it's way different & it's learning curve will push most developers away.
I mean, it's useful if you absolutely have to use Java, but it's expensive and a pale imitation of Erlang/OTP. I'm confident that it will remain so until it dies.
Java EE has a much stronger success track record than Erlang/OTP does.
The trend has started moving away from it these past years but it's pretty clear that even the worst and early versions of Java EE (looking at you, EJB 2) have been used to power massive web sites and applications that are still in use today.
Erlang/OTP is nonexistent in comparison.
Standardize on these before everything gets out-of-hand.
Is like asking WSGI api in Python to handle all those things. It just handle raw connections and is an interface for web frameworks to worry about content and not low level stuff. Maybe database connectors would be a good inclusion as well, but in Python I believe it is not part of WSGI
On the other hand, Apple has libraries for handling image and video for macOS and iOS, are written in C but Swift interfaces so easily with C, but I don't see them releasing that stuff.