
Play framework for Java - a radical rethink of Java web app development? - simonw
http://www.playframework.org/
======
simonw
I just ran through the tutorial and it was a real breath of fresh air -
everything ran out of the box, there was no need for an IDE or a build process
and changes were live the second I saved them from my editor (it apparently
ships with the on-the-fly compiler from Eclipse). Really impressed.

~~~
rapind
Agreed. I still think it's a little cumbersome compared to rails, but it's
definitely the best java web framework I've seen yet, and about as close to
rails as you can probably get with java. Groovy for the template language is a
good choice too.

The example app was very useful. Including some real world jquery ajax
functionality was a big bonus and a great way to compare functionality with
other frameworks. (render methods and routing specifically).

~~~
ConceptDog
Also agreed. Play is closer to what I was hoping Lift would end up being for
Scala.

But with Scala support coming in Play 1.1, I'm officially excited.

~~~
therockhead
Would you mind sharing some of your thoughts on lift? How does it compare to
other web frameworks that you have worked with?

------
kls
"The Play framework makes it easier to build Web applications with Java"

Maybe you should not be building web applications with Java or C# or <insert
language of choice>.

Maybe you should be building web services with these languages and using AJAX,
a client side toolkit, Javscript, HTML and CSS to build a UI that communicates
with said services.

Maybe this decouples your UI implementation from your business logic
implementation so you can go mobile, IVR, Mind Jacking, without having to
build the back end again.

Maybe server side templating was wrong and a CMS is your best choice for
static templating. Given that assembling templates during run-time as opposed
to build time seems to be a waste of resources. A CMS can deliver already
templated, flat HTML files, to the web server during build time. As well Ajax
is your best bet for delivering dynamic information.

It sure separates your concerns quite nicely, while allowing each developer to
work in their domain of expertise.

Just a thought.

~~~
greentree
The "way we've always done it" in my brain does not like the thought of
putting all the client stuff in, well, the client. I'd like to hear more about
this style of development. Do you have examples of this being done,
postmortems, blogs espousing this, more info, etc?

~~~
kls
<http://highscalability.com/amazon-architecture> Being a large company Amazon
is in different stages of a transition to this form of architecture, but for
the most part most all of the large companies are moving towards it IBM is
embracing it as a UI development philosophy. Google pioneered it, Yahoo is
well on it's way.

[http://blog.jeffhaynie.us/service-oriented-ui-
architecture-i...](http://blog.jeffhaynie.us/service-oriented-ui-architecture-
in-the-world-of-web-desktop-and-mobile-applications.html)

------
10ren
It reminds me of Sinatra. The HTTP paramater/object binding is similar, for
example: <http://www.playframework.org/documentation/1.0/5things>

A difference is that the routes, model, controller and template/renderer are
in separate directories. It's a bit awkward for the simple project of the one
in the video, but essential for more complicated projects.

It even includes a captcha generator, and their examples seem to be of real
(though very simple) applications - as opposed to toy academic ones. I get the
feeling that its developers are very familiar with the real needs and problems
of actual web development.

It almost makes me want to get into web development! The only thing is that
combining HTML, Groovy templating, Javascript and JQuery looks a little
complex - but they're probably very straightforward for common tasks.

------
FraaJad
The FAQ is an interesting read --
<http://www.playframework.org/documentation/1.0/faq>

------
falsestprophet
What is the virtue of developing a web application in Java instead of a
scripting language like Jython (aside from execution speed obviously)?

~~~
patio11
Well, at my day job, not having to throw out 10 years worth of legacy code
would be considered "a bit of a plus". We also have 1,200 employees and
precisely two engineers who have ever done a Rails application more
complicated than the 15-minute-blog demo. I think we have one guy who coded a
Python app once.

Our favorite contractors and outsourcing providers also have (comparatively
speaking) deep skills in Java and the related stacks. Some of them have
forgotten more than I ever want to know about, e.g., serializing Java beans.

~~~
martincmartin
If you pick as JVM language as suggested, why would you need to throw out any
code?

When I worked at ITA Software which writes much of their stuff in Lisp (not
the web stuff though), there was often worry that it meant new programmers
would have to learn the language and so wouldn't be productive at first. But
learning the code base takes a lot longer than learning the language, at least
enough of the language to get significant stuff done.

If you have 10 years worth of legacy code written by 12,000 employees, I
assume you're in the same boat.

------
robspychala
<http://m.mlb.com/> uses a hybrid Freemarker / Groovy / Java framework called
MVC+GF. During the 2009 season it was able to scale with out issues during
peak hours (9th innings, etc). That's hundreds of requests a sec a server -
pretty cool.

Groovy is used cause it has closures (java doesn't) and is simpler and easier
than Scala.

------
cschneid
Side question: is there a CPAN or Gems repository for similar open-source Java
libraries? I know that Apache has lots of Java libs, but beyond that, I have
no idea where to look.

~~~
fizx
Look into Maven.

~~~
cschneid
From what I understand, Maven is a build dependency manager, but not a package
manager the way CPAN is. I'm looking for a central place to find packages that
do everything. "ohh you need to interact with AWS, here's the package" type
stuff.

~~~
strlen
There's a bunch of maven repositories (usually googling '+"library name"
+"maven" +"pom.xml" works), but I haven't yet found anything like CPAN's
search website.

mvn:create can bring up an interface that's very smilar to CPAN's shell. What
needs to be done is a shell that allows functionality such as "search
/amazon/" or "search guice, jersey" or "info google-collections". Scala would
be a great choice to make sort of a "REPL" shell :-)

~~~
brianm
best way to find maven repo info for open source java stuff, that I know of,
is with <http://repository.sonatype.org/>

------
jrockway
Java has real lightweight threads, so what's the advantage of "shared nothing"
here? Extra memory usage and less speed?

~~~
mcav
It seems to refer to this:

> _"Play is designed to operate in a ‘share nothing’ architecture. The idea is
> to keep the application completely stateless. By doing this you will allow
> your application to run on as many server nodes as needed at the same time.

>What are the common traps you should avoid to keep the model stateless? Do
not store any object on the Java heap for multiple requests"_

If that's all they're talking about when they say "stateless", that's no
different than a lot of other "stateless" MVC frameworks like Pylons, Django,
Rails, etc.

~~~
modoc
I haven't done any real dev with those frameworks you list so I'm wondering
how do you manage session state? user profile, shopping cart, breadcrumbs,
multi-request flows, etc...

Do you write/read all that into the db/memcached for each request?

~~~
mcav
Yes. PHP does the same thing. Actually, _most_ frameworks do that; very few
keep state within the application server between requests. Statelessness, in
that respect, improves scalability.

~~~
modoc
PHP has session variables to put state objects into which are persisted
between requests. Right?

~~~
simonw
Yes, but most people who make serious use of them hook up a custom session
handler that writes session information out to the database (the default
implementation that ships with PHP uses the file system). Sessions that are
stored in memory by the application server instantly prevent you from load
balancing requests across multiple servers and hence kill your scalability -
unless you implement sticky sessions which adds yet more complexity.
Personally I try to avoid using session storage whenever possible - I've
recently started using signed cookies in their place.

~~~
modoc
Interesting. I mostly build J2EE apps and sticky sessions support is built in.
Complex apps require a fair bit of session state (user profile, shopping cart,
custom catalog, breadcrumbs, user promos, etc...) in general and the idea of
having to persist and reload that data over a network (db or memcached) for
each request would absolutely kill page response times. I guess it depends on
how heavy the session data is for your app.

~~~
simonw
I'm quite surprised - I've never even considered building a stateful web app
that doesn't talk to a database or caching layer at all for most requests.
It's fascinating to me how different the approaches taken in the Java world
are from the LAMP world I'm accustomed to.

~~~
modoc
From the Java world, that seems odd:) Scaling your DB and/or caching layer is
a lot harder than scaling sticky session based app instance with minimal db
interaction.

------
hariharan
Nice collection of web tools. Especially ready made libraries for validation,
captcha etc and a built-in template engine.

But I am not convinced with 'on the fly' compilation because most editors
already do a better job there and refreshing the web page to look for
compilation errors does not look productive.

~~~
guillaume
If you use a Java IDE you will of course see compilation errors before trying
the app in the browser. So it is not a problem.

------
mhd
Hmm, too much code in the template library, too much magic in general. I do
like the general packacking, the automatic compilation and the snazzy error
and testing interfaces. Seems a bit hard to change from their Groovy template
system to something like StringTemplate, though.

~~~
guillaume
Although I think that the built-in template system is very very nice, it would
be really easy to write a play module that provide any template engine you
want.

~~~
mhd
Well, both systems are basically diametrical opposites. StringTemplates is
very strong on MVC separation whereas the play templates feature a fully-
fledged programming language.

I'll have to dive deeper into play to see how much more I would have to do in
the Controller part to prepare the output for the template...

------
scotth
How does the following work? Must be a preprocessing step, if I'm not
mistaken.

With play, you can just write:

Article article = Article.findById(id); User user = User.getConnected();
render(article, user);

And retrieve objects from their Java local name in the template. That saves a
lot of useless lines of code...

~~~
guillaume
Yep there is one step of byte code enhancement, during the compilation phase.
But as the compilation phase itself it totally transparent, you can't call
that a 'preprocessing step'.

------
jeduan
Weird, I had just convinced my boss to use Spring Roo, because of the
productivity, and this seems to be more productive

------
thangalin
Mixing code and presentation is a bad idea.

------
martincmartin
How does it compare to Groovy and Grails?

------
beamso
I just watched the screencast. I'm sure that the static methods on the
controllers and the public attributes will drive purists up the wall, but the
speed of development appears excellent. Looks most definitely faster than
running glassfish in debug mode and reloading classes/redeploying all the
time.

------
maheskrishnan
just copied features from ASP.Net MVC...

~~~
regularfry
I can assure you that ASP.NET MVC has its share of copied features. And you
know what? That's a _good_ thing. Good ideas _should_ be copied and
propagated, and mixed in with whatever makes the next platform unique.

------
ilyak
"Provides integration with Hibernate" == "Would be a huge pain in the ass".

Otherwise, I'd still either pick JRuby on Rails or go ugly early with
idiomatic java.

------
c00p3r
Let me guess - it's yet another Java on Rails?

~~~
turtle4
Seems that way, although it was the most thorough that I've seen. What are
others?

Groovy runs on JVM, Wicket on Wings exists, I believe. What are other Java
options?

~~~
fortybillion
We've been using Grails (Groovy) at our startup with great success. A few
warts early on with regard to how Grails wants to handle packages and URLs,
but we push a lot of transactions through this system (sorry, I don't have
exact numbers) and Grails has held up remarkably well. It also cut our initial
development time by about half.

