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