Live data from Hacker News

Why Java folks should look forward to Scala

blog.dhananjaynene.com

1–10 of 36 posts

Re: Why Java folks should look forward to Scala

#2
I knew I felt some unease with Scala's abbreviated lambda syntax, but couldn't pin down what it was that bothered me. Seeing these examples clarified it:

    def apply() = l map (_())

    println (users filter (_.age 
The first two uses of () are anonymous functions, the last is a tuple. The only way to tell them apart, best I can tell, is the use of _ turns the scope of the surrounding parens into a lambda.

Clojure uses the reader macro #() to indicate an anonymous function.

    #(
For me, at least, having a visual clue to distinguish between abbreviated lambda syntax and other kinds of expressions (tuples in the case of Scala) greatly improves code readability.

Re: Why Java folks should look forward to Scala

#3
Java programmers who are looking for "a better Java" would probably be happier with C# than they would be with Scala, although C# doesn't run on the JVM. The "Manifest" mechanism undoes some but not all of the damage done by type erasure in the JVM, so to some extent building a more richly typed language on the JVM is like driving a car with a broken window.

My first Scala program rolled off my fingers and worked the first time. My second one ran headlong into a number of difficulties; people pointed out that the newest version of Scala added some things (not in the book I had) that would make things easier and they were right... sorta.

Now I've been doing fit-and-finish work on a mixed Scala-Java system written by people with PhD's in computer science and personally I think they'd have been better off writing the whole thing in Java.

Re: Why Java folks should look forward to Scala

#4
post #2

I knew I felt some unease with Scala's abbreviated lambda syntax, but couldn't pin down what it was that bothered me. Seeing these examples clarified it: def apply() = l map (_()) println (users filter (_.age The first two uses of () are anonymous functions, the last is a tuple. The only way to tell them apart, best I can tell, is the use of _ turns the scope of the surrounding parens into a lambda. Clojure uses the…

Scala has a lot of utility and I hope that people don't completely discount the platform entirely just because of these examples. Hopefully in time as the platform matures we'll see a better solution to the above.

Re: Why Java folks should look forward to Scala

#5

Java programmers who are looking for "a better Java" would probably be happier with C# than they would be with Scala, although C# doesn't run on the JVM. The "Manifest" mechanism undoes some but not all of the damage done by type erasure in the JVM, so to some extent building a more richly typed language on the JVM is like driving a car with a broken window. My first Scala program rolled off my fingers and worked the…

I can definitely relate to that. I was in a discussion a while ago with 2 friends, and I was "the Java guy". After that chat, I decided to go back to C# and give it a second chance, despite my Microsoft allergy ;)

It is clearly a better designed language, which of course "borrowed" a lot (90%?) from Java - and then improved it.

Re: Why Java folks should look forward to Scala

#6
post #2

I knew I felt some unease with Scala's abbreviated lambda syntax, but couldn't pin down what it was that bothered me. Seeing these examples clarified it: def apply() = l map (_()) println (users filter (_.age The first two uses of () are anonymous functions, the last is a tuple. The only way to tell them apart, best I can tell, is the use of _ turns the scope of the surrounding parens into a lambda. Clojure uses the…

In Scala the _ is the anaphoric it, not necessarily a lambda form (although Scala does the lambda inference based on it). That is, _ serves the same general role as Clojure's % in these examples.

Re: Why Java folks should look forward to Scala

#7

Java programmers who are looking for "a better Java" would probably be happier with C# than they would be with Scala, although C# doesn't run on the JVM. The "Manifest" mechanism undoes some but not all of the damage done by type erasure in the JVM, so to some extent building a more richly typed language on the JVM is like driving a car with a broken window. My first Scala program rolled off my fingers and worked the…

I can definitely relate to that. I was in a discussion a while ago with 2 friends, and I was "the Java guy". After that chat, I decided to go back to C# and give it a second chance, despite my Microsoft allergy ;) It is clearly a better designed language, which of course "borrowed" a lot (90%?) from Java - and then improved it.

More to the point, Microsoft is continuously improving C#

I was at a conference back in 1997 where we came up with a wish list of features we'd like in Java for high performance computing. We all knew it was useless to ask this from Sun, but we did anyway.

The first version of C# had everything we asked for in it, and even early versions of C# had a 'delegate' mechanism that was, more or less, method pointers.

C# 3.0 introduced support for functional programming; it's certainly not like CaML, but there's a reasonably fluent syntax for real closures -- with a little work in adding syntactic sugar it's not bad.

LINQ is amazing and people have barely scratched the surface of what's possible like it. There's a system for manipulating "Expression Trees" that lets you do LISP-style metaprogramming.

C# 4.0 added covariant and contravariant inheritance for generics and, unlike JVM-based languages, it works the way it is supposed to without any lame workarounds.

Comparing C# to Java as a ~language~ is like comparing modern italian to ancient latin. Changes happen in Java at a glacial rate after a tortuous process that ensures that when JDK 7 hits the streets it's going to be four years obsolete.

That said, the Java platform has an incredible ecosystem around it; using maven gives me the feeling I'm in Manhattan and can plug into an infinite library of amazing stuff.

The .NET ecosystem, on the other hand, feels like being a crossroads town in the middle of Iowa. Occasionally you get something good like NUnit, but open source offerings are anemic or absent, and commercial libraries often come across like ads in the SkyMall catalog. (Often you can implement the 5% of the library you need yourself in the time you'd spent talking to salespeople)

Re: Why Java folks should look forward to Scala

#9
There is no doubt in my mind that if Java had added just a few features of these languages we wouldn't be having this discussion. My MVP would be lambdas, type inference, properties and extension methods and that would probably have been enough to make explorations outside of Java mere curiosities. In the mean time, I'll keep helping out on JDK8 to get 2/4 in there.

Re: Why Java folks should look forward to Scala

#10
The original article he's responding to mentions true generics (i.e. runtime supported). Despite all of Scala's great features, it still compiles down to Java bytecode and lacks these features that are available in the CLR. The "glacial rate" (as someone else put it) at which the Java language and runtime progresses is a major turn-off for people who want to move to the Java platform from C#/CLR or other platforms where these features already exist. Edit: and with Oracle at the helm now, it's even more of a turn-off...
Post reply on HN