InfoQ

News

Javascript as Compiler Target: Clamato, GWT Smalltalk, Python, Scheme

Posted by Werner Schuster on Sep 30, 2009

Community
Architecture,
Ruby
Topics
Javascript ,
Rich Client / Desktop ,
Runtimes
Tags
Android ,
Scheme ,
SmallTalk ,
Python ,
Seaside ,
PhoneGap

Despite Javascript's ubiquity, it's a hard language to like. Until the advent of VMs like Google's V8, Apple/WebKit's Nitro/SquirrelFish Extreme and Firefox' TraceMonkey, Javascript's performance was abysmal.
Incompatible implementations across browser make development painful as well. Libraries like jQuery and many others offer convenient abstractions and allow to program to one API and even out the incompatibilities.

Another approach to solving the problems is to hide Javascript completely and use it as a compilation target. Google's GWT is a mature example that takes Java code, written to a subset of the Java API, and compiles it into browser specific Javascript. One example of a real world application of GWT is the Google Wave client. Recently, a few more language implementations have joined the trend.

Avi Bryant, creator of the Smalltalk Seaside web framework, has created Clamato, a Smalltalk dialect that compiles to idiomatic Javascript. Avi described the design principles of Clamato in the InfoQ interview with him taped at FutureRuby.

The tutorial page for Clamato allows to open a Clamato (Smalltalk) class browser in the web browser and inspect and edit the Clamato source code. To look for classes, use the text field in the left upper corner of the browser. Interesting bits are the selfhosting PEG-based Clamato parser (enter "PP" in the textfield to see the classes for the parser and the various combinators).
A certain Seaside influence is visible in the Seaside-style HTML builder (the HTMLCanvas class in the Clamato browser). Visual components can use it to build their GUIs, for instance, the counter component from the tutorial:

 
renderOn: html
  html h3 with: @counter.
  html button
    with: '+';
    onClick: [@counter := @counter + 1. self reload].
  html button
    with: '-';
    onClick: [@counter := @counter - 1. self reload].

The renderOn: html line defines a new method and the rest of the sample is the method body, which builds the HTML with a header and two buttons, which are set up with event handlers.

As it happens, another browser-based Smalltalk has appeared recently: GWT Smalltalk. The creator Peter Fisk has previously created the .NET and alternatively ActionScript-based Vista Smalltalk.  GWTSmalltalk is written using GWT which generates Javascript that runs in the browser.
GWT Smalltalk is in an early stage right now but progresses quickly. It has support for using XMPP, which puts it in a good place to interact with with Google Wave (XMPP is an essential part of Google Wave). More details are available in the Industry Misinterpretations podcast interview with Peter Fisk and on the GWT Smalltalk blog.

Stepping outside the Smalltalk sphere, Python also has its Javascript compiler in pyjamas:

pyjamas is a stand-alone python to javascript compiler, an AJAX framework / library and a Widget set API

The best place to start is the online pyjamas book.

Another language that compiles to Javascript is Moby Scheme. What makes Moby-Scheme stand out is the way it's targeting mobile devices, for the moment Android, by compiling to Javascript instead. This is possible because of PhoneGap and because Android ships an efficient Javascript VM with its WebKit based browser. PhoneGap is a library that allows Javascript to access native device functionality, such as accelerometers, GPS, cameras, as well as other features such as address books. The creators of PhoneGap built it to bridge all the disparate smartphone devices which have very different programming environments, yet share one thing: WebKit and fast Javascript VMs. By giving Javascript access to device features, cross platform apps are possible for smartphones. See InfoQ's interview with the PhoneGap creators for a thorough overview of PhoneGap.

Haxe by Sam Corder Posted Oct 5, 2009 3:36 PM
GWT Scala anyone?! by Stefan Frank Posted Oct 7, 2009 12:54 AM
  1. Back to top

    Haxe

    Oct 5, 2009 3:36 PM by Sam Corder

    haxe.org/ Haxe also has had Javascript as a compilation target for a few years. It is a nice looking language but has sadly remained on the fringe for a long while.

  2. Back to top

    GWT Scala anyone?!

    Oct 7, 2009 12:54 AM by Stefan Frank

    GWT Smalltalk looks promising: I really like the idea of using a language other than java to write GWT-Apps. Alas, Smalltalk wouldn't have been the first language to come to mind: A Scala-Version would be nice and would maybe reduce much of the bloat that currently comes with using Java for setting up widgets...

    And aside: cappuccino.org/ certainly belongs in this list: It uses ObjectiveJ, which is a variant of ObjectiveC. It takes some time to get used to it, but the language is a rather good fit for gui-work and it also comes with a complete framework to build browser-based apps. They built 280 Slides with it, on of the best looking browser-based app around...

Educational Content

Brian Marick on 4 Challenges and 5 Guiding Values of Agile Software Development

Brian Marick takes us through a quick tour of the most important values and challenges to adopting Agile successfully (they aren't the typical challenges and values we hear in the community).

Are You a Software Architect?

The line between development and architecture is tricky. Does it exist at all? Is an ivory tower actually needed? There's a balance in the middle, but how do you move from developer to architect?

Agile – A Way of Life and Pragmatic Use of Authority

The word 'authority' sometimes produces an allergic response in hard-line agilists. Freedom and authority – both are bad if misused and both are good if used in right spirit for a noble cause.

Getting Started with Grails, Second Edition

"Getting Started with Grails" brings you up to speed on this modern web framework. Companies as varied as LinkedIn, Wired, and Taco Bell are all using Grails. Are you ready to get started as well?

Using ITIL V3 as a Foundation for SOA Governance

Those familiar with only ITIL V2 often scoff at the thought that ITIL could serve as a governance framework for SOA. With ITIL V3, the focus of the framework shifted towards service-orientation.

Adrian Colyer on AspectJ, tc Server and dm Server

SpringSource CTO Adrian Colyer discusses AspectJ, SpringSource's dm Server and tc Server products, OSGi and Scrum.

Adam Wiggins on Heroku

Heroku's Adam Wiggins talks about Rails, Background Jobs, Add-Ons, Ruby, and how Heroku manages to work around Ruby's inefficiencies using Erlang and other languages.

SOA as an Architectural Pattern: Best Practices in Software Architecture

For Grady Booch the foundation of a good architecture is patterns, SOA being just one of many patterns. In this Second Life presentation, Booch attempts to bring more clarity on what architecture is.