Sunday, August 25, 2013

Play Framework 2.x - Taking the Plunge


So after many months of kicking and screaming against being forced into the new 2.x.x branch of the Play! Framework I finally decided to take a weekend and learn the damn thing and get it over with.





Pros

Much more powerful and feature packed than the 1.x branch
In addition to some serious code optimizations and refactorings, things like an interactive console, built in H2 in-memory database browser and a built-in LESS and CoffeeScript compiler are just a few of the bells and whistles added on that really add to the development experience.

The Scala templating language is not as scary as it sounds
...And that's coming from a Java developer. Yes, I really enjoyed using this templating system even though some things took a couple minutes to really sink in. Parameter groups? What's that?

The new ebean ORM 
Though I've only used it to complete the Zen Tasks tutorial, i'm seeing that it requires a lot less hand-holding in the JPA annotation department. Give it a @ManyToOne annotation in one class and you don't need to go to the related class and set up the mappings. It's something I haven't seen done anywhere else (except Rails, I think) and it's nice to see it available here in sweet ol' Java. 


Cons

Not as friendly, free form an "playful" as the 1.x branch. 
Doing the simplest of things requires a lot more typing, planning and thought now. Gone are the days when I could have just done this:

public static void updateUser(User user) {
 user.save();
 render();
}

Now I have to do:

public static void updateUser() {
 Form userForm = form(User.class).bindFromRequest();
 User u = userForm.get();
 u.save();
 ok(views.html.users.updateUser.html);
}

This approach provides certain advantages, but it really takes away from the appeal and fun I had with the 1.x approach.

Documentation is a bit lacking
I wish the documentation could have been organized better and be more detailed a la 1.x. Certain sections like Forms and Action Composition could use a little attention.

Searching for help turns into a hunt
Searching for help online usually returns 1.x or 2.x Scala results. This is not helpful to a 2.x Java developer.

Other Thoughts

I've been a big fan of the +Play Framework since I walked away from Rails over a year ago. I haven't looked back since. Part of what made me fall so madly in love with it was it's power without being verbose; elegant simplicity without the need for me to get embroiled in XML files and the like. I could have hardly believed it was Java I was using!

As of late though, it's become a bit heavier and less of a tool that I could use to knock out a prototype in no time flat. Don't get me wrong, it's still miles better than Spring or Struts (shudder), but it's just not as free form and delightful as it was when it was younger. I do understand, though, that some of its "agility" was sacrificed to introduce better optimized code and more powerful technologies, so I guess I'll just file this under the price of progress.


For those of you wondering why I took a weekend, this included getting comfortable with +IntelliJ IDEA and wrangling with the many technical issues that came up with the Scala and Play2 plugins. IntelliJ is a marvelous IDE and has proved me wrong in believing that Eclipse was the be all and end all of Java IDEs, but I think the Play 2 plugin could use some work. It won't, for example, let me reference a template via index.render(...), so I have to do views.html.index.render(...) or import views.html.index before I can call the render method. It's a minor issue, but majorly annoying when I'm trying to dance my way across the keyboard to project completion.

Conclusion

In closing I'd like to say that Play 2 is not the horrid, complex mess I thought it was. Sure it's a bit different and sure i'll have to wave goodbye to some of my old habits, but the framework has been made better and future proofed for tomorrows web application developers. I really appreciate all the hard work that +James Ward and the team at Typesafe have been doing. 

Here's hoping that Play 3.0 will be backwards compatible!




Post a Comment