5 ways to Play! poorly
That said, Play! isn’t idiot-proof. Here is a list of 5 mistakes to avoid in your Play! projects.
1) Using Modules too liberally
Play modules are great, but they can lead you to develop your projects as if you were still in the same Java world you’d always been in. For example, when developing a REST api in Play, I started by installing the RestEasy Module It seemed like a no-brainer – an easy way to implement JAX-RS services. However, after a bit of development, it became clear that one can obtain all the RESTful goodness by simply using Play routes There is no reason to deal with increased build times, increased deployment size.
If you need the functionality of a specific module, by all means, include it. However, spend the extra 5 minutes to see whether the functionality you need is provided in core Play first.
2) Not considering the Scala/Java decision closely enough
This is most relevant if you are working in Play! 1.x. If you are in Play 2.0, its easy – use scala, please. However, it can be appealing to use Java for play 1.x projects. However, I tend to think that it is a bad idea. The Play! development team is clearly moving towards Scala as the primary language, and it seems like a good idea to start with Scala in your 1.2 projects now. It should make the 1.2 to 2.0 upgrade that much easier when you are ready. I expect to have another entry for my readers in a few weeks with some tips on the 1.2 upgrade process.
3) Building a War
Any Java developer knows this cycle. Build an application, package it into a war, deploy the war to an application server. Play allows you to use this familiar cycle, and they support lots of popular app servers. That said, think carefully before you go this route. The play server and play run commands bring up a standalone server using Netty. It is fast, simple, and perhaps most importantly, ensures that you are running your application in the same method for both development and production.
4) Fail to worry about Template Performance
Play is fast. The JVM is a very optimized platform, and play takes advantage of that. However, play has its Achilles heel – Groovy Template rendering. I know it, you know it, the play dev team knows it. Luckily, there are a lot of easy ways to fix this problem is performance is a concern in your app.
- Try one of the many alternate templating engines. FasterGt, Japid or Rythm all provide much better speed.
- Try Play! 2.0. The template system has been moved to Scala, which shouldn’t have any of the performance issues.
- Go Client-Side. Play! makes a great REST server, and if you combine it with a client-side MVC framework like jmvc or backbone, you can avoid the overhead of server-side template compilation.
5) Using Getters & Setters
There you have it, 5 Play! framework anti-patterns. Please comment if you have any anti-patterns of your own to share.