Workspace Developers

Data processing just got easier with Apps Script’s new V8 runtime

We’re excited to announce Apps Script is now supported by the V8 runtime that powers Chrome and Node.js. This update lets users take advantage of modern JavaScript features (ECMA 6 and new releases moving forward). It also enhances new or existing scripts, like those that transform data in Google Sheets, with less verbose and more standardized code.

What is Google Apps Script?

As a quick summary, for small to medium-sized team projects, Google offers a free scripting environment that connects Google and non-Google applications to automate calculations or workflows (by visiting script.new in a browser, or Tools > Script editor within a Google Sheet, Doc, Slide, Form, etc., or recording your steps as a macro). Each script (called an Apps Script) can run on a schedule, or be triggered by a user’s actions. These actions can include opening a sheet or interacting with custom UI components such as custom formulas, pop-ups, menu dropdowns, or even complex HTML-based interfaces with buttons and text inputs (web apps).  

Apps Script is part of the G Suite developer platform. If you’re a beginner, try it out here.

image6.gif
Type “script.new” in your browser to start a new Apps Script project.

Four improved use cases 

No side-effects

In computer history, one can compare the revolutionary practicality of the industrial period’s assembly line with that of assembly language. The sequential list of instructions (for-loops, while-loops, if-statements), called imperative programming, served as a recipe-like format, but it doesn’t have room for abstracting code for humans (in other words, very literal instructions). It also can run into trouble when executing multiple instructions using the same memory;  if there are “too many cooks in the kitchen,” unintended interpretations produce alternate outcomes (or side effects). 

By leveraging modern JS, one can lean on functional programming, which bases its logic in evaluating statements as mathematical functions. This way, each function has its own purpose, which reduces hidden dependencies; allows parallelization without tasks “stepping on each other’s toes;” and locks memory to ensure there are no overwrites.

Succinct syntax

Modern JS’s explicit expressions reduce complexity, making it easier to write and maintain (read) scripts. Two of many favorites are:

Arrow functions: a function is passed as an argument to another function as data, in one line, using an arrow icon =>

1.jpg

Spread operator: inserts the values of an array using 3 dots ...

2.jpg

I recommend two great resources by Google Developer Experts (GDEs):

Data processing operations

Whether it’s physics simulations,  invoice trends, ETL (extract, transform, load), or linear regression-based processes, using “map,” “filter,”, and “reduce”with arrow functions is powerful and clear. The runtime also provides a faster CPU computation for such mathematically intensive activities, and a better logs experience

map()

3.jpg
4.jpg
5.jpg

The best of JS features, combined with Apps Script 

JS modules, which help import functionality declared in one file into another, are not available at this time. However, if you are looking to leverage modern features like this along with TypeScript, coding in your favorite IDE, or using third party JS libraries like Tensorflow (machine learning), Sequelize (database connector),  or GPU Accelerated JavaScript (GPU processing) with the ease of Apps Script’s built-in Google services, you can use CLASP (Command Line Apps Script) in a Node.js environment.

Next steps

If you’re using scripts that employ the older runtime, review these incompatibility tips—unless you wish to opt out from migrating to the new version. It’s exciting to see what the community can build with the new capabilities modern JS unlocks, especially those who work with Google Sheets and data processing use cases.