Did you know? You might have Phantom Code!

Did you know? When a Google Apps Script project containing multiple ‘files’ is run, the entire script is ‘loaded’ and run. That might include what I call Phantom Code: script content that you don’t intend to execute. This situation is more likely when you are using the recommended practice of separating your code into different gs files, each focused on a different concern.

Problems might show up as unexpected behaviours, or it might be benign but contribute to your script execution limits and slow your scripts.

Continue reading


Did you know? (It’s worthwhile including attribution for code snippets!)

I believe that everyone who writes software of any size will reuse code written by someone else at some time. I’m talking about referring to a library or API, but to copy & paste reuse; fully adopting someone else’s source code. Further, I believe that there are lots of great reasons to do so. Developers are quite used to performing internet searches or using dedicated code repositories to locate candidate code snippets that they will import into their projects in whole or part, and possibly modify to their own purpose.

Much of the code you’ll find this way is freely available (it will cost you no money), but may have additional licensing requirements that you should be aware of and conform to. One of the most common requirements is attribution.

attribution (noun) The act of attributing, especially the act of establishing a particular person as the creator of a work of art.ref

In today’s entry, I’m going to make a case for including proper attribution for all the third-party code we reuse, and suggest a consistent way to do so. My examples will focus on Google Apps Script, but this can apply to any programming language.

Continue reading

Did you know? (You can log to a spreadsheet from client JavaScript!)

Google Apps Script has a Logger class, intended to help debug by enabling you to log the operation of your code, and examine run-time data. Viewing those logs is supported through the View > Logs menu option in the Google Apps Script editor.

Unfortunately, the built-in Logger doesn’t work in every situation. A requirement is that you must be running your script with an attached editor / debugger session, so that precludes logging trigger functions (when reacting to actual events), and many asynchronous operations such as UI interactions. If you want to compare results between sessions, you’ll be frustrated to find the output of the Logger is transient – the next time your script is executed, all previous logs are lost.

Today’s post is a quick tip for generating persistent logs from your whole application, including client-side JavaScript running in a user’s browser, such as an add-on sidebar or dialog, menu-driven functions, and autonomous functions such as triggers. Custom functions are not permitted to modify spreadsheet contents directly, so they are the one exception for this technique.

Continue reading

Did you know? (Custom Functions in Google Apps Script)

In Google Apps Script, Custom Functions are special. They have limitations that other script functions don’t, but to compensate, they have been given awesome powers! Ok, that’s a bit strong – let’s say they have unique capabilities that aren’t immediately obvious.

You can learn most of what you need to know to write your own Custom Functions by reading Google’s documentation. But did you know

  • You can craft effective auto-completion help with comments in your Custom Functions?
  • Your Custom Functions can present customized error messages for users?
  • Custom Functions can support an arbitrary number of parameters?

Today’s blog might have some surprises for you, if you thought you knew everything about writing Custom Functions.

Continue reading