Opa, the cloud language – a test drive

Alastair Aitken 26 July 2011 6
Opa, the cloud language – a test drive


What is Opa?

Opa is both a new language and a web platform, which includes a web server, a database engine and a distributed execution engine.

Who produces Opa?

Opa is produced by MLstate, a Paris, France company founded in 2007.

Why Opa?

Opa aims to reduce complexity by rationalising the number of different systems required to create scalable and secure applications running in the public or private cloud. Opa applications have no dependencies, including everything from web server through to database.

A “Hello World” application in Opa

In the Javascript world of Node.js, the classic “Hello World” application is:
which when placed into a file example.js is run thus: % node example.js Server running at http://127.0.0.1:1337/ In Opa, “Hello World” is more terse:

which, when placed into a file example.opa is compiled thus:

% opa example.opa

and run (even on a Mac which doesn’t use .exe extensions by convention) thus:

% ./example.exe

You can also compile and run in one step with:

% ./example.exe --

Compiling the “Hello World” application on a Mac raised the following warnings:

ld: warning: directory '/opt/mlstate/lib/ocaml/site-lib/zip' following -L not found
ld: warning: directory '/opt/mlstate/lib/ocaml/site-lib/camlzip' following -L not found
ld: warning: directory '/opt/mlstate/lib/ocaml/site-lib/ssl' following -L not found
ld: warning: directory '/opt/mlstate/lib/ocaml/cryptokit' following -L not found
ld: warning: directory '/opt/mlstate/lib/ocaml/site-lib/cryptokit' following -L not found
ld: warning: directory '/opt/mlstate/lib/ocaml/site-lib/ulex' following -L not found
ld: warning: directory 'libsecurity' following -L not found
ld: warning: directory 'appruntime' following -L not found
ld: warning: directory 'libbase' following -L not found

This didn’t appear to affect compilation; upon inspecting the directory there was a 37MB file with the extension ‘.exe’. The large size of the file reflects the fact that an Opa executable contains everything: web server, database and all the plumbing.

Starting the application took a few seconds then yielded:

Accesses logged to access.log
Messages logged to error.log
Opa-server (OPA/218) serving on http://localhost:8080

Navigating to http://localhost:8080 revealed “Hello World” in all its glory. Look at the resulting page’s source code showed that as well as the HTML page, a 356Kb Javascript file was delivered which presumably is included in case any additional front-end functionality had been developed.

Further with “Hello World”

Opa is a statically typed functional language (although the compiler will infer types if not explicitly declared) and included the data type XHTML. This data type is designed to make creation, storage and transformation of HTML easier. So our “Hello World” application could look like this instead:

The first line is a function declaration, the chevrons on the right-hand side denoting the XHTML data type. Adding a function with a bit of interpolation in our example gives:

Styling “Hello World”

Resources, such as stylesheets, can be embedded into an Opa application. For this we create a subdirectory ‘resources’ and create ‘main.css’ with the following:

and then amend the last line of our “Hello World” application to embed the stylesheet:

The Opa chat room example

Chat rooms example code is rapidly becoming the “Hello World” of the real-time web and the official Opa ‘book’ starts off with such an example. With the copious commenting removed, the code is reduced to an impressively spartan handful of lines:

Summary

To ease the pain for beginners, the examples could start a bit simpler. There appears to be a few typos in code examples, which is frustrating when starting on an unknown language, but generally the documentation is comprehensive. Errors thrown by the compiler, whilst attempting to be helpful, were just a little confusing too.

Can Opa reach a point where it’s considered mainstream? The barrier to entry is huge, Opa requires learning a completely new language; a similar whole-stack system such as Wakanda uses Javascript, which eases adoption – Javascript developers and documentation are relatively easy to find. Also trust must be placed in the entire stack – at the moment it’s difficult to ascertain the efficacy of the entire stack without subjecting it to real-world development and load testing.

Deployment is probably the biggest pain-point for web development, regardless of platform. Given that most development will never require any degree of fine-tuning (and accepting Donald Knuth’s suggestion that “premature optimization is the root of all evil”) then relying upon an essentially closed stack that doesn’t allow switching out components may prove to be an acceptable trade-off for pain-free deployment.

Notes

The build reviewed was OPA 1.0 s3.5 Build 218 for MacOS 10.6.8


Alastair Aitken (114 Posts)

As a contract developer and manager I’ve worked in a wide range of enterprises in a variety of countries where I’ve encountered everything from great work, awful work, bizarre work, all the way down to quasi-legal work. If you think that you recognise your own organisation within my articles then you’re undoubtedly wrong, where you work isn’t that unique.


6 Comments »

  1. Adam Koprowski 27 July 2011 at 8:03 pm - Reply

    Thank you for your interest in Opa! At MLstate we are very passionate about the technology that we build, so if there is anything we can do to help you get more familiar with Opa please let us know and we will be delighted to help :).

    • Anonymous 28 July 2011 at 8:34 am - Reply

      It would be an unusual move to abandon the knowledge of an entire stack: a DBMS might be swapped out but the application server would remain. Microsoft’s .NET framework required a change of language, web server and application server and yet it took several years before more conservative enterprises considered it to be production-ready. It’s the fear of the unknown that is probably the biggest obstacle to change; it’d be great to see some case studies of organisations making that change to Opa, highlighting both the benefits and potential pain-points of a transition.

    • ceed 28 July 2011 at 11:30 am - Reply

      maybe a 32bits version of opa =)

      • Jahlin 3 September 2012 at 8:38 pm - Reply

        Thanks for being on point and on taergt!

  2. Adam Koprowski 27 July 2011 at 8:06 pm - Reply

    Oh and one more thing: that’s true that the entry barrier is substantial. You say: “Opa requires learning a completely new language” — true enough. But at least this new language gives you all-in-one, as opposed to learning a new server-side language, database query language, client-side language and web framework all one by one.

  3. Burcu 3 September 2012 at 1:11 pm - Reply

    Wonderful site and theme, would really like to see a bit more connett though!Great post all around, added your XML feed! Love this theme, too!

Leave A Response »