views:

379

answers:

4

Hi!

I have a personal project - a web mashup which uses multiple REST-Apis and Webservices, which I would like to program using scala, mostly because I would like to use it as a pet project for learning this language. However, it is possible that the project grows and that other java programmers contribute to it. Furthermore, I would like to code some features using java, which I know better. Therefore, I was thinking of using a Java Framework which can play nice with multiple view technologies (the mashup involves basic image editing, therefore, it would include a Flex-Air client).

I was thinking of using Struts2 (mostly because it is widely used and it would look good on a resume) or eventually Spring / Seam.

Has anyone already tried this: Using a Java Framework with Scala and having both Java and Scala classes. Is it doable on a productive environment or should I just completely forget it and become proficient enough in Scala and use something like Lift?

Thanks you very much in advance!

A: 

In theory, any of the popular Java MVC frameworks will work with Scala, they'd have the same pros and cons as they would with Java. However, it's very common for these frameworks to embrace the JavaBean pattern, and that's a code smell in Scala. I haven't looked at Lift, but I would hope that it's a better fit for the functional nature of the language.

skaffman
+1  A: 

We are using several java frameworks in our production scala app: Restlet, Spring, Hibernate, Wicket, etc. with no major problems.

However, I would recommend using java for your hibernate entities because scala does not support nested annotations util 2.8. This causes a problem if you declare your named queries via annotations.

Also, if you need a java bean in scala, it is trivial to create as follows

@scala.reflect.BeanProperty
var firstName:String = _
agilefall
@BeanProperty may be trivial to use, but it means using var, and var is a smell, considering that the value will likely be injected once and never changed. If this isn't what val is for, I don't know what is.
skaffman
I agree that it is a smell, but when you are using java frameworks beans are often required.
agilefall
+8  A: 

Some Java frameworks are not presently (Scala 2.7.x) usable with Scala. Specifically, the ones that have nested annotations (annotations within annotations) are not supported. The present plan for Scala 2.8 includes support for that.

Also, frameworks which require static methods being passed to them can be impossible to use, as Scala does not have static methods, and no compatibility work-around for Java interoperability.

Note that this applies only to PURELY Scala projects. Both problems are often easily offset by just writing tiny Java wrappers for the contentious features.

Now, having said all that, I strongly recommend going with Lift. It is a powerful framework, the productivity with it is impressive, and it's safe by default -- which, unfortunately, cannot be said of many other frameworks.

As for Struts, I think it's one of the most awful web frameworks in existence. It does look good on résumé, though one can always hope that will cease to be the case. In my opinion, the sole value of Struts is that it's awfulness led many developers to get acquainted with other language, in search of reasonable and usable frameworks.

Daniel
+1  A: 

I've been using the standard JavaEE 5 (+JAX-RS) stack with Scala and find that many of the annoyances that web frameworks solve can be alleviated with Scala's features.

Not to say that there are not any challenges, but I did try a prototype of the project using Lift and found myself overwhelmed.

Lift uses a lot of functional features, as well as implicits which can be really cryptic for the average Java programmer.

So, my suggestion is to stick to standard (JavaEE) and learn how to harness Scala's syntax to be more productive in the Java environment. Then move on to a pure Scala stack if you need it.

Plus, you will be able to mix Java code easier this way.

efleming969