May 10, 2017

Rest APIUntil relatively recently, if you wanted to build a WordPress theme, you had to use PHP. With the introduction of the REST API, that’s no longer the case. It’s possible to build integrations with WordPress in any language. As Matt Mullenweg has pointed out on several occasions, a leading motivation for the introduction of the REST API was to tap into the JavaScript ecosystem.

JavaScript has long had an image problem, but developments in the Javascript ecosystem and the language itself means that creating Javascript front-ends, including powerful SPAs and other web applications, needn’t mean dealing directly with JavaScript at all.

Of course, Javascript is the only language that will run directly in the browser, but that only means code has to end up as Javascript: it doesn’t have to start life that way. Since the advent of CoffeeScript, a language that compiles to JavaScript, any number of languages that compile to Javascript have been created — and any of those can be used to build front-end applications that take advantage of the WordPress API.

Let’s have a look at three of those languages.

TypeScript

TypeScript is a superset of Javascript. That means it builds on top of Javascript to add extra features and paper over some of the less inspired design choices that make coding in Javascript tricky.

TypeScript, as the name suggests, is a strongly typed language that adds a comprehensive type system to Javascript. The type system helps avoid a lot of bugs that are bane of Javascript developer’s lives, in addition to making the code easier to read and reason about.

But that’s not all; TypeScript also extends Javascript’s object oriented features, fully supports ECMA6, and is accompanied by excellent tooling.

Elm

TypeScript is Javascript with some extras. Elm is not like Javascript at all. Elm is a functional programming language that was created specifically for building web applications.

It comes with all the trimmings of functional languages: immutable state, first class functions, pattern matching, and so on. Elm is also extremely fast: like React it uses a shadow DOM to render page changes, which makes it perfect for building complex interactive web applications.

The headline feature of Elm is the Elm Architecture: an intuitive method of building web application as views, models, and updates. Elm applications tend to be highly readable and maintainable.

Elm’s creators and Elm enthusiasts boast that there are no runtime exceptions for Elm applications: because of its type system, the Elm compiler can find most problems in code at compile time. If it compiles, it’ll almost certainly run without errors.

Elm doesn’t just output Javascript: it can output HTML and CSS too, which means it’s possible to develop web applications entirely within Elm, taking advantage of a powerful functional language for all aspects of the application.

PureScript

I want to end this look at Javascript alternatives with a glance at PureScript. Like Elm, PureScript is a functional language. Elm is designed to be easy to use and understand. The same can’t really be said of PureScript, especially if most of your experience is with JavaScript. PureScript takes many cues from Haskell, a language beloved by many, but not easy to grasp.

However, PureScript is a powerful strongly-typed language with a lightweight syntax that is extremely expressive once you get to grips with the PureScript way. It’s well worth looking into if you tried Elm and found it overly opinionated and restrictive.

My aim here hasn’t been an in-depth examination of Javascript alternatives, but an expression of why I and many developers are excited by the WordPress API — it massively increases WordPress’ flexibility and opens up new vistas that will have a huge impact on the WordPress ecosystem over the next few years.

Nexcess
Nexcess

Nexcess, the premium hosting provider for WordPress, WooCommerce, and Magento, is optimized for your hosting needs. Nexcess provides a managed hosting infrastructure, curated tools, and a team of experts that make it easy to build, manage, and grow your business online. Serving SMBs and the designers, developers, and agencies who create for them, Nexcess has provided fully managed, high-performance cloud solutions for more than 22 years.


We use cookies to understand how you interact with our site, to personalize and streamline your experience, and to tailor advertising. By continuing to use our site, you accept our use of cookies and accept our Privacy Policy.