tech blog

AppNexus is today’s most powerful, open, and customizable ad tech platform. Advertising’s largest and most innovative companies build their businesses on AppNexus.

AppNexus Engineering@Scale: Writing High Integrity JavaScript

| Comments

The latest AppNexus Engineering@Scale talk comes to you from Portland, where AppNexus just purchased 10,000 square feet of downtown office space. AppNexus has been aggressively growing its Portland presence and can’t wait to move in to their downtown office.

In this Portlandia installment of AppNexus Engineering@Scale, two AppNexians share the stage. First up: Travis Johnson, Director of Engineering, shares insight into how the AppNexus User Interface (UI) team is using Grunt for better testing. Then Nathan Wall, one of the UI team’s software engineers, introduces the concept of high integrity coding. Caution: it might blow your mind.

Building a test-driven culture with Grunt (Travis Johnson)

About six months ago, AppNexus began to focus on creating a test-driven culture in the UI team. Drawing on advice from Daniel “dB” Doubrovkine, the team knew they needed creative solutions that would let them test early, often, and fast.

Enter Grunt. The UI team had been relying on Jenkins and Jasmine for testing but knew that was insufficient. Adding JavaScript’s task runner Grunt to the mix has let the team automate their testing *and *operate at the fast pace that AppNexus requires. Travis outlines the three Grunt plugins that make the difference:

  1. grunt-contrib-jasmine
  2. grunt-regarde
  3. grunt-notify

(Update: The UI team has recently stopped using grunt-regarde and has switched grunt-contrib-watch.)

Writing high integrity JavaScript (Nathan Wall)

JavaScript is highly malleable by design, which allows for tremendous creativity for developers. That also means it can’t always be trusted. Currently there are two approaches to dealing with the malleability of JavaScript:

  1. Don’t worry about it and assume it is a safe environment.
  2. Lock the environment.

However, both of these approaches have serious drawbacks. On the one hand, treating JavaScript like a safe environment doesn’t work when high reliability and high security requirements are at play. On the other, locking down an environment only works if that environment that isn’t being shared. Plus both approaches limit the biggest pro to JavaScript’s flexibility: room for creative problem solving.

But what if you just wrote code that always works? This is the third alternative that Nathan Wall proposes here. His creative solution to dealing with the malleability versus trustworthiness tradeoffs of JavaScript showcases the type of innovation that AppNexians thrive on.

Nathan defines high integrity JavaScript as “code that works in whatever environment it is in.” High integrity coding applies in situations when third party code is being used or written and/or with applications requiring security, like banks, social networks and email clients. Nathan sees writing high integrity JavaScript as having two goals:

  1. Design scripts that run predictably, reliably and securely given a consistent initialization environment.
  2. Leave the environment in a state that functions observably identically to the way it did when we got access to it.

To meet these goals, Nathan discusses in-depth a handful of essential JavaScript skills that you’ll need to be familiar with. These are: getting up to speed on ECMAScript5, writing general purpose code, using private variables and guarding internal state.

While nothing’s definitive in the realm of guiding, consider this your guide to writing high integrity JavaScript.