The Artima Developer Community
Sponsored Link

Java Community News
Groovy, JRuby, or Scala: Which JVM Language to Learn Next?

45 replies on 4 pages. Most recent reply: Nov 10, 2007 11:38 AM by Jamie Lawson

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 45 replies on 4 pages [ « | 1 2 3 4 | » ]
James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 16, 2007 2:00 PM
Reply to this message Reply
Advertisement
> I think that Martin Odersky gave Scala a fighting chance
> by choosing to let it compile down to bytecodes for the
> JVM. Developers can use already developed libraries, in
> some cases ones that have been well-optimized, to produce
> applications. My assumption is that along the way the
> developers of Scala will give the option for libraries
> produced in Scala as an alternative to Java libraries.
>
> He also chose two paradigms that bring together the
> academic and business communities: functional and
> object-oriented.
>
> Basically, he's made intelligent choices to give Scala a
> chance in the wild.

I agree and I think it's got a lot of potential. But if the pointy-haired-bosses of the world don't take Scala seriously, it's not going to gain much traction in 'business'. The Scala community needs to contain it's disdain for 'blub' developers for a while.

It would also help if Scala came up a little higher on a Google search for the word 'Scala'.

Dave Webb

Posts: 55
Nickname: lazydaze
Registered: Feb, 2006

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 16, 2007 3:17 PM
Reply to this message Reply
> The Scala community needs to contain it's
> disdain for 'blub' developers for a while.

They're very kind to me!

It might be difficult to predict how well individual languages will prosper, but it's easier to predict trends in ways of doing things. OO was rumbling for a while and it just happened to be Java that caught the big wave. At the moment I think that Scala represents something who's time is coming fast, altho it might not be Scala itself that catches the wave. At the very least, Scala appears to be doing a great job of preparing the groundwork, both theoretically (it's beyond me) and practically (making the language usable to Java programmers and integrating with the JVM). That's why I'm so interested in Scala at the moment, despite it's academic feel and lack of documentation. If Scala isn't big in 5 years, something which expresses the same mind-set will be, so it's not wasted effort getting to know it. I'm learning loads.

David Pollak

Posts: 4
Nickname: dpp
Registered: Jan, 2007

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 16, 2007 3:50 PM
Reply to this message Reply
The Scala code example is very imperative. If once rewrites it functionally, I think it shows Scala's strengths more clearly:

import scala.io.Source
 
val MAXLENGTH = 70
 
def process(filename: String) = {
    Source.fromFile(filename).getLines.map(_.trim).
      zipWithIndex.filter{case (line, _) => line.length >= MAXLENGTH}.
      map{case (line, num) => (filename, num, line)}.toList
}
 
println(args.flatMap(name => process(name)).mkString("\n"))


First, the process method has no side effects (it doesn't print.) Instead, it returns a meaningful result that can be used by the caller for the caller's purposes.

The code gets the lines of the file and trims each line.

Next, it "zips" the lines together with a line number.

Next, it filters out the lines that do not violate the MAXLENGTH rule leaving only the lines that violate the rule.

Next, it combines the lines with the filename that contains the line.

The main line collects the results for each file and prints them out.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 16, 2007 6:17 PM
Reply to this message Reply
> The Scala code example is very imperative. If once
> rewrites it functionally, I think it shows Scala's
> strengths more clearly:

Do you really find this to be better? I don't mean to be contentious but this to me is highly obfuscated. Maybe it's just that I come from a different background. It just seems like terseness for terseness sake. This is the kind of thing that I am talking about.

I do get your point about the lack of side effects. But I would prefer to be able to pass in a method that accepts each line as it is identified. Honestly, I'm not even sure if that code creates a big list and returns it or if it's a evaluated later.

Martin Odersky

Posts: 84
Nickname: modersky
Registered: Sep, 2003

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 3:04 AM
Reply to this message Reply
> It would also help if Scala came up a little higher on a
> Google search for the word 'Scala'.

It comes in third at the moment, after Scala multimedia and the Theatro alla Scala. I think it's OK to let the Scala Opera house come before, after all it's been around much longer than the language ;-)

-- Martin

Martin Odersky

Posts: 84
Nickname: modersky
Registered: Sep, 2003

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 3:38 AM
Reply to this message Reply
Here's another solution to the challenge in Scala:
import scala.io.Source
val MAXLENGTH = 70
def process(filename: String) = 
  for {
    (line, lnum) <- Source.fromFile(filename).getLines.zipWithIndex
    if line.length - 1 > MAXLENGTH
  } println(filename+" line="+(lnum + 1)+"chars="+line.length)


This is both functional and easily readable. In fact, David Pollak's solution is almost the same but with the for expanded to applications of the functions map and filter. There's a standard translation in Scala from for loops to applications of these functions. I just applied it in reverse.

I think this shows several things:

1) It's possible to write really nice code in Scala.

2) But it takes some expertise to find the best solutions.

3) Scala's equivalences between low-level and high-level syntax help in finding better solutions.

BTW Scala is strictly speaking not a JVM language. There's also a version for .NET, but it is less well supported than the Java version.

Bill Pyne

Posts: 165
Nickname: billpyne
Registered: Jan, 2007

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 6:20 AM
Reply to this message Reply
> BTW Scala is strictly speaking not a JVM language. There's
> also a version for .NET, but it is less well supported
> than the Java version.

I didn't mean to imply otherwise. Being barely literate on the JVM and less so on the CLR, I wasn't even sure if Microsoft calls what runs on the CLR bytecode, so I didn't want to bring it up. Making Scala VM-agnostic is another choice that gives it a fighting chance. As James Watson said, copious examples (and a book) would be great - written in your free time of course - in getting Scala coding spread.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 6:46 AM
Reply to this message Reply
> As James Watson
> said, copious examples (and a book) would be great -
> written in your free time of course - in getting Scala
> coding spread.

There are some wikis out there with Java examples galore.

My personal thing is that I'm not comfortable with my understanding of the syntax at a very atomic level. I can't really love using a language if I don't have this understanding. But this is more of a personal thing and not something I think most developers care that much about. Perhaps the existing documentation explains this but I've not found it to be very accessible.

Martin Odersky

Posts: 84
Nickname: modersky
Registered: Sep, 2003

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 8:55 AM
Reply to this message Reply
There will be at least two books on Scala which should come out fairly soon. Hopefully they will help.

James Watson

Posts: 2024
Nickname: watson
Registered: Sep, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 9:24 AM
Reply to this message Reply
> There are some wikis out there with Java examples galore.

Scala examples, that is.

And you'll definitely sell at least one book to me, Martin.

Bill Venners

Posts: 2284
Nickname: bv
Registered: Jan, 2002

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 17, 2007 10:21 AM
Reply to this message Reply
I suspect the following Scala code would be easier to read for most Java programmers:

import scala.io.Source
 
val MaxLength = 70
for (filename <- args)
  for ((line, lnum) <- Source.fromFile(filename).getLines.zipWithIndex)
    if (line.length - 1 > MaxLength)
      println(filename + " line=" + (lnum + 1) + " chars=" + line.length)


Two nested for comprehensions are easy for the imperative mind to grok, and inside that a print statement that's executed only if the line length exceeds 70. I'm curious how taking the if outside the for comprehension might affect performance, but unless this section of code is critical to performance I would prefer this because I suspect it would be easier for most to read.

Eric Armstrong

Posts: 207
Nickname: cooltools
Registered: Apr, 2003

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 18, 2007 10:51 AM
Reply to this message Reply
I find myself increasingly impressed by the way in which "new languages" get created in Ruby--languages that make life easy, but which still give the full power of Ruby whenever you need it.

The best known Domain Specific Languages include Rails & Rake. I'm intrigued by Martin Fowler's construction of an XSLT-like language in Ruby. And I've recently found the optiflag option parser that is written DSL-style. I'm sure there are some others that I've forgotten to mention.

So not only is Ruby a great language in it's own right, it keeps evolving better and better tools. It's an ecosystem that keeps getting more powerful with time.

That said, I remain a big fan of readability, and there is a lot to be said for a language like Scala. (I look forward to future versions of Ruby that remove some of the write-only Perl-isms that found their way into the language.)

Peter O'Connor

Posts: 3
Nickname: peteroc
Registered: Mar, 2007

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Oct 19, 2007 10:18 AM
Reply to this message Reply
Nobody mentioned javascript.
Rhino makes it possible to call native java classes.
For me though scala is the one. Its got everything and it feels right. I'm currently prototyping the automation of tests of distributed services in scala. Using the Actors library makes the tests a lot cleaner. The reason I mention javascript though is that I may be forced to consider it for its simplicity and popularity. It may be that someone else will need to modify these tests in future. They probably would have a better chance of getting started quickly if its javascript, especially if they don't have much of a development background. A lot of the time these are the factors that determine the decision.

Jamie Lawson

Posts: 4
Nickname: jrlawson
Registered: Jul, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Nov 10, 2007 11:32 AM
Reply to this message Reply
1) Anyone attending the Scala session at JavaOne saw that all of Sun's big guns were there, as well as Google's big guns and the academics. Corporate support? My organization (160000 engineers small) is giving in-house training on Scala already.

2) It's dumb to compare languages on a trivial problem. Compare languages on a hard problem. Loose type systems will work on easy problems but they will kill you on hard problems.

3) Has anyone done performance tests on Jython or J/Ruby? It's really awful stuff.

Jamie Lawson

Posts: 4
Nickname: jrlawson
Registered: Jul, 2005

Re: Groovy, JRuby, or Scala: Which JVM Language to Learn Next? Posted: Nov 10, 2007 11:36 AM
Reply to this message Reply
Yes, the functional version is better!!! It is easier to verify. Moreover, the properties of the functional version are better than the properties of the imperative version.

Flat View: This topic has 45 replies on 4 pages [ « | 1  2  3  4 | » ]
Topic: JCP Election Ballots to Close Today Previous Topic   Next Topic Topic: Douglas Crockford on The State of Ajax

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use