
Why Java Developers Should Check Out Scala - twelsonrossman
http://www.techrepublic.com/blog/programming-and-development/why-java-developers-should-check-out-scala/5753
======
eranation
The world is split I assume between the "new wave" which prefer vim, textmate
over eclipse / aptana / vstudio, prefer linux/Mac over windows, prefer dynamic
and functional over static and object oriented, prefer git over svn, and
prefer fun startups over gray enterprises, and I can't blame them.

However, as much as it may surprise, most developers of this world, as much as
they would like to work in a startup, work in a gray, corporate enterprise,
write Java, Spring and Hibernate, or .NET, and have no clue about anything
beyond that.

Scala does a wonderful thing, it allows enterprise developers to taste some of
the goodies of Ruby / Python but stay in static Java land. which is great news
for everyone.

There are many Enterprise developers who are amazing developers and
architects, and can benefit any startup, the more they get close to newer
"trends" the more likely the connection will happen.

Young startups will benefit, 40+ enterprise Java architects will benefit, and
perhaps the talent wars will have a cease fire.

I'm pushing everyone I know to take a look at Scala, it's here to stay, and if
you take a look at play framework, it's looking even more like the next big
thing.

It all comes down to the community, if the ruby / rails community will be
scala / play friendly, and endorse it as a "ok it's Java but we hate it less",
it will help it take off.

As an enterprise developer, I really need something like scala / play to take
off, as I won't be able to get ruby on rails / django in the same way I could
get play / lift. as much as I think they are great frameworks, it's hard to
sell to the enterprise crowd.

~~~
rpearl
"dynamic and functional"

I don't understand what you've said here. The two terms are entirely
orthogonal. There are functional langauges which are dynamically "typed", and
there are functional languages which are statically typed. Lumping the two
terms together is misleading and useless.

Static typing (done correctly) is just straight up better than dynamic typing.
End sentence. I cannot count the number of times I have had errors at runtime
working in python that simply would not have existed at all if I was using a
statically typed language. With a sufficiently expressive type system, the
types do not get in the way, but you still get compile-time enforced correct
static semantics.

~~~
23david
I agree. Static typing is great. I don't know why all these scripting
languages choose to throw out static typing. If a variable is always going to
be an integer I don't know why its important to be able to stick characters,
strings or objects into it without seeing any errors. It's good for a
beginning programmer perhaps, but even with that I tend to disagree since it
encourages bad practices.

At some point I just got tired of seeing the same types of errors and wanted
my tools to work a lot better. Python / PHP / Ruby aren't improved by lacking
static types. How hard would it be to add static types into PHP, Ruby, or
Python?

[http://stackoverflow.com/questions/1365333/will-php-
become-a...](http://stackoverflow.com/questions/1365333/will-php-become-a-
full-fledged-statically-typed-oop-language-in-the-near-future)

~~~
eranation
I'm a big static typing fan, but the facts are out there, startups use Rails
and Django, and front end is JavaScript, all are dynamically typed, yet very
popular.

A good static typed language that the only difference between it and Ruby /
Python is the type system, has a good chance in being accepted by a larger
audience of developers, both enterprise and startups.

People prefer dynamic as they don't like to compile, and it provides rapid
code / refresh cycles, I don't think anyone would say no to less bugs and
better refactoring, and to self explanatory APIs using content assist.

------
cyberroadie
Here is one of the first empirical Scala vs Java studies:
<http://www.neverworkintheory.org/?p=375>

Here is the actual paper: [http://www.rz.uni-
karlsruhe.de/~kb95/papers/pankratius-Scala...](http://www.rz.uni-
karlsruhe.de/~kb95/papers/pankratius-Scala-ICSE12-preprint.pdf)

Quote from the conclusion: With respect to effort, this study refutes the
claim that Scala programs are faster to develop: in comparison to Java, Scala
requires more effort, and especially more testing and debugging effort.

~~~
spullara
My anecdotal evidence agrees with the study. Type inference is also the reason
the Scala compiler is so much slower than the Java compiler.

~~~
ExpiredLink
Scala has been on the market (i.e. promoted to a broader audience) since 2005
or so. There is plenty of evidence now that Scala is more complex than Java
and less suitable for enterprise applications. Despite the fanboy-ism here and
on reddit: the Scala hype is over. Definitly.

~~~
danieldk
Having used Scala some myself, I wouldn't be surprised that if we look back in
ten years, we have come to the conclusion that Scala is the C++ of modern
times. It tries to support relatively opposing paradigms (functional
programming - object oriented/imperative programming), has a very extensive
type system, and drags in a lot of historical baggage via Java.

I guess everyone has encountered the C++ is 'C with better strings and
arrays'-type of programmer who doesn't use RAII or the STL. Or the template-
fanatic programmer that wants to drag in template meta-programming into every
corner of the project. Or the STL fanatic that wants to replace every for-loop
by a function in std::algorithm, even if there is no appropriate fit or it
requires building a bunch of stateful function objects (thank god we have
closures now). Etc.

If projects do not impose serious restrictions, such a broad language will
quickly become an incomprehensible mess.

Being a recovering C++ fanatic myself, I believe more in smaller languages try
to solve a particular problem now. For instance, take Prolog, it's a beautiful
language for what it is aimed at: logic programming. All the weird object-
oriented Prolog experiments have died out by now, and it's a language that you
use when you want to solve a particular kind of problem.

~~~
Evbn
Yes. Scala is C++ of the JVM.

------
xwowsersx
Scala hits such a sweet spot (at least for me). It's a pleasure to use, the
language is so flexible, and you can write very nice, succinct and easy-to-
reason-about code. The support for higher-order functions and closures, etc is
really nice. I've been doing some android development in Scala and it has a
huge impact on productivity.

------
lekanwang
Java's pretty tedious for certain tasks, but it does lend itself well to large
teams coding on a large code base and being able to understand everything
quickly. Yes, Eclipse is much more heavyweight than vim, and Java's a whole
lot more heavyweight than Ruby, but I'd rather peruse through 10M lines of
Java code in Eclipse than 1M lines of Ruby code in vim any day.

Even so, I run into the infuriating aspects of Java from time to time, and
that's when Scala comes in. I see it to Java as Coffeescript is to Javascript.

~~~
Evbn
But 10M line of Java gets a lot less work done than 1M line of Ruby.

------
23david
Bad idea.

Better: Why Language Developers Should Stop Making Languages on Top of the
JVM.

Imagine if Ruby or Python were only available on top of the JVM... There may
be a need for versions of a language that live in the JVM, but don't make the
entire ecosystem dependent on it.

~~~
chimeracoder
In general, this is true, but the proper way to view Scala is as a 'fixed'
version of Java. Scala isn't really competing for the same mindshare as
Ruby/Python/etc., and for good reason. Scala is basically what Java _should_
have been (or at least, that's the goal).

Scala is not truly functional - like Java, it is object-oriented. It just so
happens that, once you step outside the Java bastardization of that term and
think about a more 'pure' OO, the result is fairly functional-looking. OO and
FP aren't really competing paradigms; rather, OO is a more complex paradigm
that can be constructed from a functional system. (The inverse is technically
true too, but much uglier in practice).

(To give an example of what I mean, Scala supports first-class objects, and
functions/methods are included in that statement. Scala does _not_ support
first-class, module-level functions (outside an object). That's not functional
programming; it's object-oriented! But if you design your OO system well, you
get something similar. Java does this badly, because methods aren't first-
class objects - and unlike C, you can't really use pointers/references to fake
the same behavior, so you get the worst of both worlds).

Of course, Scala has to deal with limitations of the JVM - that's their
compromise to gain binary inter-compatibility - but the designs of the two
languages are a night-and-day comparison.

~~~
andolanra
It is possible to be both object-oriented and functional—for example, OCaml
and several Lisps are functional languages that nonetheless feature object
systems. The two paradigms are not necessarily in conflict, and Scala is a
perfect example of a language which is both. (The definition of 'functional
language' is vague and generally somewhat informal, but broadly speaking it
has more to do with how one approaches problems than e.g. where functions are
defined.)

~~~
chimeracoder
> The two paradigms are not necessarily in conflict.

Agreed - that's my whole point. It's better to think of object-oriented
programming as a construction within FP. Of course, some (badly-designed) OO
languages like Java sandbox you and restrict your access to some of the more
powerful, higher-order concepts, which is why they seem to be 'in conflict',
when in reality, one is just a more abstractly implemented, whereas the
other's more specifically implemented.

> Scala is a perfect example of a language which is both.

No, it's not - for example, functions have to exist within an instantiation of
a class (a singleton object counts). By providing true first-class objects
(unlike Java), you get many of the same benefits as first-class functions, but
it's fundamentally not the same thing.

Really, an easy way to create a language which supports both is to start with
a very basic language with true first-class functions and closures (like Lisp)
and then define a few closures that encapsulate state (objects), and then add
a couple of basic macros that turn generic functions into bound methods (ie,
automatically provide the implicit parameter instead of calling it
explicitly).

...which is why I agree that they're not in conflict - a well-designed OO
system can be easily implemented within a well-designed functional system!

(The reverse doesn't work so well because you can easily add an implicit
parameter to generic functions, but you can't completely remove an implicit
parameter from a bound method, even if you pretend it doesn't exist - ie,
treat all methods as static methods).

~~~
andolanra
A "first-class function" is a function that can be passed to a function,
returned from a function, assigned to a variable, or stored in a data
structure or basically used in any way that you would use any value. In Scala:

    
    
        object Foo {
          def f1(x : Int) : (Int => Int) = {
            return { y : Int => x + y }
          }
          def f2(f : Int => Int) : Int = { return f(5) }
          val f3 = f1(1)
          val f4 = List(f1(2), f1(3), f1(4))
        }
    

Yes, functions cannot be defined at the toplevel (unless you're in the REPL),
but values also cannot be defined at the toplevel; they too must exist within
an object or class. In that sense, functions are on equal footing with values.

~~~
chimeracoder
> In that sense, functions are on equal footing with values.

But function objects are not on equal footing with non-function objects. You
can nest function objects _or_ non-function objects inside other function/non-
function objects, but at the root, you need an object that _isn't_ a function.

At the end of the day, yes, you can do the same things, but my original point
was that this doesn't make Scala functional: it makes Scala object-oriented
(Java, by contrast, is _not_ properly object-oriented, because it has four
kinds that aren't objects).

------
binarycrusader
I think the more interesting thing is a link in one of the comments:

    
    
      http://www.infoworld.com/d/application-development/scala-the-android-programming-language-you-didnt-know-you-had-170999
    

...I didn't realise you could use Scala with Android's Dalvik.

Admittedly, that's an article from 2011, and it's probably on hacker news
somewhere already, but still...

~~~
Evbn
Scala compiler and library implementation ships as a se of jar files, so it
can be used in any env that provides the Java API.

------
prpatel
No. I think Scala is a fine language, with lots of neat features. But it does
not give the developer enough of a leap - someone has already mentioned a
parallel between C -> C++ and Java -> Scala. I think this is a reasonable
comparison.

This is why I tell folks to avoid Scala and pick one of two other great
options which offer a fundamental change from Java:

* Groovy (dynamic lang, easy to pick up _and_ master) * Clojure (the power of LISP, steeper learning curve)

There's a bunch of stuff out there which explain why NOT Scala, so I won't
regurgitate it here.

------
bgilroy26
For anyone who wants to learn more about Scala: Martin odersky's scala class
at Coursera starts in two weeks.

------
dgabriel
For anyone who's interested, coursera is offering a Scala course taught by
Odersky this fall. It starts the 18th of September.

<https://www.coursera.org/course/progfun>

------
guelo
It is too easy to write dense indecipherable code in Scala. Until someone at
least comes up with an "Effective Scala" that is as complete as Josh Bloch's
"Effective Java" at outlining the best practices for readability and
maintainability, Scala will not be an acceptable replacement for Java in
larger organizations.

~~~
koko775
<http://twitter.github.com/effectivescala/>

------
leishulang
we need a new world where haskell is the new C(++) and Clojure(script) is the
new JAVA(Javascript).

