
Swift is a lot like Scala - javinpaul
https://leverich.github.io/swiftislikescala/
======
skrebbel
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 of the "familiarity" goal (and, often, to
interface with existing code) plus functional stuff because of the "powerful"
goal. In a way, they're all Java with suck removed and cool stuff bolted on
top.

So can we please stop the "ripoff!" arguments and look at what you can do with
it? (note, i'm referring to HN comments on threads about Swift more than to
the article)

C# 1 was a blatant ripoff of Java 1.2 (or something like that), with hardly
anything new added, and only the biggest suck removed. Look at where C# is
now. If Apple can push Swift the same way, there are good times ahead!

(assuming it gets good non-Apple support, but that's another rant)

~~~
noblethrasher
C# 1.0 (the spec) and especially Visual C# 1.0 (the IDE) were recapitulations
of Delphi in Java skin.

Now, C# is by far my favorite language (even though I think in ML), but I'm
now a bit envious of the Java approach: One of the big ideas of OOP going back
to Alan Kay is that OO languages should be _extremely_ dynamic, and that you
achieve performance by building better hardware (or tuning it)†. This is what
Java and Objective-C do. And, this is why Java programmers can create classes
and objects with reckless abandon and still get excellent performance.
Meanwhile, in C#, I find myself worrying about whether something should be a
class or a struct; it doesn't happen often, and I know that I ought not be
thinking about it, but it's there.

So, in summary, I now appreciate the value of putting the performance knobs on
the machine rather than in the language, which represent the two different
philosophies of Java and C#.

†Said by Alan Kay, and repeated by Steve Jobs: “People who are really serious
about software should make their own hardware.”

------
rtpg
Kinda frustrating that the language comparaison is by syntax instead of
features ( [http://www.scribd.com/doc/227879724/Swift-vs-
Scala-2-11](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 someone shows me otherwise, I'm convinced that Scala and Swift only
have superficial similarities.

~~~
densh
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 Swift and how exactly are
they different from Scala's?

Edit: changed 'superior' to 'different'.

~~~
eklavya
Don't bother, people will just say X is better than Scala here. They don't
know the amount of research done by Odersky on generics and why Scala can not
be easily beaten in this area at least.

~~~
eropple
Scala can't be easily beaten there? Man...have you used C#?

I mean, I use Scala every day, but C# gives you so much solely on reification
and Scala manifests are a real poor patch.

~~~
eklavya
Holy shit you have got to be joking. Really trolling now, are we? Take a look
at things like Shapeless
([https://github.com/milessabin/shapeless](https://github.com/milessabin/shapeless)).

~~~
eropple
I've used Shapeless. It doesn't affect my actually writing code on a daily
basis. Reified generics do.

~~~
eklavya
How exactly?

------
riffraff
The article appears to say: they both have

* first class functions

* single inheritance with traits/protocols

* extension methods

* distinction between variables and constants

* a few builtin data structures (tuples, arrays, maps etc)

By this, most "recent" PLs look like Scala. The omitted differences are where
most actually disappear (i.e. handling of variance/generics)

------
zak_mc_kracken
There are similarities, of course, as you could expect from any modern
language (i.e. created in the 21st century) but if there is something
noteworthy about all the recent languages that came out these past years
(Kotlin, Ceylon, Swift, Fantom, Gosu), it's not how much they look like Scala
but all the features from Scala that they left out.

The Scala experiment produced a lot of interesting results and added a lot of
clarity about what features are interesting in a modern language (property,
lambda, extension methods, sum/union types, and a few others) but the
complexity of Scala's type system and the uncertain shape of its code base
(see Paul Phillips' talks) is demonstrating that it's often wise to support
fewer features rather than be a kitchen-and-sink language.

I am very excited by this trend of minimalism in languages and the willingness
from language designers to say "Interesting feature but it will add too much
complexity, so I'm not adding it".

Best of luck to Swift, and I can't wait to see if a language will finally
emerge on the JVM to supplant Java (even though this might take a solid
decade).

~~~
virtualwhys
The Scala experiment, as you say, seems to be kicking some serious tail, no
need to speak of it in the past tense ;-)

Big companies are adopting Scala (Twitter, LinkedIn, eBay, Yahoo, Sony, and so
on), not surprising given Spark, Spire, Akka, Play, etc. The Scala language
itself is certainly not without problems; at this point the ecosystem behind
it is arguably its greatest strength.

Rest assured, if there is a language that will supplant Java on the JVM
(highly unlikely in the near-term), it will be Scala (or some variant [Dotty]
thereof). Ceylon's got a shot but they're a bit late to the party, and Kotlin
isn't even 1.0 yet (Java 8 and 9 will punish that project's adoption, IMO).

~~~
zak_mc_kracken
> Rest assured, if there is a language that will supplant Java on the JVM
> (highly unlikely in the near-term), it will be Scala

Not sure why you're so confident since Scala has gained about 2% mind share in
ten years of existence and it's still all but impossible to find Scala jobs,
but hey, if you like it, good for you.

~~~
thescrewdriver
It isn't too tricky finding places use Scala. Most of my dev work is done in
Scala.

------
seivan
I noticed the author wrote

let emptyArray = String[]()

That's actually old, and no longer valid. The current syntax is

let emptyArray = [String]()

------
resca79
Basically both represent the new concept of how a new language should be
today. Many similarity there are, but "it's fair to say that Swift is a
dialect of Scala" it not true. Also, the word "dialect" should be mean a
sublanguage much expressive, but in many of your examples Swift seems much
"verbose" than Scala.

------
tel
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.

------
kawa
All those languages look like a combination of Java and ML to me. Of course
they use different features and small additions here and there but overall:
ML+Java.

------
ghshephard
It's interesting, given that Joel Spolsky says of Swift "It feels exactly like
go", and this person is saying, "Swift is a dialect of Scala".

Does that then imply that Go is a dialect of Scala?

~~~
danieldk
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, Swift
manages to adopt insights from the last 30 of 40 years of PL research. Go is
an utterly boring language and has very little to do with Scala (or Swift).

~~~
themartorana
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 boring?

~~~
danieldk
_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-independent'.

Sure, it gets the job done.

 _However_ , a lot of PL research has gone into making languages safer.
Allowing you to make bugs that manifest at runtime, compile time errors. And
while large bugs may not be that big a deal for the average web application,
not everyone writes web applications. Billions are wasted on software bugs,
from research that turns out to be invalid due to multiplication of units of
measurement that cannot be multiplied, to Bitcoins that are lost due to
programming errors, to deaths caused by errors in life-critical software.

Go does almost nothing to solve the one of the largest challenges of software,
namely to make it safer. Sure, it's more safe than C. But arguable it's even a
step back from Java by its refusal to include some form of parametric
polymorphism, requiring developers to revert to runtime introspection instead.

~~~
hyp0
Speaking descriptively, not normatively, it just seems the industry is moving
towards _easier_ , not _safer_. yes, including PHP, but also python and ruby.

I think the trade-off is that _safer_ requires more upfront design, and is
more viscous (harder to change). Whereas industry seems to get better end-
results, with less design and faster iteration (i.e. so-called extreme
programming). _What 's the point_ goes the argument _of getting the wrong
thing perfectly correct?_. Added to this is the relative unpopularity of safer
languages like SML etc.

Statically typed languages (Java etc) are mainly popular more because of
performance, not safety.

So... I predict _easier_ will continue to beat _safer_... in terms of
_popularity_.

~~~
TheHydroImpulse
> Statically typed languages (Java etc) are mainly popular more because of
> performance, not safety.

No. The whole reason to have types is for safety, type safety. Where more
errors/bugs can be found and found a whole lot earlier. That's the basis of
the argument of dynamic vs statically-typed languages. If performance was all
that matters, we'd all be writing C and C++.

------
CCs
82 days ago:
[https://news.ycombinator.com/item?id=7837108](https://news.ycombinator.com/item?id=7837108)

------
xh208
I know it's off-topic but I every time I heard 'Swift' I feel sorry for 'the
other Swift' i.e.
[http://en.wikipedia.org/wiki/Swift_(parallel_scripting_langu...](http://en.wikipedia.org/wiki/Swift_\(parallel_scripting_language\))

~~~
twsted
Apple put this phrase on their Swift page
[https://developer.apple.com/swift/](https://developer.apple.com/swift/)
"Looking for the Swift parallel scripting language? Please visit
[http://swift-lang.org"](http://swift-lang.org")

------
StronglyTyped
The difference is the rounded edges, you see.

------
gamesbrainiac
I've heard a lot of people say that swift totally ripped off Kotlin, a new
language that Jetbrains is working on.

