Thursday, May 2, 2013

Google Apps Script revisited: still crap if you're using it wrong

You probably read my first post about Google Apps Script, which described my (mostly) bad experiences while experimenting with it. Well, I might have been wrong. Not that Google Apps Script is not slow - it is! - but maybe that doesn't even matter.

If you want to know why I think Apps Script is so slow, check out the previously mentioned post, or simply take a look at this script (exactly the same I used 9 months ago, by the way). On a cold start, the script takes about 10 seconds to load. That's horrible. Loading my blog doesn't take that long, even though it contains a ton more content than this simple script. Moreover, the UI is quite unresponsive (input some text and click "search uss!"). To be honest, this is simply because there's virtually no client-side logic - which means that clicking the button sends a request to the server what to do next. That's the way Google Apps Script is designed, and I think this makes things for people who aren't experienced developers a lot easier.

I love your inner values

So, what about the "inner values" of Google Apps Script, then? It offers quite a big range of built-in APIs to access and modify data from Google services - ranging from Drive, to Gmail (yes, an API for Gmail!), to Analytics, Tasks, Calendar, and so on... That's pretty impressive and I think that's the real value of Google Apps Script. You don't want to use this to create stunning web apps, but you want to use this for organizing and analyzing your data stored in various Google services.

GmailArchiver

A few weeks ago some random lawyer asked me to create an application using Apps Script for him, which archives all mails in a specific label into a spreadsheet. "Peanuts", I thought and gave it a try. A few days later I had finished GmailArchiver. Thanks to the APIs built into Apps Script this was not hard at all. The only thing that gets into your way when developing for Apps Script again and again: a single execution of a script isn't allowed to last longer than X minutes (I think it's five minutes Apps Script specialist +Sergii Kauk says your script is allowed to run for 6 minutes). Therefore you have to prepare your script to get killed at any time and resume it a few seconds later at the same progress. You can see the actual implementation in the script, but it comes down to a Trigger which triggers execution every 5 minutes so your script can resume at the last known state.

The point is: it doesn't matter how slow Apps Script performs in this case, because it's doing the job without any user interaction. When it's done, it sends an email to the user telling him where to find the archived mails.

By the way, that guy who actually requested this script never replied, so all the time I spent on this is wasted time. :'( That's what you get for working with lawyers...

StackUnderflow

Another script I made, which doesn't access data on Google services at all this time. It's a simple utility which translates the StackExchange API into a RSS feed. In my case, I wanted a feed for featured (android-tagged) questions and another feed of unanswered (android-tagged) questions. Again, it doesn't matter how slow the RSS feed is being created, because it's only requested by some RSS aggregating server (RIP Google Reader :'().
You can find these scripts here and here.

DriveCleaner

Aaand one more: a script which deletes all files matching the specified regular expression. Particularly useful if you want to get rid of unintentionally uploaded hordes of .class-files. Use with caution. You can find the script here.

TL;DR

Google Apps Script is cool. Just don't use it for creating web apps / mobile apps / or any other app outside of spreadsheets.