Play 2 vs. Grails 2 Smackdown
ubertracks.com
ubertracks.com
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.
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.
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
I know many people don't like it , but I invested a fair amount of time into understanding hibernate and if I stick with the JVM I would want to be able to apply that.
For example: I remember in play 1.x various helper method were provided that were different from those in standard JPA including something that felt like properties in ruby. Not really a problem in practice, but required a litte trial and error when compared with the hibernate docs. However I imagine Play 2 makes use of various dynamic style programming techniques (via Scala) that might make hibernate behave in subtly different ways to what the hibernate literature might lead you to believe?
I appreciate that this is an extremely hand-wavey question.
Ebean looks interesting but it seems me that there is very small community, some documentation are from year 2009(it seems me litle bit old).
- 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).
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.
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.
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.
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.
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.
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.
Also, you are not restricted to hibernate since the GORM stuff has been refactored and now supports new hotnesses like MongoDB and Redis - https://github.com/SpringSource/grails-data-mapping
I absolutely won't use Hibernate for any new projects. I don't understand why anyone is using Hibernate. Here is a write-up of my experiences with it:
Also you can switch to JPA and use any JPA provider
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.
If I wanted to learn something for personal interest I would probably want to do Scheme,Haskell or Go.
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
(tl;dr Spring MVC first, then Grails, then Play)
Option Adoption Ready Importance Votes
Spring MVC 85% 82% 851
Play 71% 78% 735
Grails 77% 76% 711I'm personally going to try Play next actually, mostly due to Scala being typed