Wednesday, October 5, 2011

JavaOne 2011: The Not Java That's Not Scala: Alternatives for Java EE Development

The cleverness of the title of JavaOne 2011 presentation "The Not Java That's Not Scala: Alternatives for Java EE Development" (25182) captured my attention and it was futile to resist the urge to see what the presenter (Justin Lee of Oracle) with that title would talk about in 60 minutes. With that in mind, I returned to the Parc 55 Embarcadero, a conference room in which I've already seen a couple of sessions in this year and several in last year. The session appears to be relatively well-attended though thankfully it is far from standing-room only.

Justin Lee is a GlassFish and Grizzly team member and works with websockets. He is a Basement Coder and has been using Java since 1996. He said that he has used several other languages such as Python, but he has not gotten the chance to use many languages other than Java because Oracle is committed to Java. He also stated that he likes Scala, but wants to avoid the community getting into a mono language focus on Java or even only Java and Scala.

Lee's slide "Why Not Java?" listed some of the frequently stated objections to Java such as "15+ years old," "verbosity," "it's not cool!," and "it doesn't have my favorite feature!" Lee said that there are some things Java will never do and used the example of functional programming. He pointed out that even with lambdas, "Java will never be a functional language."

The slide "Why Not Scala?" listed some commonly cited reasons for not using Scala. He quoted James Gosling, "Academics are driving the bus." He also cited inaccessibility of advanced features to "Average Joes" and "esoteric features." His last bullet of the slide is "rampant feature abuse." I thought Lee made a good point about this last bullet. He pointed out that although it's true that developers can choose to only use the more understandable portions of the Scala language, the problem is that they may be left trying to read and maintain code with some of the more difficult portions that fellow developers put in place.

Lee's "So What's Missing?" slide listed closures, syntax cleanups, succinctness, generics, and concurrency. Although Java has some of most of these, it can stand some improvement in most of them. A second slide with the same title listed functional programming, mutability, null handling, extendability, and modularity. ?Of course, JDK 8 with Project Lambda and Project Jigsaw will address some of these.

Lee said "suggest" may be too strong of a word for his recommendation of the languages Fantom and Gosu because these languages have their "own baggage." Although the abstract says Mirah would be covered, Lee opted not to cover it in the presentation because that language's creator (Charles Nutter) is giving a focused presentation on that language at this conference.


Fantom (formerly "Fan") has several advantages including having familiar syntax, being functional, employing static and dynamic typing, having "modern" concurrency features, and being portable (can build JavaScript or SWT). Fantom's portability is enabled by compiling to Fcode that can be converted to JVM bytecode or to .NET CLR (partial) bytecode or to JavaScript.

Lee showed some Fantom syntax. He explained that Fantom does not have arrays, but the List syntax makes them appear to be arrays for ease of use. Literal maps, lists, URIs, types, and "slots" were presented. Lee had slides comparing a Java version of a Person class to a Fantom version of the Person class. This example showed that all constructors in Fantom are named "make" and the "new" keyword precedes the "make" declaration. An ampersand precedes an identifier to represent it as an attribute rather than a method. This example also showed that Fantom methods support default method parameters.

Another slide showed "inheritance and mixins" syntax in Fantom. This slide showed that "initial assignments" use a (Pascal-style) colon preceding the equals sign (:=) while reassignments use simply the equals sign without the preceding colon.

Lee showed examples of Fantom closures, which incidentally use implicit "it" handle in a similar manner to that Groovy closures use. Lee believes that Fantom does not support closure currying.

Fantom stores nullability within the language's format. It never stores null in a "normal" variable, but placing a question mark (?) after a variable name means that it "might store null." Fantom also builds immutability into the language itself. I have long missed Java not having a true const keyword that actually does something and Fantom does add that. Lee's slide showed using const on a class declaration and on local variable declarations. I definitely am feeling a bit of "const envy."

Fantom concurrency uses actors similarly to how Scala and Erlang approach concurrency.

Fantom provides standard libraries and Lee showed using these libraries to easily retrieve a web page's content over HTTP, using date literals (which looks surprisingly simple especially when compared to Java's awful Date/Calendar mess), and calculating an HTTP Basic authentication string.

Lee discussed Fantom's approach to modularity and meta-programming. He described Fantom Pods as something like JARs but with additional metadata.

Fantom supports DSL development and allows embedding of other languages within Fantom code. This approach is somewhat similar to using CDATA in XML and makes it easier to plug in other languages and regular expressions without cluttering readability with special escape characters. Fantom can use Java libraries as documented in Using a Java Library from Fantom.

Fantom has Facets, whose syntax and usage appear to be similar to Java's annotations (Fantom also supports Java annotations via Java FFI). Lee showed use of @Js to demarcate a class as a JavaScript class with all JavaScript code within Fantom.

Fantom's Draft is a "mini web framework" that is a "bit like Node.js."

Lee concluded the portion of the presentation on Fantom with a list of references. These references include Tales Framework, Spectre Framework, and the main Fantom page.


Gosu (Reference Guide) has familiar syntax, closures (Blocks), and generics. Gosu also provides Groovy-like object equality with == and instance equality with === and Groovy-like null safety operator (?.). In keeping with Gosu's Groovy-likeness, Lee talked about Gosu having properties so that get/set methods do not need to be explicitly called.

Gosu constructors are all named "construct" just as Fantom's constructors are all named "make." Lee also showed that Gosu variable declaration has the variable name first and then the type inferred. Also like Fantom (and C++ and many other languages, but not Java), Gosu supports default method parameters.

Lee included a slide on Gosu's use of delegate. This is a convenient way to "wrap" or "delegate to" an existing class. Lee also showed a slide with less verbose code needed (than Java) to manipulate Strings and Files. I again could not help but think of Groovy's GDK String and File extensions.

Gosu creators state that Gosu's Donkey Patching is something like Ruby's Monkey Patching. Because these are statically invoked extensions, they cannot be used with inheritance or other areas where static methods are not supported.

Lee stated that the part of Gosu he likes best is its XML marshalling and handling. This was impressive in its simplicity, but I again could not help but think that Groovy does pretty well with XML as well.

Gosu includes Ronin, which Lee describes as a JSP-like web built-in web framework. He stated that Gosu has been around for a while and probably uses that JSP-style syntax because of the timing of its creation.

The Comparing Gosu to Other JVM Languages table is an interesting reference for comparing Gosu to a small subset of JVM languages including Groovy, Scala, Clojure, JRuby, Jython, and Java). I also found Notable Differences Between Gosu and Java to be enlightening. Lee's Gosu references slide listed the main Gosu page, the Ant-based Aardvark build tool, and the JVM Language Summit 2011 presentation on Gosu.

Conclusion This was a great presentation and I believe that Lee covered the basics of Fantom and Gosu that I'd like to know for a first review. This is what I'm looking for when attending a presentation on a topic I know very little about: an overview and enough basic information to know if it's worth further investigation and research. In my case, I still don't see a compelling reason for me to leave Java+Groovy or Java+Scala or some other combination of these languages to use these new languages. However, I am happy that I attended and I can see how in certain situations these languages are advantageous. In particular, deployment to JVM, CLR, and JavaScript from Fantom might be useful to certain people in certain situations. I always enjoy learning a little about different programming languages and this presentation did just that for two languages.