Matt RaibleMatt Raible is a Web Developer and Java Champion. Connect with him on LinkedIn.

The Angular Mini-Book The Angular Mini-Book is a guide to getting started with Angular. You'll learn how to develop a bare-bones application, test it, and deploy it. Then you'll move on to adding Bootstrap, Angular Material, continuous integration, and authentication.

Spring Boot is a popular framework for building REST APIs. You'll learn how to integrate Angular with Spring Boot and use security best practices like HTTPS and a content security policy.

For book updates, follow @angular_book on Twitter.

The JHipster Mini-Book The JHipster Mini-Book is a guide to getting started with hip technologies today: Angular, Bootstrap, and Spring Boot. All of these frameworks are wrapped up in an easy-to-use project called JHipster.

This book shows you how to build an app with JHipster, and guides you through the plethora of tools, techniques and options you can use. Furthermore, it explains the UI and API building blocks so you understand the underpinnings of your great application.

For book updates, follow @jhipster-book on Twitter.

10+ YEARS


Over 10 years ago, I wrote my first blog post. Since then, I've authored books, had kids, traveled the world, found Trish and blogged about it all.

Play 2.0, A web framework for a new era

This week, I'm in Antwerp, Belgium for the annual Devoxx conference. After traveling 21 hours door-to-door yesterday, I woke up and came to the conference to attend some talks on Play and PhoneGap. I just got out of the session on Play 2.0, which was presented by Sadek Drobi and Guillaume Bort. Below are my notes from this presentation.

The Play 2.0 beta is out! You can read more about this release on the mailing list. This beta includes native support for both Scala and Java, meaning you can use both in the same project. The release also bundles Akka and SBT by default.

In other news, Play 2.0 is now part of the Typesafe Stack. Typesafe is the Scala company, started by the founder of Scala (Martin Odersky) and the founder of Akka (Jonas Bonér). Guillaume is also joining the Typesafe Advisory Board.

Sadek and Guillaume both work at zenexity, where Play is the secret weapon for the web applications they've built for the last decade. Play was born in the real world. They kept listening to the market to see what they should add to the project. At some point, they realized they couldn't keep adding to the old model and they needed to create something new.

The web has evolved from static pages to dynamic pages (ASP, PHP). From there, we moved to structured web applications with frameworks and MVC. Then the web moved to Ajax and long-polling to more real-time, live features. And this changes everything.

Now we need to adapt our tools. We need to handle tremendous flows of data. Need to improve expressiveness for concurrent code. We need to pick the appropriate datastore for the problem (not only SQL). We need to integrate with rapidly-evolving client side technologies like JavaScript, CoffeeScript, and Dart. We need to use elastic deployment that allows scaling up and scaling down.

zenexity wanted to integrated all of these modern web needs into Play 2.0. But they also wanted to keep Play approachable. They wanted to maintain fast turnaround so you can change your code and hit reload to see the changes. They wanted to keep it as a full stack framework with support for JSON, XML, Web Services, Jobs, etc. And they wanted to continue to use and conventions over configuration.

At this point, Guillaume did a Play 2.0 Beta demo, show us how it uses SBT and has a console so everything so it runs really fast. You can have both Scala and Java files in the same project. Play 2.0 templates are based on Scala, but you don't need to know Scala to use them. You might have to learn how to write a for loop in Scala, but it's just a subset of Scala for templates and views. SBT is used for the build system, but you don't have to learn or know SBT. All the old play commands still work, they're just powered by a different system.

After the demo, Sadek took over and started discussing the key features of Play 2.0.

To handle tremendous amounts of data, you need to do chunking of data and be able to process a stream of data, not just wait until it's finished. Java's InputStream is outdated and too low level. Its read() method reads the next byte of data from the input and this method can block until input data is available.

To solve this, Play includes a reactive programming feature, which they borrowed from Haskell. It uses Iteratee/Enumerator IO and leverages inversion of control (not like dependency injection, but more like not micro-managing). The feature allows you to have control when you need it so you don't have to wait for the input stream to complete. The Enumerator is the component that sends data and the Iteratee is the component that receives data. The Iteratee does incremental processing and can tell the Enumerator when it's done. The Iteratee can also send back a continuation, where it tells the Enumerator it wants more data and how to give it. With this paradigm, you can do a lot of cool stuff without consuming resources and blocking data flow.

Akka is an actor system that is a great model for doing concurrent code. An Actor could be both an Enumerator and an Iteratee. This vastly improves the expressiveness for concurrent code. For example, here's how you'd use Akka in Play:

def search(keyword: String) = Action {
  AsyncResult {
    // do something with result
  }
}

Play does not try to abstract data access because datastores are different now. You don't want to think of everything as objects if you're using something like MongoDB or navigating a Social Graph. Play 2.0 will provide some default modules for the different datastores, but they also expect a lot of contributed modules. Anorm will be the default SQL implementation for Play Scala and Ebean will be the default ORM implementation for Play Java. The reason they've moved away from Hibernate is because they needed something that was more stateless.

On the client side, there's so many technologies (LESS, CoffeeScript, DART, Backbone.js, jQuery, SASS), they didn't want to bundle any because they move too fast. Instead, there's plugins you can add that help you leverage these technologies. There's a lot of richness you can take advantage of on the client side and you need to have the tools for that.

Lastly, there's a new type of deployment: container-less deployment to the cloud. Akka allows you to distribute your jobs across many servers and Heroku is an implementation of elastic deployment that has built-in support for Play.

They've explained what they tried to design and the results of this new, clean architecture have been suprising. Side effects include: type-safety everywhere for rock-solid applications. There's an awesome performance boost from Scala. There's easier integration with existing projects via SBT. And it only takes 10 lines of code to develop an HTTP Server that responds to web requests.

The memory consumption is amazing: only 2MB of heap is used when a Play 2.0 app is started. Tests on Guillaume's laptop have shown that it can handle up to 40,000 requests per second, without any optimization of the JVM. Not only that, but after the requests subside, garbage collection cleans up everything and reduces the memory consumption back to 2MB.

At this point, Guillaume did another demo, showing how everything is type-safe in 2.0, including the routes file. If you mistype (or comment one out) any routes, the compiler will find it and notify you. Play 2.0 also contains a compiled assets feature. This allows you to use Google's Closure Compiler, CoffeeScript and LESS. If you put your LESS files in app/assets/stylesheets, compilation errors will show up in your browser. If you put JavaScript files in app/assets/javascripts, the Closure compiler will be used and compilation errors will show up in your browser.

Play 2.0 ships with 3 different sample applications, all implemented in both Java and Scala. HelloWorld is more than just text in a browser, it includes a form that shows how validation works. Another app is computer-database. When Guillaume started it, we saw how evolutions were used to create the database schema from the browser. The Play Team has done their best to make the development process a browser-based experience rather than having to look in your console. The computer-database is a nice example of how to do CRUD and leverages Twitter's Bootstrap for its look and feel.

The last sample application is zentasks. It uses Ajax and implements security so you can see how to create a login form. It uses LESS for CSS and CoffeeScript and contains features like in-place editing. If you'd like to see any of these applications in action, you can stop by the Typesafe booth this week at Devoxx.

Unfortunately, there will be no migrating path for Play 1.x applications. The API seems very similar, but there are subtle changes that make this difficult. The biggest thing is how templating has changed from Groovy to Scala. To migrate from 1.2.x would be mostly a copy/paste, modify process. There are folks working on getting Groovy templates working in 2.0. The good news is zenexity has hundreds of 1.x applications in production, so 1.x will likely be maintained for many years.

Summary
This was a great talk on what's new in Play 2.0. I especially like the native support for LESS and CoffeeScript and the emphasis on trying to keep developers using two tools: their editor and the browser. The sample apps look great, but the documentation look sparse. I doubt I'll get a chance to migrate my Play 1.2.3 app to 2.0 this month, but I hope to try migrating sometime before the end of the year.

Posted in Java at Nov 16 2011, 05:58:09 AM MST 11 Comments
Comments:

I have been waiting for Play 2.0, thanks for the heads up :)

Posted by Marius S on November 16, 2011 at 08:35 AM MST #

@Matt Thanks for the write-up!

At this time, do you think that Play 2.0 should be a serious consideration for a team creating a new web app in Scala or Java? What are the drawbacks in Play 2.0 compared to other leading choices?

Posted by Jay Barker on November 16, 2011 at 08:57 AM MST #

Thank you for writing this! Wish I could have attended the play! talks at devoxx. Looks like 2012 might be a fun year :)

Posted by Andreas on November 16, 2011 at 09:06 AM MST #

Very nice report! This sounds like dream stuff. ;-)

Posted by Jon K on November 16, 2011 at 09:06 AM MST #

I'm a *huge* fan of CS and Less. I don't know how we created website before these technologies were available. The 'native' support of CS/Less can be done easily with an Eclipse builder. Every time I save a file, it gets 'compiled' and I can see errors *before* I do a context switch to reload things in my browser. I don't know if I need my web app framework to do all this for me. Here is my writeup on how to set this up:

http://stackoverflow.com/questions/6645640/integrating-coffeescript-with-eclipse/7507987

I worry about the speed and cpu load of Scala. Sure, it compiles down to the JVM byte codes, but that doesn't mean it is fast. Groovy is dog slow, so at least they've switched from that. I'm also not a huge fan of the syntax of Scala. Seems like more of a fad language to me. I'm waiting for Ceylon, mostly because I know Gavin really knows his shit and will do a great job with it.

I've been using a relatively unknown template engine for my latest project called Cambridge Templates (stupid name, I know). This is one of the most brilliantly simple engines I've ever used and it is very fast. I integrated it with the Jexl expression language (it is in trunk now) and that has been more than adequate. Most of the time, I'm working in CoffeeScript on the client side anyway. The author is very responsive to fixing bugs and adding requested features.

http://code.google.com/p/cambridge/

Posted by Jon Stevens on November 16, 2011 at 11:36 AM MST #

@Jon: No need to worry. Scala basically emits the same bytecode Java would emit for the same task. Most comparisons show that both languages have the same performance, sometimes Java is a few percents faster, sometimes Scala.

You think Scala is a fad language although it has regular releases, an active community, commercial support, a huge team of people working on the language, a standard library, dozens of books, IDE support, documentation and a huge eco-system around it? Interesting, considering that Ceylon has to this day nothing of the above.

Posted by Steve on November 16, 2011 at 12:49 PM MST #

To add to Steve's comment, Scala is designed by Martin Odersky--the guy who wrote javac and laid the groundwork for generics in Java. It's also used by several of the most popular web applications: Twitter, LinkedIn, and FourSquare among others.

But surely Gavin King can do better. He created Hibernate after all, and everyone uses that. Well, everyone except Play 2.0 apparently.

Posted by Zachary Kuhn on November 16, 2011 at 01:15 PM MST #

@Jon Go look at the Hibernate source code when Gavin was the only committer (< 3.x) and see if you are so sure he's the right guy to bring us all the next language.

I also don't like the Scala syntax that much. Mainly because its cutesy attempts at compacting the amount of written code is a nerdy step backwards: readability trumps all value-wise in a codebase, and there are tools to help the poor little programmer's fingers.

Posted by Rob on November 17, 2011 at 10:37 AM MST #

At this moment is Play 2.0 production ready?

Posted by numan on November 21, 2011 at 10:45 AM MST #

For those of you 'loving' Scala... please read:

http://blog.joda.org/2011/11/scala-feels-like-ejb-2-and-other.html

Posted by Jon Stevens on November 25, 2011 at 10:45 AM MST #

Thanks for the interesting link Jon. I think Play 2 does a good job of hiding Scala's complexity, but it can still be a very confusing language.

@numan - Play 2.0 is development ready, but not quite production ready.

Posted by Matt Raible on November 29, 2011 at 04:04 PM MST #

Post a Comment:
  • HTML Syntax: Allowed