HomeBlog → A short intro to SGL

A short intro to SGL


Early in history of our company there was a need to use a programming language for controlling application and services logic.

That led to the creation of two scripting languages; first there was PASTE, a very simple programming language offering basic program control constructs and value types.

It was used for a few things before it was replaced with SGL (yes, we are big on acronyms and initialisms here at Phaistos) - a much more powerful language based on the PHP language syntax and semantics.

SGL was used to build the original BestPrice product (then called 'Pathfinder Shopping'). It was also used to control various other services and for 'gluing' together components and technologies(hence its full name, Switch Glue Langue - SGL).

When designing the new BestPrice service we realized we would gain a lot by re-writing SGL based on Javascript syntax and semantics, both in the development and operation of that service, but also for switching to a new language powerful enough to be used for controlling applications and services logic(which has been the case so far) but also for becoming the language our developers will be using for building products, replacing existing programming languages in the process.

Most of our developers are spending their majority of their time wrangling with Javascript - they have built frameworks (CORE) and great many services and products with it.

That familiarity, along with the power availed by Javascript semantics, made it easy to decide to build a Javascript based language (for all intents and purposes, SGL is an Javascript compiler and interpreter, with additional features baked into the language and runtime).

The 'new' SGL is a high performance, easy to extend and integrate with other components and services programming language.

We have migrated all existing services using the previous SGL incarnation to the new SGL and built many more utilizing it.

Furthermore, we plan to replace PHP - the scripting language we use for building web services on the backend - with SGL.

This would narrow down the number of different programming languages we use to 2 (Javascript(SGL) and C/C++ on the backend).

We do and will keep using other languages where it makes sense, of course (Bash scripts, Perl, Python, Java) - but for almost every service and application we will build its going to be Javascript.

A side benefit of that is that our frontend developers will need to master a single programming language(Javascript); new people joining the company will also be able to contribute in a fraction of time it would take otherwise, and will take a considerable less time and effort to guide them through the process.

SGL is x5 faster than PHP in our benchmarks, and at least as fast as V8 in most benchmarks.

Because we always improve our technologies stack, future updates and performance enhancements will propagate to all services and applications using SGL.

We prefer to use technologies and services we ourselves build and maintain; from programming languages, to data stores, to DNS servers, to application servers and load balancers, to various frameworks and libraries.

It takes time and effort we should, perhaps, have invested in building more products, but we are confident controlling and owning the technologies we use is providing us with significant advantages and makes it so much easier to build applications and services in a far shorter amount of time it would take otherwise

A real life example

Below is part of an SGL script demonstrating content grabbing (from NASA Picture of the day website).

Any Javascript programmer can easily read and understand the code snippet, which also features callback functionality, date/time handling and database connectivity.

var RUN_EVERY   = [810, 910, 1010, 1110];
var URL         = "http://apod.nasa.gov/apod/astropix.html";
var run         = false;
var rpc         = new RPC.Endpoint("");

var dtObj   = new Date();
var dt      = dtObj.asStringwithFormat("%H%M");
for (var i = 0; i < RUN_EVERY.length; i++) {
   var dt  = RUN_EVERY[i];
   var d   = parseInt(dtObj.asStringwithFormat("%H%M"));

   if (dt == d) {
       run = true;

if (!run)
console.log("Fetching " + URL);

tank.fetch(URL, function(resp) {
   var content = resp.content;
   var parser  = new Parser(content);

Your comment



captcha Refresh captcha