[1] https://www.quora.com/How-does-Scala-compare-to-Java-8/answer/Denis-Kalinin
How does Scala compare to Java 8?
When
presenting a new version of Java, Brian Goetz said that while Java is
getting lambdas, it still feels like Java. I would argue that this could
be seen as both advantage and disadvantage at the same time.
The
main problem for me is that Java is still an imperative language. The
if statement is still a statement (so you need variables to define the
control flow), the HashMap still returns null, throwing and catching
exceptions is still the most common way to deal with dangerous code.
Introducing the Optional class doesn’t change anything for legacy code
if it already relies on nulls.
In
contrast, Scala has had the Option type since 2007 (version 1.1), so
pretty much everything in Scala, including the standard library, uses
it. There are type-safe ways for dealing with dangerous code such as the
Try type or ScalaZ disjunctions. Finally, “everything is an
expression”, so you don’t need variables most of the time.
Here
I’m not even talking about more advanced Scala features like pattern
matching or for comprehensions, which don’t exist in Java at the moment.
The only two advantages Java still has is
- performance
- market share
I
would argue, performance differences between Scala and Java are
irrelevant for many (if not most) projects. As for the market share,
Scala is quite easy to grasp (see my recent article The fastest way to learn Scala
).
Finally, many former Ruby/PHP/etc developers will not consider Java as a
viable option exactly because of its “Java feeling”, but they can
easily switch to Scala because it’s ”a statically typed language that
feels dynamic” (see this presentation about switching from Rails to
Scala - From a monolithic Ruby on Rails app to the JVM
).
Still,
I wouldn't blame Java architects for the decisions they've made,
because they are doing the best they can given the circumstances.
Microsoft seemed to have taken a completely different approach to
introducing new features, but they also had questionable results.
[2]
A good comparison - less than 5 min read /analysis
[3]
Books
[4]
Hands on
https://livebook.manning.com/book/functional-programming-in-scala/chapter-15/10
Summary
Hands on
https://livebook.manning.com/book/functional-programming-in-scala/chapter-15/10
Summary
You see world is getting more into functional programming.
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.