Live data from Hacker News

Swift is a lot like Scala

leverich.github.io

31–40 of 54 posts

Re: Swift is a lot like Scala

#31

Earlier quoted context omitted.

Aw, but what about utterly fast to develop in, utterly awesome at concurrency, utterly easy for ruby/python/dynamic-language devs to pick up and gain huge performance boosts, utterly easy to get in to the ecosystem, and utterly simple to use? I'm not a language geek mind you, but if people find it useful (and plenty of large and small companies have had huge wins with it at rapid pace) who cares if it's utterly borin…

Aw, but what about utterly fast to develop in, utterly awesome at concurrency, utterly easy for ruby/python/dynamic-language devs to pick up and gain huge performance boosts, utterly easy to get in to the ecosystem, and utterly simple to use? Most of those characteristics are also true for PHP, which is arguably also easier to deploy, since nearly every virtual hosting provider has mod_php enabled and it is 'platform…

[deleted]

Re: Swift is a lot like Scala

#32
post #25
post #12

Kinda frustrating that the language comparaison is by syntax instead of features ( http://www.scribd.com/doc/227879724/Swift-vs-Scala-2-11 is what's referenced in the article). I'm fairly convinced that Swift enums and Scala case classes are only superficially the same, and based off the discussions I've heard about generics in Swift, Swift is miles aways from even C++-levels of generics, let alone Scala's. Unless so…

Author of those slides here. They were made on the next day after the language was presented on WWDC and were based purely on the first draft of the Swift book published online by Apple. Needless to say the book was more of a tutorial than a full-blown spec at that time and many important aspects were not covered (generics were lightly documented without much details). Can you please provide details about generics in…

I think that poster is saying that Swift's generics are not as good as C++'s, and even more not as good as Scala's.

"Miles away" is ambiguous, but I think it's "miles behind" in this context, given its proximity to "even" and "let alone."

Re: Swift is a lot like Scala

#33
post #21
post #12

Kinda frustrating that the language comparaison is by syntax instead of features ( http://www.scribd.com/doc/227879724/Swift-vs-Scala-2-11 is what's referenced in the article). I'm fairly convinced that Swift enums and Scala case classes are only superficially the same, and based off the discussions I've heard about generics in Swift, Swift is miles aways from even C++-levels of generics, let alone Scala's. Unless so…

I agree - the examples given are almost infuriating. Whilst I can't comment on how idiomatic the Swift code is, the Scala code is anything but. There's little benefit to using a language like Scala if you're going to count the number of apples and oranges in a list by incrementing a mutable var for each type.

My problem with both languages is that you can count apples like that. If it can be done, it will be done.

Re: Swift is a lot like Scala

#34
post #12

Kinda frustrating that the language comparaison is by syntax instead of features ( http://www.scribd.com/doc/227879724/Swift-vs-Scala-2-11 is what's referenced in the article). I'm fairly convinced that Swift enums and Scala case classes are only superficially the same, and based off the discussions I've heard about generics in Swift, Swift is miles aways from even C++-levels of generics, let alone Scala's. Unless so…

Swift enums and Scala case classes both attempt to emulate ML/Haskell Algebraic Data Types. In the design goal there they both are identical.

Swift's enums are a more faithful translation than Scala's case classes (since case classes are more ambitiously/granularly typed, and this leads to some weakness [0]). Right now they're a little broken, though, since recursive enums lead to compiler bugs (here's are a few of my attempts to fight this: [1], [2]).

[0] http://stackoverflow.com/questions/25330359/what-are-the-pro...

[1] http://tel.github.io/2014/07/30/immutable_enumeration_in_swi...

[2] http://tel.github.io/2014/07/27/calkin-wilf-in-swift/

Re: Swift is a lot like Scala

#35

Earlier quoted context omitted.

And they all feel like dialects of OCaml ;). (I am not saying 'Haskell' here, because it does not include object oriented programming.) The thing is that the current generation of languages have so many overlapping features, that they are not all that different language-wise. Just like moving between Pascal, Ada, and Modula-2 was not that hard. Also, I'd say that Go is the exception here, because in contrast to Go, S…

Aw, but what about utterly fast to develop in, utterly awesome at concurrency, utterly easy for ruby/python/dynamic-language devs to pick up and gain huge performance boosts, utterly easy to get in to the ecosystem, and utterly simple to use? I'm not a language geek mind you, but if people find it useful (and plenty of large and small companies have had huge wins with it at rapid pace) who cares if it's utterly borin…

> Aw, but what about utterly fast to develop in, utterly awesome at concurrency, utterly easy for ruby/python/dynamic-language devs to pick up and gain huge performance boosts, utterly easy to get in to the ecosystem, and utterly simple to use?

I've been working in Go for the last three months and I've come to see most of these as false. Concurrency and improved performance are arguable, but simplicity of use and ease coming from a dynamic background have not been my experience. I feel like I'm writing in Pascal again. Code that would be trivial for me to parameterize and isolate into a function in a dynamic language (or heck, in Java) becomes an exercise in frustration, usually ending in copy-paste. The official stance of the language appears to be PRY (Please Repeat Yourself) rather than DRY, boilerplate is on the order of writing Java.

And as far as performance/concurrency go, it's not particularly competitive with other languages that've made focused efforts on either/both.

I'll say that I've found the built-in package management nice (cross my fingers, haven't hit any of the rumored version conflict issues yet), but I can't think of much else nice to say.

Re: Swift is a lot like Scala

#36
In my experiences playing with Swift it has roughly two design goals—make a modern feeling ObjC and jam it into ML/Haskell ADTs. Almost every moment of using the language feels like a tug-of-war between those two sides.

I'm personally hugely excited about this in the same way I was hugely excited about this feeling in Scala. I don't think FP and OO ought to stay on their own side of the fence—I think they're mutually useful.

But I think the OO in Swift goes way too far in order to have ObjC compatibility (perhaps).

I think that perhaps the biggest challenge that Swift falls the furthest on is managing combining immutable and mutable code. `let` and `var` are very thin veneers and it's easy to have things "change underneath you" even while writing a lot of let-like code.

I think this is mainly driven by the highly mutability-dependent ObjC bindings Swift must support in order to be useful to Apple. I also think it's a bit tragic.

My hope is that this being the early days for Swift its influence will drive more immutability through these APIs as they evolve.

Re: Swift is a lot like Scala

#37
post #22

Earlier quoted context omitted.

Because they care about performance in multi-core contexts.

Reference counting and multi-core performance are not mutually exclusive at all. In a lot of applications where you exploit parallelism, you parallelise loops (e.g. via OpenMP), usually objects go out of scope outside the parallelized loop (single threaded code), so you can use a bare pointer. In the loop you do mostly stack allocations. Of course, there are degenerate cases where there's a lot of lock contention on…

Then what languages or virtual machines uses reference counting and is performant in a muti-core context?

:-)

Re: Swift is a lot like Scala

#38
post #22

Earlier quoted context omitted.

Because they care about performance in multi-core contexts.

Reference counting and multi-core performance are not mutually exclusive at all. In a lot of applications where you exploit parallelism, you parallelise loops (e.g. via OpenMP), usually objects go out of scope outside the parallelized loop (single threaded code), so you can use a bare pointer. In the loop you do mostly stack allocations. Of course, there are degenerate cases where there's a lot of lock contention on…

You can have deterministic destruction in GC enabled languages.

Re: Swift is a lot like Scala

#39
post #34
post #12

Kinda frustrating that the language comparaison is by syntax instead of features ( http://www.scribd.com/doc/227879724/Swift-vs-Scala-2-11 is what's referenced in the article). I'm fairly convinced that Swift enums and Scala case classes are only superficially the same, and based off the discussions I've heard about generics in Swift, Swift is miles aways from even C++-levels of generics, let alone Scala's. Unless so…

Swift enums and Scala case classes both attempt to emulate ML/Haskell Algebraic Data Types. In the design goal there they both are identical. Swift's enums are a more faithful translation than Scala's case classes (since case classes are more ambitiously/granularly typed, and this leads to some weakness [0]). Right now they're a little broken, though, since recursive enums lead to compiler bugs (here's are a few of m…

Not sure what weakness you're referring to in that SO post; the OP is actually saying otherwise:

> I have always considered the Scala variation to be on the advantageous side [relative to Haskell].

Daniel Spiewak does provide an answer that points out a weakness with scala collections when used with ADTs, but (G)ADTs of and in themselves are pretty damn elegant in Scala, arguably rivaling Haskell equivalent (provided we set aside Scala's slightly more verbose implementation).

Re: Swift is a lot like Scala

#40
post #4

Any language designer that has both "modern, powerful features" and "familiar for current developers" as design goals, will end up with something not unlike other languages that have this. It is not a coincidence that Scala, modern C#, Kotlin, Xtend, Nemerle, Ceylon, Dart and Swift have a lot in common. They're all compiled languages with pretty high performance characteristics. They have support for OO stuff because…

Well, it's worth pointing out that Scala pre-dates most of the new comers you mention by several years.

Kotlin, for example, their raison d'etre seems to be, "we're Scala without the complexity"[1].

As for the syntatic similarities between Swift and Scala, well, they're not identical (and the whole `var` bit on the Scala side should be chucked out as that is far from idiomatic Scala). At most you can say that Swift is more similar to Scala than any other language, which is to say the language designers probably saw some nice-to-haves in Scala and acted accordingly.

For me Swift seems like a kind of hybrid ML Coffeescript a la Scala with a Swist ;-)

[1] http://confluence.jetbrains.com/display/Kotlin/Comparison+to...

Post reply on HN