Play 2.0+Java vs. Play 2.0+Scala? - java

I am thinking about migrating to play 2.0 after play 1.2. One thing that bothers me is that people say Scala is more "preferred" for a play 2.0 application. I know the differences over 1.2 and 2.0, but I'm unsure if there are differences between Play 2.0 with Java and Play 2.0 with Scala
So there are questions in my mind:
Is there anything that I cannot do with java over scala in a Play
2.0 application?
What advantages do I have if I start to learn and use scala in a
play 2.0 application?

I just finished a prototype using Play 2.0 with Java and now am considering to learn Scala just so I can switch to it for further development.
It's not just the usual Java vs. Scala discussion - the problem as I see it with the Play framework is that it forces Scala idioms onto Java. An example from the documentation about calling multiple web services:
public static Result feedComments(String feedUrl) {
return async(
WS.url(feedUrl).get().flatMap(
new Function<WS.Response, Promise<Result>>() {
public Promise<Result> apply(WS.Response response) {
return WS.url(response.asJson().findPath("commentsUrl").get().map(
new Function<WS.Response, Result>() {
public Result apply(WS.Response response) {
return ok("Number of comments: " + response.asJson().findPath("count"));
}
}
);
}
}
)
);
}
It works but doesn't look like conventional Java. Those parentheses look really scary. Even Eclipse gets confused and never knows what generics I need or want to use - I always have to choose them manually.
Also note that in the documentation they made this look pretty by removing #Override annotations, using just two spaces for indentation and overall choosing a very simple example without validation or error recovery so they don't use too many lines. I'm not even sure you could configure a code formatter to output it like this without messing up other code completely.
In practice I ended up with an unreadable block of a horrible Java-Scala-abomination just for getting some data from another service.
Unfortunately I can't find any example of combining responses in Scala. At least calling single web services in Scala looks much shorter and easier to read.

AFAIK, it is better to go with Scala, because it offers more functionnality.
For instance (correct me if I'm wrong), you can directly using the Iteratees with Scala (aka reactive programming), but I don't know how to achieve that with Java.
Also, the Java API of Play is an upper layer in the Play architecture, the core is written with Scala; so if you want to lean what's happening inside, go with Scala.
And also note that you can mix Java and Scala in the same Play project, so you can move smoothly to Scala.

I was new to Play and just wrote a small-mid sized Project with the Java side of it.
It works and is powerful, but a lot of Features just seem to be very Scala centric and the Java support is sub-par.
The Java API Doc is virtually non existent, which takes away some comfort in the IDE (IntelliJ - I recommend it).
The integration in the Java world is not very "natural" (SBT..), It does not build as a war or maven module (but there seem to be plugins to do this). You kind of loose the benefits of the existing Java tooling.
The concepts which differentiate Play from the other Frameworks almost all seem to be scala native and Java second.
I stumbled onto some bugs and quirks and I always would end up in Scala code I had to read and understand to fix or work around it. (Actions, RequestBody stuff, Async, routes, template implicits and so on)
So the Java side of things just feels very second tier to me, although they are clearly making an effort for them to be equally good.
Now, after the Project, I would say it is very usable and would even use it again (in Java).

What advantages do I have if I start to learn and use scala in a play
2.0 application?
As djangofan commented, when you google for Play help, you get examples in Scala.
Is there anything that I cannot do with java over scala in a Play 2.0
application?
However, I haven't yet (still a beginner) found an equivalent of Ebean for Scala. The Scala examples I've found all use direct SQL for persistence. Where's the database abastraction?
Since I haven't found a database abstraction for Play with Scala, I'm continuing with Java...

Related

Lift framework with java

I'm building a web application that needs high performance. I intended using Java EE but after researching about it, there are many negative comments about Java EE applications.
I'm thinking about the Lift framework, but it seems that Lift only support Scala, and I only know Java. Does Lift actually support Java? (I can't find any project example that uses Lift with java). I downloaded a Lift framework project application and there is a boot file in it, can we create a same boot file but for Java?
I'm pretty sure Lift is Scala only. If you're looking for high performance and Java then you should check out the Play Framework as it also has the benefit of not requiring a Servlet container to be deployed.
The Lift framework is Scala only. I want to note that in my experience the transition from Java to Scala was not that hard and now that I know it, there are many language features that make development easier and faster for me. You can take a look at this guide for transitioning between languages: http://www.scala-lang.org/node/960 to see if it might be something that might be right for you. From experience, I really enjoy using the Lift framework as it offers a lot of performance and functionality. The documentation is a bit lacking, but the community is great and makes up for that if you get stuck.
As for Java EE having negative comments, that is a bit vague. The Java EE spec includes everything from Servlets to JSF and EJB. Parts of the spec you will find in almost any web framework (including Lift) and others are more specialized. JSF for example has a lot of overhead, but tries to simplify a lot of the typical application lifecycle. EJB similarly tries to simplify the persistence layer through object relationship management (ORM).
High performance sites can be accomplished with most frameworks, but a lot of it will come down how you develop it. Also, because the framework supports it does not mean you need to use a particular component. Spring (http://www.springsource.org/) is a framework that many people have used on high performance sites, and is incredibly configurable (Supports EJB and JSF, but you don't need to use it). Also, Wicket (http://wicket.apache.org/) is a Java framework that offers a similar feel to Lift that might be interesting to you.
I worked with Lift only for a year now, and was never really interested if it would run from java (I wanted to learn new effective conceptions anyway).
So, I don't fully know the subject. But what I know for sure is that Liftweb has java methods almost everywhere to support java, too. So, you can build your app if not fully in java, then most part of it.
Prooflinks are like these:
http://main.scala-tools.org/mvnsites/liftweb-2.4-M4/net/liftweb/actor/LiftActorJ.html
Classes that add support for java by adding java-acceptable method names and such. These classes usually have a "J" letter at the end.
Anyway, I'd suggest to try out Scala, too -- it's great. And even if you use java only -- you probably will get used to Scala anyway, because you probably would want to read the source code sometimes.

How can you use groovy inside Play! Framework, outside of templates?

The FAQ states
Is play a Groovy framework?
No. Even if we use Groovy as the base technology for the Play
templating system, it’s totally transparent. Also, you can’t write
directly any other part of the application (such as controllers,
models or other utilities) in Groovy. If you’re looking for a Groovy
based framework you should have a look at Grails.
While I get that it's not supported out of the box, I do believe/hope the integration is possible ... I mean, Java is Turing Complete after all :)
So, has anyone experimented in writing Groovy code, and calling that code from Play! Controllers? What's the best way to achieve that?
Bonus points: If the solution worked seamlessly with IntelliJ, that would be heaven.
As said in the documentation, Play is not a Groovy framework. Is is plain java and I am not aware of any initiative of using Groovy in Play.
Plus, bonus point, Play2 has completly removed Groovy even in templates to be replaced by Scala. So I think that even if a solution exists it might not be maintained in the future.

Is there an OpenRasta like REST framework for Java?

The circumstances force me to start writing a java based server and I am looking for a REST framework for Java. I really like the way OpenRasta works - a REST framework for .NET, so my question - does anyone know a REST framework for Java which works similarly to OpenRasta?
Thanks.
EDIT
Unfortunately, I am not in a position to be an early adaptor, so well established frameworks have preference over emerging ones.
You want to use one of the implementations of the JAX-RS specification, one of the main ones being Jersey. The specification and it's implementations have been around for a long time and are tried and tested (as opposed to Play! which you don't seem to like due to it being a newer framework).
I used OpenRasta and then worked on Java projects using JAX-RS. It will feel very familiar and you will get the benefits of POJOs like you get from OpenRasta's use of POCOs. I feel it's a great choice for creating RESTful services. In fact, I would probably chose it over OpenRasta now but this is more due the benefits of working within a Unix environment than the frameworks themselves.
The play framework is a popular new choice for Scala and the JVM:
http://www.playframework.org/documentation/1.2/routes
One option is Play!, which is basically framework based off Ruby on Rails.
Second option you might be interested in is Lift, which also has really cool features like comet, AJAXy snippets, etc. But it is a little bit different than Play!.
As part of this project, I would recommend Restlet which is the first and most comprehensive REST framework for Java. It works on both client and server side and is indeed resource centric, not just a MVC framework adapted to REST.

Open source projects with Java and Scala interaction

I'm going to give a talk about using Java and Scala together and I want to investigate some projects (large and small) which contains Java and Scala code.
If you know links to correspondent projects post them here.
This page on the Scala wiki is a good starting point...
The various scala testing frameworks come to mind. They all have some integration with JUnit or TestNG
Gimd is one example of small project: http://code.google.com/p/gimd/
Although development stalled for a while because I'm busy with other duties it already contains some examples of Scala<->Java integration. Notably:
unit tests are written using junit
Gimd is using JGit (library in Java) as underlying layer
While working on Gimd I found that using Java from Scala is mostly easy and seamless the contrary is not always true. It's not really a fault of Scala as it's simple manifestation that Java is a less expressive language.
Unfortunately I don't know any open source project but I have worked on very large projects over the last few years that have java and scala interacting and my experience has been mostly very positive. If I had one piece of advice it would be to use scala-javautils. It's a life saver and is far better than the scala jcl code. Before we started using it trying to get some interactions involving collections was heart-breaking. However I'm led to believe 2.8 will solve this.
In general I find the interactions between scala and java very close to using one language.

Playframework and Django

I have worked with Django before and have recently seen the Play framework.
Is this the Java community's answer to Django? Any experiences with it? Any performance comparisons with other Java web frameworks?
Edit:Almost similar to this question, the responses, unfortunately don't say much about the framework.
Play! is a breath of fresh air into Java and bypasses all the Enterprise cruft that has evolved over the years. Even the namespace is just play not com.playframework. It is supposed to be an answer to Rails, Django etc and is MVC based. It is needed for Java to stay relevant in all but deep entrenched enterprise shops.
Play! reduces the overabstraction and painful configuration of old Java. It is a complete stack it does not rely or play to the old Servlet/EJB methodology like Restlet tried to do (making REST easier in Servlets). Play! is a great REST based Java framework that is a valid contender to other platforms MVC frameworks.
It is very RESTful and it is easy to bind a parameter to a java method. They have also made JPA much easier to use through their play namespace.
play.db.jpa.Model
public void messages(int page) {
User connectedUser = User.find("byEmail", connected());
List<Message> messages = Message.find(
"user = ? and read = false order by date desc",
connectedUser
).from(page * 10).fetch(10);
render(connectedUser, messages);
}
Python is used for scripting instead of builds with Maven which might save a few lives.
I haven't been this excited about a Java framework since Red5 or Restlet. A bonus is they have easy ways to get your app up on Google AppEngine as well using the Java version of GAE.
I have been using Play! now for a few months and in fact have come to love the framework. I struggled with Rails and Django a bit, mostly because I am really not a fan of dynamically-typed languages; however, there was never a really good web development framework for Java to compete with these. In terms of productivity, Rails and Django were the leaders for the MVC arms race that was going on. Play! is awesome, it's concise, scalable, powerful, and it has a great community that is growing all the time. If you're still really into using a language like a Python or Ruby, you can use Play! with Scala too. I am really trying to get into Scala right now because I think it has a great future and it's a lot of fun to use. Anyway, I would recommend giving it a try!
The Play! framework is a really good piece of software, and that the JavaEE bloated environment should be inspired from.
I moved from Java -> Django because of the fast cycle "modify file" / "reload browser", and the Play! framework makes me came back to my favorite Java language.
It could also be compared in some terms to what Grails and in general dynamic languages in Java (Groovy is used in Play!) are trying to import: simplicity, speed and reliability.
I am also a Django user. I've just visited the Play framework and skim thorugh its documentation. It has the simplistic design Django has been known of. It even has app engine support built-in. I'm sure many java developers will support it, and it only need some time to see cool plugins from the community.
We recently started using Play for building a webservice for various mobile applications. I come from a Java environment. I can tell you that the learning curve isn't all that steep--literally in an hour I had the webservice running with basic API already. One week later we were on Amazon Web Services. I definitely see a future for Play as it simplifies web development for Java developers.
Couple of things that I noticed however (asset versioning, etc.) still are not built into the framework, but i'm sure they'll be there in time. I would say it is definitely worth a shot using Play.
I come from a very strong java background. So my answer here could be a little biased.
Play finally brings to the java community what django has been for all these years in the python community, but just a way better.
Play is built on the jvm therefore inheritance all the goodies from a solid platform that has been proving over the years to be the most reliable and scalable one that allows to write and run applications at scale.
I want to say that I did try django. Its popularity among the web community made me curios and I wanted to give it a try.
Strangely I did not find it as easy to use as I had expected.
So many configurations. Too may libraries doing the same thing and often not play very well with each other. A way too much magic.
Furthermore, not having type safety makes very hard to manage and maintain
web application at big scale.
Don't get me wrong, I am pretty sure that people managed to do it, but in my experience I still find java/scala best suited for this, especially when you share the code base with a lot of other developers.
IDE support for Java it is unbeatable. If you implement TDD you will find yourself refactoring code and moving things around on the daily basis. And java IDEs give you all this power. With type safety and more.
My take away is that as long as you find yourself writing a simple CRUD application/prototype/toy without even thinking too much of advanced features and big scale then you can probably find some advantages on using python/django. Otherwise the whole java ecosystem wins hands down. And play is the cherry on top.

Categories