InfoQ

InfoQ

News

My Bookmarks

Login or Register to enable bookmarks for unlimited time.

The content has been bookmarked!

There was an error bookmarking this content! Please retry.

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

Posted by Werner Schuster on Sep 30, 2009

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

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
GWT Scala anyone?! by Stefan Frank Posted
  1. Back to top

    Haxe

    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?!

    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

10 tips on how to prevent business value risk

One category of risk that project teams need to ensure they address is business value failure – delivering a product that fails to provide value for the business investor.

Interview: Software Systems Architecture: Working With Stakeholders Using Viewpoints and Perspectives

InfoQ spoke to the authors of Software Systems Architecture on a couple of new topics, the System Context viewpoint and Agile, which have been added to the second edition.

Beauty Is in the Eye of the Beholder

Alex Papadimoulis discusses ugly code, where it comes from, how to avoid it, and how to get rid of it.

Architecting Visa for Massive Scale and Continuous Innovation

John Davies examines Visa’s architecture and shows how enterprises have architected complex integrations incorporating Hadoop, memcached, Ruby on Rails, and others to deliver innovative solutions.

Max Protect: Scalability and Caching at ESPN.com

Sean Comerford unveils ESPN.com’s architecture, what components are used and why, and the current changes the website goes through.

The Seven Deadly Sins of Enterprise Agile Adoption

Are there repeated patterns of failure on Enterprise Agile Enablement efforts? Sanjiv and Arlen discuss Seven Deadly Sins to avoid when adopting Agile in an enterprise.

Questions for an Enterprise Architect

Erik Dörnenburg answers: What is Enterprise and Evolutionary Architecture?, discussing 4 issues: Turning strategy into execution, Ensuring conformance, Where do the architects sit? Buying or building?

Wrap Your SQL Head Around Riak MapReduce

Sean Cribbs explains what Map-Reduce and Riak are, why and how to use Map-Reduce with Riak, and how to convert SQL queries into their Map-Reduce equivalents.