Jump to Content
Developers and Practitioners

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

March 16, 2020
Alexandrina Garcia-Verdin

Google Developer Advocate

This update to Apps Script lets users take advantage of modern JavaScript features and enhances new or existing scripts with less verbose, more standardized code.

Try Google Workspace at No Cost

Get a business email, all the storage you need, video conferencing, and more.

SIGN UP

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.

https://storage.googleapis.com/gweb-cloudblog-publish/original_images/image6_pqqD9nv.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 =>

https://storage.googleapis.com/gweb-cloudblog-publish/images/1-1.1000029420000392.max-1200x1200_XzGOL9M.jpg

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

https://storage.googleapis.com/gweb-cloudblog-publish/images/2-2.1000031220000383.max-1200x1200_0tSXCbo.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()

https://storage.googleapis.com/gweb-cloudblog-publish/images/3-3.1000029920000339.max-1200x1200_6bFs3xU.jpg

filter()

https://storage.googleapis.com/gweb-cloudblog-publish/images/4-4.1000031420000308.max-1200x1200_A7RHqfg.jpg

reduce()

https://storage.googleapis.com/gweb-cloudblog-publish/images/5-5.1000030820000250.max-1200x1200_bWBB6vi.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.

Posted in