
Play 2 vs. Grails 2 Smackdown - eranation
http://www.ubertracks.com/preso/#/
======
mark242
Since June, when the presentation was created, Play has gone through a few big
revisions. The primary method of accessing a database is Anorm (which, if you
aren't a Hibernate fan, Anorm is a huge win) although you can also use
Hibernate, or you also have the choice of using Slick, which is Typesafe's ORM
(and a lot easier to use). IntelliJ 12 has better support for Play as well,
and the overall performance has improved a great amount.

It's too bad that the presentation doesn't include sample Scala code for Play;
imho this is the number one reason to use Play. The saveRating() controller
method that they use as Play's example, which is some twenty lines of Java
code, could be done in one or two lines of Scala code. Similarly, running a
job in Play is essentially just spinning up an Akka actor and scheduling
messages to send to it-- very very straightforward.

Play has been extremely easy to work with, especially with writing Scala code,
and it's much more lightweight compared to, say, the Lift framework.

~~~
mbell
Has play stopped using Ebean? It's my favorite Java ORM and I've never heard
of Anorm.

~~~
mark242
Play uses Ebean on the Java side of the fence. Anorm is for Scala users.
Here's how to do a query for a person in Anorm:

SQL("select * from person where id = {id}").on("id" -> myAgeVariable).map(row
=> MyPersonObject(row[String]("name"), row[Int]("age"))).toList

...returns you a list of MyPersonObjects. No need for JPA bindings or any
other annotations. Based on type safety, you must have the method
MyPersonObject.apply(name: String, age: Int) or else the compiler will error.
It's a great way of catching SQL funkiness inside your IDE.

~~~
alexatkeplar
Yech, embedding raw SQL strings in a typesafe, compiled language like Scala is
so full of fail it's not funny. Hopefully they'll switch out Anorm for Slick
(which is also a Typesafe project - <http://slick.typesafe.com/>) soon.

~~~
codewright
Ebean vs. Anorm vs. Slick is a good example of why I don't like using full-
stack frameworks.

When I use minimalist web frameworks, I get to use best-of-class libraries
across the board, not make decisions based on damage control.

Examples of minimalist web frameworks: Sinatra, Flask, Scalatra,
Ring/Compojure

~~~
alexatkeplar
Yep, I do like the Ring/Compojure philosophy. Actually we just open-sourced a
pixel server based on Ring/Compojure yesterday
([https://github.com/snowplow/snowplow/tree/master/2-collector...](https://github.com/snowplow/snowplow/tree/master/2-collectors/clojure-
collector))

------
rockyj
I don't know why JRuby + Rails gets no love. JRuby is similar to Groovy but
the Rails ecosystem is far far better than Grails. I have worked on all three
frameworks and I think -

\- The Rails ORM (ActiveRecord) is far more superior and mature than ANORM or
anything out there \- The Rails templating system is super easy and feature
rich \- Rails has awesome libs like Devise (Authentication), Cucumber (BDD)
and Capybara (UI Testing) \- The argument that Ruby is slow is not really
valid with JRuby + Torquebox. Yes, it cannot match Java but for most apps it
is sufficiently fast.

All in all, I have been trying to find a better combination than Rails + JRuby
but I cannot find any. If pushed against a wall I would only say that for
large projects some sort of type safety helps which Scala can provide but
prepare for some pain while development (when compared to JRuby + Rails
ecosystem).

~~~
eeperson
I'm really surprised that you would consider ActiveRecord more mature and
superior to anything else. I've always considered it the weakest part of
Rails. It doesn't include support for foreign keys (you can ad it with a 3rd
party plugin but I was really surprised that it wasn't included) and it gives
you no control over which fields are lazy loaded. Am I missing something? Why
do you consider it superior to everything else?

~~~
rockyj
About foreign keys - [http://guides.rubyonrails.org/migrations.html#active-
record-...](http://guides.rubyonrails.org/migrations.html#active-record-and-
referential-integrity)

About Lazy Loading at field level it is not really needed in most scenarios.
You can do it with your own code if you wanted it that way.

Edge case scenarios may be handled differently in most ORMs however with
Active Record I never felt the need to write SQL ever. Also for simple checks
I use the Rails console to see data whereas with other ORMs I had to open a
SQL console.

------
babs474
Grails is decent in my experience but I have two major gripes after working on
a large Grails project

1\. code reloading (ie change code, see results) doesn't work reliably and
server restarts are slow

2\. The ORM is still based on hibernate.

Is it just me or does anyone else have an incredibly difficult time with
hibernate? I've wasted many stressful days debugging weird flush exceptions.
I've never had trouble with ActiveRecord. I think it boils down to the concept
of a "session" in hibernate, which is essentially a giant global variable
begging you to touch it or look at it wrong, whereupon it will plot its
revenge by deciding which obscure exception to throw at flush time.

~~~
mbell
Hibernate is useful in one situation: you have a transaction that has to exist
across actions taken by multiple disparate services, and you still need the
container to manage this for you.

In my opinion, if your in that situation, you either have an application that
is an edge case, or you've architected your application poorly.

My rule of thumb:

If it has the word 'enterprise' anywhere in it's name or description. Avoid it
like the plague, only use it if its the last available option.

~~~
babs474
Couldn't agree more about the enterprise sentiment. That is why I like things
like Grails, that try and drag the enterprise java world, kicking and
screaming into the modern era of ruby on rails style mvc and such.

I think Grails mostly succeeds at this modernization, but I have to give fair
warning that there are still some enterprisey bits (Spring, which isn't so bad
and Hibernate, which will bite you) down in the guts.

edit: Forgot to mention that Groovy is a fantastic, under-appreciated language
with some neat features that should get more attention. Groovy is a major
selling point for using Grails.

~~~
mbell
I love groovy. Anytime I have something 'Java-JVM' that isn't performance
critical, I write it in groovy. But even that mindset is falling away given
the ability to use @CompileStatic.

The best part of groovy to me is that I can use it where I want, when I want,
with a single POM dependency and without (generally) having to think about how
it interacts with existing Java code.

When I write a Jersey controller, I start in java, if I hit a point where I'm
thinking "this would be easier with a closure" or "defining an entire inner
class here is stupid", I stop, change the file ending from .java to .groovy,
and code away.

~~~
vorg
> Anytime I have something 'Java-JVM' that isn't performance critical, I write
> it in groovy. But even that mindset is falling away given the ability to use
> @CompileStatic.

The @CompileStatic-based static compilation in Groovy only began being written
1 year ago (in October 2011), and was only mature enough to be included in a
production-ready version of Grails (version 2.2) a few weeks ago (December
2012).

Scala has had static compilation from the very beginning, and was rewritten
between Scala 1.x and Scala 2.x.

Stick to dynamic typing if you're using Groovy, even stuff that isn't
performance critical.

------
jiggy2011
I started using Play! when it was at about v1.0 because it was a simple light
framework and an easier alternative to grails or spring.

I'm not going to use it for any new projects though. Play 2.0 is a whole
different thing which seems targetted at Scala mainly (which I don't have time
to learn) , and is not very backwards compatible with play 1.x at all.

~~~
eranation
In my opinion it's worth the time spent learning, I think Scala is much less
complex than its reputation and doesn't take much time to learn the basics,
and once I did, I didn't want to go back to Java which seems to me now much
more complex and cumbersome than Scala. It's really starting to become my
favorite general purpose language.

~~~
jiggy2011
I'm sure it's a decent language. It's that I have only so much learning time
available and Ruby/JRuby , JS and ObjC seem like they would be a more
practical use of it.

If I wanted to learn something for personal interest I would probably want to
do Scheme,Haskell or Go.

~~~
ndeverge
I don't know if Scala is a good programing language, but it makes me a better
programer.

------
jlward4th
In case anyone wants to check out the live demos of the apps that Matt Raible
and I built for this presentation check out the Grails app:
<http://bike.ubertracks.com/>

And the Play app: <http://hike.ubertracks.com/>

The code is at: <https://github.com/jamesward/happytrails>

Both apps are a bit dated at 7 months old because Grails and Play have been
progressing pretty quickly. With Play 2.1 on the horizon it's probably time
for a refresh. And as someone pointed out, I've need to do a Scala + MongoDB +
Single Page App version. Just haven't had the time. But in case anyone is
interested, someone did create a Spring MVC version of the app:
<https://github.com/brentlemons/runhappy>

~~~
mgkimsal
I'm seeing the code for the presentation, but not the grails and play code -
is that in github anywhere?

~~~
aruld
Check out branches in that GIT repo.
<https://github.com/jamesward/happytrails/branches>

~~~
mgkimsal
Thanks!

------
eranation
A relevant recent JVM framework poll: <http://www.infoq.com/research/jvm-web-
frameworks>

(tl;dr Spring MVC first, then Grails, then Play)

~~~
jlward4th
Depends on how you read the numbers, so here are the results for those 3:

    
    
      Option     	Adoption Ready	Importance	Votes
      Spring MVC	85%	        82%	        851
      Play	        71%	        78%	        735
      Grails        77%	        76%	        711

~~~
eranation
Yep, thanks for the comment (And thanks for the great presentation!)

I'm personally going to try Play next actually, mostly due to Scala being
typed

------
mgkimsal
Partial to Grails - would liked to have seen the 'demo data' approach in
Grails call an external service method instead of inline in the bootstrap
process. It's the default way that's shown, but doesn't allow for too much
growth. It's one of those 'default' things that you see everyone doing because
it's what's promoted, but it's not really a great practice - having a separate
service method that can rebuild initial or sample data (which can also be
invoked from other locations, not just the bootstrap) would be preferable. Or,
perhaps better, use one of the 'sample data' plugins which provide DSLs for
that sort of thing.

------
moondowner
Sorry, but I'd go with Spring MVC (with Thymeleaf) + Spring Data JPA :)

~~~
jaytaylor
Why are you sorry? Different frameworks have different strengths (and
weaknesses!). When in doubt, going with what you are most comfortable with is
frequently a good bet.

------
bstar77
It's unfortunate that the benchmarks are hidden behind links. I'm not sure
most people checking this presentation out will notice that.

~~~
jlward4th
What do you mean be that? The results are certainly in the presentation.

~~~
bstar77
For me to see the graphs I had to click links to reveal them. Usually
presentation slides do not have interactive elements.

~~~
audreyt
It's a 2-dimensional presentation; one can use the up- and down-arrow keys for
subsection navigation instead of clicking links.

~~~
bstar77
I understand that, I'm just pointing out that its not obvious.

------
zoowar
I enjoyed the mechanics of traversing this slide show with my mouse wheel.

~~~
supersaiyan
I didn't realize that the site could scroll and just closed it, until I saw
your comment

~~~
eranation
Note it also scrolls down, I nearly missed half of the presentation at first,
look for a green down arrow

~~~
Cbasedlifeform
I have to confess I found this the most confusing navigation interface ever. I
quit after a half dozen slides. Was there a "home" option somewhere I stupidly
missed?

~~~
jebblue
Agree, cool presentation but I'd missed the down navigation until read these
comments.

