gmosx

RingoJS vs NodeJS

by gmosx, at 23 Jun 2010

Unless you 've been living in a cave for the last year, you know that server side (better: 'general purpose') JavaScript is all the rage. Everything started with CommonJS: the emerging standard spawned an ecosystem of compatible implementations competing against each other while advancing the JavaScript state of the art.

Then, NodeJS happened: An async only JavaScript platform, powered by V8, not really interested in CommonJS conformance. RY (the new DHH) managed to grab the attention of the developer community with cool marketing, leaving other implementations in the shadows. One such great implementation that deserves more attention is RingoJS.

Some time ago I switched from Narwhal to Ringo and never looked back. I strongly believe that Ringo is the preeminent CommonJS implementation. Here is why:

  • Ringo is quite possibly the most conformant CommonJS implementation, certainly more conformant than Narwhal and Node.
  • Ringo is *fast*. If you tried Narwhal/Rhino and found start up times lacking or module reloading unacceptably slow check out Ringo! You will be pleasantly surprised. And while v8 may be faster than Rhino, the JVM is still quite optimized for server side environments. (And btw, in a modern Web application, time spent running the server side script is a negligible percentage of the total request/response cycle. You should probably work on optimizing network issues, database interactions, client side rendering etc)
  • Ringo is mature, stable and crash free. Ringo is the evolution of Helma, one of the first server side JavaScript platforms (more than 10 years in development). It's also based on the mature Java platform. Contrast this to reports of NodeJS crashes.
  • Access to the gazillion of Java libraries. There is no merit in reinventing the wheel, just reuse code from the Java ecosystem. The integration between Java and JavaScript is seamless.
  • Windows compatibility. OK, Windows sucks, but still, a lot of engineers use Windows as a development platform. Ringo apps work on Windows out of the box.
  • Support for synchronous and asynchronous APIs. Use what's best for your application.
  • Thanks to AppengineJS you can run your Ringo applications on Google's scalable infrastructure.
  • The lead developer is extremely talented and friendly.

Stop drinking the Kool-Aid! Engineer your application on top of a mature, conformant and compatible platform: RingoJS.

Update: Removed a controversial link

Normal Template

by gmosx, at 25 Jan 2010
For some time now I was using a custom version of JSON-Template. I really like the simplicity of JSON-Template and the clean separation of data, logic and design. On the other hand I hate the syntax (repeated section, argh) and the 'cursor' paradigm employed has problems in practice.

In this vein, I designed a new template engine, called Normal Template. I consider this an evolution of JSON-Template concepts that works better in practice. Here are some benefits:

  • Separate 'if' command (required in practice)
  • Replaced {} interpolation with {=..}, safer in practice, more readable
  • A subset of XPath is used to navigate the data dictionary along with a cursor model (select)
  • Abbreviations for tags (s for select, r for reduce, etc)
  • Meta templates and static includes
  • Compiles to a javascript function for extra performance
  • Improved syntax error checks and reporting

For more information, please consult the detailed docs. To wet your appetite, here is an example.. more

HTML parser for JavaScript

by gmosx, at 27 Dec 2009
I needed an HTML parser for one of my projects. As I am using exclusively JavaScript lately (and loving it) I searched for a JavaScript solution. Envjs looked interesting but the messy source code (and global namespace pollution) was discomforting. Finally I decided to package Java HTML5 parser used in Envjs for Narwhal

The tricky part was to make the parser compatible with Sizzle but I am happy to report that they both work great together now. You can find the source code for the package here. And here is the mandatory example:

var HTMLParser = require("htmlparser").HTMLParser,
    sizzle = require("sizzle").sizzle;

var html = '<html><p id="header"><b>nice</b></p><div id="test" class="big">hello</div><div>second</div></html>',
    parser = new HTMLParser(),
    document = parser.parse(html),
    $ = sizzle(document);

$("div").forEach(function(el) {
    print(el.innerHTML);
});

print(document.toHTML());
print(document);

Now it is easy to write your own server-side web scraper using familiar client-side tools!

Markdown for Javascript

by gmosx, at 09 Aug 2009
The other day I was working on the docs section of nitrojs.org. Originally, I came up with a custom solution that eventually proved inpractical. Taking a hint from narwhaljs.org, I decided to write docs in the Markdown format, so I could reuse them on Github as well. 

John Fraser's Showdown was a great fit for the job, so I quickly packaged it as a Narwhal package. Since this package is generally useful, the Narwhal maintainers added it to the tusk catalog. Alternatively, you can find the source here

Now, there is no excuse. I really need to write some Nitro docs ;-)

Narwhal v0.1 / Jack v0.1

by gmosx, at 30 Jul 2009
The long awaited first versions of Narwhal and Jack have been finally released! From the release notes:

Narwhal:

Narwhal is a cross-platform, multi-interpreter, general purpose JavaScript platform. It aims to provide a solid foundation for building JavaScript applications, primarily outside the web browser.  Narwhal includes a package manager, module system, and standard library for multiple JavaScript interpreters. Currently Narwhal's Rhino (http://www.mozilla.org/rhino/) support is the most complete, but other platforms (http://narwhaljs.org/platforms.html) are available too.

Narwhal's standard library conforms to the ServerJS standard (https://wiki.mozilla.org/ServerJS). It is designed to work with multiple JavaScript interpreters, and to be easy to add support for new interpreters. Wherever possible, it is implemented in pure JavaScript to maximize reuse of code among  
platforms.

Jack & JSGI:

JSGI is a web server interface specification for JavaScript, inspired  
by Ruby's Rack (http://rack.rubyforge.org/) and Python's WSGI (http://www.wsgi.org/). It provides a common API for connecting JavaScript frameworks and applications to webservers. more