aspose file tools*
The moose likes Scala and the fly likes library handiness compared to groovy? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Languages » Scala
Bookmark "library handiness compared to groovy?" Watch "library handiness compared to groovy?" New topic
Author

library handiness compared to groovy?

John Broglio
Greenhorn

Joined: Nov 03, 2003
Posts: 3
One thing I like about Groovy is the ease of accessing library calls. Examples from Groovy:
1. database. I can dynamically load the mysql jar, connect, and pose a query in 3 lines
2. http. I can make and process an http/https POST in a few lines (with the http-builder library)
3. mail. I can send mail in 2 lines (using AntBuilder and javamail)

In these and similar cases, how does Scala compare? I know I can drop through to Java libraries with both Groovy and Scala, but if I have to insert verbose Java-style library invocation repeatedly, that would pretty much defeat the purpose of having a succinct language.

Thanks,
John
Venkat Subramaniam
Author
Ranch Hand

Joined: Jan 28, 2008
Posts: 79
Hi John,

Groovy is a wonderful language (I love it, I use it, I've written a book on it). Groovy is concise, however,
I will not chose Groovy just because it is concise. For me, it's metaprogramming capability is very important.
So, there is more than one reason to chose a language. Conciseness is one, but it may not be the only or even
the most important one.

Similar to Groovy, you enjoy conciseness in Scala as well. You can, within a few lines of code, make
a http request and pattern match the result (Scala's pattern matching and extractors are pretty awesome).
XML is a first class citizen in Scala. This makes the code concise. Scala shares a number of features with Groovy
when it comes to conciseness. However, just like I love Groovy for more than conciseness, I love Scala for
more than conciseness as well.

To mention a few, Scala is much more strongly typed than Java and, at the same time, it has low ceremony. This is
very useful to express interface contracts without redundantly specifying types. Scala has powerful actor based model
for concurrency. This makes it easier to write correct concurrent code, and the code is concise as well.
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Venkat Subramaniam wrote:Groovy is a wonderful language (I love it, I use it, I've written a book on it). Groovy is concise, however, I will not chose Groovy just because it is concise. For me, it's metaprogramming capability is very important. So, there is more than one reason to chose a language. Conciseness is one, but it may not be the only or even the most important one.

Similar to Groovy, you enjoy conciseness in Scala as well. You can, within a few lines of code, make a http request and pattern match the result (Scala's pattern matching and extractors are pretty awesome). XML is a first class citizen in Scala. This makes the code concise. Scala shares a number of features with Groovy when it comes to conciseness. However, just like I love Groovy for more than conciseness, I love Scala for more than conciseness as well.

Venkat,
You mentioned metaprogramming in Groovy, but not in Scala. I though Scala supported it too. Am I wrong on that?


SCJP, SCJD, SCEA 5 "Any sufficiently analyzed magic is indistinguishable from science!" Agatha Heterodyne (Girl Genius)
Venkat Subramaniam
Author
Ranch Hand

Joined: Jan 28, 2008
Posts: 79
Burk, Scala currently does not offer metaprogramming
capabilities like in Groovy. You can realize
some limited capabilities using traits.
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Traits? Are they a form of mixin?
Venkat Subramaniam
Author
Ranch Hand

Joined: Jan 28, 2008
Posts: 79
Scala traits let you mixin behavior at compile time unlike Ruby/Groovy Mixins which give you the ability to mixin at runtime.
Burk Hufnagel
Ranch Hand

Joined: Oct 01, 2001
Posts: 814
    
    3
Interesting, I'll have to do some reading... Would you happen to know a good book that might explain it?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Out of curiousity, can anyone explain in short how traits solve or avoid the problems you can get from multiple inheritance? Obviously they are more powerful than Java interface but despite this fact they don't suffer from the same problems as multiple inheritance in C++. Is this correct? Maybe some information on this? Thanks!

Marco
Venkat Subramaniam
Author
Ranch Hand

Joined: Jan 28, 2008
Posts: 79
Marco, in short you ask, so here is it in short

Object chaining.

Now for a bit more explanation. There was nothing wrong with multiple inheritance (MI). What was
wrong was how MI was implemented in some earlier languages.

The methods you implement in traits go into small objects. Depending on how you mix the traits in,
these get chained to form an instance of your class. Rather than posing an issue of method collision,
it resolves it in the way of method chaining their calls through these internal object chains.
I discuss this further in the book and show how things like decorator pattern are trivial to implement
using traits in Scala.
Ivano Pagano
Ranch Hand

Joined: Dec 16, 2006
Posts: 47

Venkat Subramaniam wrote:Marco, in short you ask, so here is it in short

Object chaining.

...

I discuss this further in the book and show how things like decorator pattern are trivial to implement
using traits in Scala.


This sounds quite interesting, could you share a simple example, if possible in a context like this short topic, of a simple decorator implementation?
Marco Ehrentreich
best scout
Bartender

Joined: Mar 07, 2007
Posts: 1278

Hi Venkat,

thanks a lot for the "short" explanation! This helped me to find some more information on this topic in the internet. Anyway, you already convinced me to check out your book and read up on all the interesting things you summarized here in these posts! I promise

Marco
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: library handiness compared to groovy?
 
Similar Threads
Learning two languages this year
How to generate XML from MAP
Question on the Groovy book
Groovy / Scala / Java interest levels from Wikipedia page views
groovy vs scala