Using Scala in GWT projects
By andre
I’ve been experimenting with GWT (Google Web Toolkit) recently. GWT allows you to write responsive and consistent user web interfaces in a subset of Java programming language. The source code is then compiled into JavaScript, which can be run in any supported web browser.
This concept looks very attractive to me. While I’ve done a fair amount of web development, including JavaScript, in my earlier days, including writing some Ajax even before it was known as Ajax, I grew disappointed with scripting languages in general and JavaScript in particular because of lack of strict typing and browser differences. GWT abstracts these things away nicely and improves speed of development, maintainability and readability of the code. It is quite surprising to discover that GWT is open source, so even if Google goes bust, it will not disappear. As an example of GWT’s power consider the fact, that GMail’s interface is written in it, as well as Google Reader and a number of other Google web products.
While GWT is purely client-side library and server side can be implemented in any programming language, it makes sense to use Java for server-side as well. There are a lot of tool, frameworks and libraries for web development in Java, and the fact that client side and server side are in the same language allows certain amount of code sharing, with restrictions, of course.
I have also discovered an interesting new software development language - Scala. It is a functional/OO language, geared towards Java developers, i.e. offering interoperability with Java and offering somewhat familiar syntax and, most important, compiling into Java bytecode (a .NET port is in development as well). This is great news, since using specific features of Scala helps solving some of the common problems of web development, without requiring to switch to another platform completely. One can see, that JVM is finally catching up with CLI/.NET in the actual availability of multiple development languages (some languages targeting JVM have existed for years, but none of them before Scala have acquired any considerable following).
I was very eager to try out Scala doing GWT development. I was, however, saddened to discover, that Scala can be practically only used for server-side, since GWT compiler (Java to JavaScript) does not targets Java bytecode, as I initially thought, but rather source Java. Therefore a special compiler Scala->JavaScript must be written before such development is possible.
Guys behind this project seem to take a different approach - they are trying to compile Scala into a variant of Java, utilizing then existing GWT toolchain to generate JavaScript. I am happy with any approach, as long as it yields practical and working results. It would be great to see Google adopting the technology and devoting some resources to it.