Hacker News new | comments | ask | show | jobs | submit login
Google's Code Editor (docs.google.com)
303 points by obilgic on May 16, 2012 | hide | past | web | favorite | 85 comments

The link title will attract developers anxious to see what Google is offering or Googlers are using to edit code, but this is just an online editor designed for Apps Script editing. It's been around a long time and is less interesting than the link-bait title suggests.

Google Apps Script is very useful in conjunction with Google's online apps and their rich libraries. JavaScript makes for a good customization language.

One non-obvious irritation, however, is that scripts cannot be shared. So, for example, one has to duplicate code between multiple spreadsheets rather than being able to import it as one would expect. There's an issue open, but even with a high priority, it's two years old:


That model does work reasonably well for use cases like roleplaying game character sheets, where individual players may want to tweak the scripts for their specific character.

It is incredibly useful in general, but definitely not news.

I have a financial spreadsheet that I use to track the distribution of my portfolio. I follow a system where I have a target allocation for each of a small number of assets, and then I buy or sell shares when any given asset gets beyond a certain tolerance of its target allocation.

Using Google Spreadsheets and the Google finance API available with Google Apps script, I was able to automate every part of this except syncing it with my account (since there's no API to access my financial records.) All I have to do is click a button, and the cells change color based on whether I should buy, sell or hold.

I'd be really interested to see how your set-up works. Would it be possible for you to share your files/code and a short description of how you implemented your set-up? I am happy for you to remove/sanitize sensitive details relating to your portfolio. However, I would love to understand how I can develop a solution like this for myself.

Thank you for your help.

What I have is a sheet which says how many of each asset I own, and the desired allocation. Then, there is a cell that calculates the current allocation, based on the number of shares, and the current price of the share.

The current price of the share is fetched from another sheet using a vlookup. That sheet is populated by the script. The script is here! https://gist.github.com/2717042

The overall system is based on research I found here: http://seekingalpha.com/article/15134-the-seeking-alpha-etf-...

> I was able to automate every part of this except syncing it with my account (since there's no API to access my financial records.)

It's actually possible to simulate a browsing session and have the App Script log in to your broker's site and scrape the data you need. Here is some prototyping code: https://gist.github.com/aaf74e50b9a281396722

What part did you use the scripting engine for? I was able to do something very similar, but purely with spreadsheet rules.

The scripting engine fetches up-to-date stock quotes and fills them in. The rest is all done using spreadsheet rules.

Here is the scripting engine part: https://gist.github.com/2717042

Update (2012-05-22): Google Apps Scripts now supports libraries:



Google has had what they call "Google Apps Script" for quite some time. From the documentation page at https://developers.google.com/apps-script/guide:

"Google Apps Script gives users a new level of control over Google products. Now you can access and control Google Spreadsheets and other products using JavaScript scripts that you write yourself and can share with others. Unlike browser-based JavaScript, the scripts you write run directly on Google servers in order to provide direct access to the products they control.You can also use Google Apps Script from Google Sites."

This online code editor seems to be a new and improved UI for creating / editing apps scripts. That said, this editor isn't proprietary. A quick look at the source shows that they're using CodeMirror (http://codemirror.net/). We've tried out various code editors for unclassroom.com (where I work) and code mirror has been the best to work with in terms of features, ease of use and comprehensive documentation. The second version (CodeMirror2) is really top notch compared to other alternatives out there.

Last year I've used Google Apps Script to automate a spreadsheet, it worked very well and that spreadsheet is still used inside my company. It's not very complex, all together maybe 200 lines of code, with tests.

But, I'm not sure if I would do it again.

Development style is not enjoyable, coding inside textarea with syntax highlighting is simply not good enough. I would prefer to use my text editor and some way to deploy changes without the need to copy-paste from editor to browser. I want to use my

Also, tell me exactly what language and what runtime is being used on the server. I remember searching the docs and it was "it's javascript". Maybe it's better now, I haven't looked since. Or just use node, after all it's V8.

In ideal world, this is what I would like (and really use):

* let me code offline: my editor. my source control.

* give me some SDK to run code offline like app engine

* give me a way to push changes to server

* great documentation

Without these, it's just too much like VBA in the nineties.

edit: 200 lines of code

NOTE: this is NOT a troll.

I know a great tool for the job.

It works fine with source control and allows documents to be diffed and merged.

The editor is 100% offline as is the product or it can be 100% online at will. No need to push changes to server - just replicate/copy. If you fancy collaboration tools you can use use extensive ones on a subscription basis.

It's got a well documented SDK and an interface that you can call.

Documentation is wonderful.

Automation can be done with PowerShell, VB.Net, C#, Python, Ruby, VBScript, JScript/JavaScript, Java or even Common Lisp if it takes your fancy.

Seriously just use Excel - it's just what you've asked for.

I don't think you're trolling; Excel is certainly an option.

But for two things:

  Excel for Mac - $129 (http://www.amazon.com/dp/B003YCOJBC)
  Excel for Win - $121 (http://www.amazon.com/dp/B0039L2XG6)
And you need a Windows box or Mac with Excel installed. I personally have access to dozens of machines, literally none of which have Excel. All of them have a web browser, and thus access to Google Spreadsheets and Google Apps Script for free. To me, and many others, that makes all the difference in the world.

That's not a major issue.:

You can use Office 2010 web apps FREE from a SkyDrive account and openly collaborate with people or you can pay $20 a month per seat for Office 365 and you will get Sharepoint and ALL Office 2010 desktop apps.

The office web apps work perfectly in all browsers (I've tried Chrome, Firefox and IE).

Considering the cost of playing around with Google spreadsheet with those restrictions, it's possibly a good idea.

Does the Excel web app support VBA? I was under the impression that the 365 apps offer a subset of the functionality of their desktop counterparts.

They don't support VBA directly.

I've always used Excel to publish result data to a spreadsheet rather than the entire thing. Data collection is done using InfoPath so you get the following workflow:

[www:InfoPath Office 365] -> [dt:Excel]-> [www:Excel report on Office 365]

It depends on your use case. I'd be tempted to use a sharepoint list with a custom report for anything more complicated.

How come Excel works fine with source control? It is a binary blob and diff and merge are done with Excel itself, not the version control's merge and diff (which may or may not be what you want).

What are those collaboration tools for Excel? This is an honest question: all I see is some spreadsheet on shared drive or Sharepoint with some ad hoc process around editing, making sure the need for the merge is avoided.

Excel files are simply zip files with XML in them.

What version control system will let you see the changes between the contents of two zip files again?

With Git and Svn you can specify the diff to use, so you can use something like oodiff if you are versioning OpenOffice files.

Something to diff zips of xml almost certainly exists and could be used in the same manner.

Now, patch is another thing ...

TortoiseSVN will diff OO and MS Office files out of the box.

But seriously, you're kidding right? Here's microsoft's answer to the diff and merge question: http://answers.microsoft.com/en-us/office/forum/office_2007-...

Granted, excel is a powerful tool for an individual to work with, but for teams working with a large number of complex sheets the model breaks down quickly. Keeping up with changes and versions using excel is a nightmare.

That's what Sharepoint is for :)

Also Word/Excel 2010 have excellent change management tools which integrate nicely with mercurial and SVN built in (under review changes).

You have to frig a couple of command line switches to get it to work but TortoiseSVN has those preconfigured.

EDIT: answers.microsoft.com is full of trash - ignore it...


We have 400+ page documents in the system and they all work nicely :)

You are right, it's something I forgot to mention: we are Google Apps users. We love that product: gmail, docs, spreadsheets, now drive... our whole business is based on Apps and our own ticketing/crm/sales software.

And I don't even use Excel, I run linux, although I've used Excel a lot and I think it's awesome at what it does.

I didn't find your reply as trollish, you certainly do make a very valid point.

WRT to Linux, all the Office web apps work on Linux quite happily.

We tend to give senior people access to windows machines with Office 2010 Professional Plus on and relegate support staff to Linux machines with Office web apps (in Chrome).

Can you elaborate on Common Lisp automation...

Via COM. Technically any language with a COM or DCOM bridge will work fine. lispworks has one and there is a route via the CLR here:


I've worked with this for some clients. I am but an egg, but I'm not convinced this is entirely JavaScript, I've had some code fail in App Script that passed JavaScript unit tests. And you cannot bring in libraries like jQuery.

You can hack some of these. Scripts can import code from a remote server, which allows you to edit where you like, push to your remote server and pull it into App Script. That tool enables small libraries, I've used it to write a simple test environment. I think you could test App Script JsTestDriver et al with some kind of mock-up strategy.

I haven't enjoyed it, but it has met the client requirements and that's the main thing, right?

It is server side javascript and because of that there is not jQuery (which is client side library). You are not working with DOM, you are working with API defined by Apps Script, check the docs here https://developers.google.com/apps-script/

I get that detachment from the DOM but jQuery has useful tools beyond element selection and manipulation.

For that matter, why doesn't App Script expose an interface that expresses page components as part of a DOM? The Sheet app could provide an interface to a cell with classes for its particular column, row and sheet, allowing access with jQuery / CSS selectors. Instead users have to learn a new interface with stuff like Spreadsheeet.getRange().

And maybe they've revised the docs, but I spent a fair amount of time in them and didn't see any discussion of what JavaScript tools would not be available. I had to figure that out by trial and failure.

We've got a fairly robust Mail Merge script with attachments (either the same for all or per-user), but distribution and maintenance is tricky given the lack of support for a centralised library of code.

Ideal would be allowing any publicly accesible URL (with some security measure to avoid blatant security holes) like Github raw master (always up-to-date).

The closest I've found is using eval (which is clearly NOT the best approach). There would need to be a format to specify which services you want to use (as currently it derives these from the source you write in the editor).

I would LOVE to be able to load in 'authorised' libraries to avoid redundant code.

I implemented Conway's Game of Life in AppScript once: http://sigusr2.net/2010/Jun/25/google-spreadsheets-game-of-l...

Your comment reminded me of a post I saw on here a few months back, a commandline interface for google apps (including docs):


This is pretty much what I want as well. I'm working on an app that is essentially your own Google Fusion Tables running local or on your own server. It includes a CLI for running as a service (integration, etc), so plugins could be made that hook into your local editor. It's a JS-based data publishing platform.

Btw, I was invited to YC interview round to show it. But sadly PG passed on it due to an enterprise strategy. :( Funny thing is I had an acquisition offer on the table during the YC meeting and subsequently closed a round. :)

The server environment is JVM-based since they expose GWT as the way to build UI. I think I remember seeing Rhino-specific error messages.

The coding environment is not very good, but you can build ERPs, CRMs, document management and similar for small businesses on Google Docs, in a way Microsoft Office / VBA never made possible. The modules it provides (spreadsheets, forms, formatted text document, gmail, calendar, wiki) seem to be very useful building blocks for describing your business processes.

Agreed an offline editor is very important, in my keyboard setup for some reason I can't use the character "}". Needless to say, hard to code without it. I'm sure they will fix it so, but it's a big no no for me at least.

Edit, it is not due to my keyboard language, i simply cant use the "}" character, the AltGr combination with the third button after the "L" is not working (My keybard has "ñ").

200 or 20000 lines of code?

200 :) thanx, i fixed it.

This really is a "Google Apps Scripts" editor for writing JavaScript to manipulate stuff in Google docs...see https://developers.google.com/apps-script/guide_writing_scri...

Is there an article explaining this or anything? I couldn't seem to get to it anywhere from the main google docs/drive page (although I didn't look very hard). 'docs.google.com' also isn't being translated to 'drive.google.com' like it normally is.

I hope they end up expanding this and using it for things like phone code interviews, though. Coding via the regular google docs interface was a bit of a pain.

Checkout the help menu, it has links to:

The documentation[1] And the old support channel[2]… …which is now officially at[3]

[1] https://developers.google.com/apps-script/guide [2] http://productforums.google.com/forum/#!forum/apps-script [3] http://stackoverflow.com/questions/tagged/google-apps-script

This is actually pretty cool, one step closer to making Google Docs a worthy competitor to Office. If they combine this with an Access-type database app, it could be a great tool for businesses.

Although using the interface builder brings back memories of VB...

The UI designer from old-school VB the best part about it. Obviously, the language part was crap. I think that forms designer still represents a rapid UI development environment that many languages/environments have not reached.

Probably not a very popular opinion here on HN, but the raw productivity you can achieve in the VBA/Office world is hard to reach anywhere else.

That still mostly exists in Visual Studio. I'm writing C# right now and the good old toolbox is right there on the left. Now it has even more goodies thanks to the .NET framework.

I typically do more webapps than anything else, so I have gotten used to designing my own UIs from scratch. I don't mind as it helps keep things very lean... but I'd love to use something like Sencha's app designer thing. I just can't justify the cost currently.

I always thought Trolltech's Qt Designer was much better.

Evidently, you could smell a VB product a mile away because of the awkward widget positionings in the window and the usually-not-resizable aspect.

You had to write manual resize code for all window components in VB, whereas in Qt it was all automatic.

Thinking about Google Docs simply as an Office competitor is wrong. If you come to it expecting to do everything you do in Office, it is probably adequate but definitely much worse. However, Docs can do sharing of centralized data, use web APIs, integrate with your mail, and more - things Office can't even hope to match.

> Access-type database app

I think that's the idea of Fusion Tables [1]. Since there is an API, I don't see why you couldn't combine it with Apps Script (what this editor is), if you wanted to. I don't think tight integration is there yet but the pieces seem to be in place. I think they just need to allow a script to be invoked from a Table.

1. http://www.google.com/fusiontables

I think the interface builder resembles more interfaces builders for Java than Visual Basic and Delphi ones...

And that's good IMHO

I use Google Docs code a lot at work in "production". Here's my experiences:

Yes, you can do more than a few hundred lines of code. My in house library is now about 5k LOC. Yes, it's basically straight JavaScript. Everything is there except for the DOM. Yes, the online editor sucks. I don't use it at all. (see below how) No, you cannot use jQuery/Prototype, etc (there's no DOM or Window class). No, you cannot use long running methods. Google Docs cuts you off at around 30 seconds of execution. No, you cannot share code. (see below)

-- How I develop on Google Docs:

1. I develop it outside of Google Docs using Sublime Text 2

2. I test using Node.JS + assert() + methane.js (see below)

3. I then minify it using Google Closure Tool

4. Then I copy and paste it into Google Docs

This works well because the online editor blows when you're doing anything semi-complex.

--- Testing in Google Docs

I use node.js + assert() + methane.js. What is methane.js? It's a little piece of JS that mocks some of the Google Apps classes and functions. I can then override that mocked method to return the value I expect Google to return and test my own methods.

It's here: https://github.com/chrisle/methane

Consider it alpha code. It's not very well documented. It works for me!(tm)....

-- Sharing code in Google Docs:

Inside of onLoad() I've seen people use UrlFetch and then eval() the response string as a way of getting shared code to work. Not ideal, but it works. I personally don't share code or use this method.

If you want to look at another editor using CodeMirror check out Adobe's Brackets:


It's early in development and not ready for general use yet.

Unlike Google this one is open source and it runs as a desktop app built primarily with JavaScript, CSS and HTML5.

I guess 2013 will be the year of the OnlineIDE? It would be pretty great to use ChromeOS for some actual work.

There's actually a Web Development category in the Chrome Web Store. Cloud coding is something I was very much pushing for when I was working on the store, we blogged about some of the tools available at http://blog.chromium.org/2011/06/cloud-coding-and-beyond-web....

Cloud9 is pretty decent - especially being able to deploy directly to Heroku and Azure

Don't forget Git and GitHub.

The script manager can be very useful. For a project, I needed to get translations in 4 languages and the client wanted to handle all of it. I wrote a quick script to pull id's and all the columns and format it exactly how I needed, than email me the file. Anytime there are language updates, they send me a note, I run the script and commit the language file changes.

The same logic applies to another where I let the client update SEO keywords/meta/OG info. Of course I could have built a CMS for it, but then again, they already have a google account and revision history with gdocs is a nice touch.

That will better for phone interviews will Google than the "plain" Google Doc (which is just terrible for writing code -and that's normal-).

It has also an interface builder:

File -> Build a user interface.

disabled on mine

works for me using Aurora 14.0a (Firefox) ... save your script first ... then it might be enabled.

This is an awesome tool. Has anyone tested to see if it supports collaborative editing the same way other google docs tools do? If so, this would be a great alternative to screen in some cases, and would definitely go in my interviewers toolkit.

FWIW, Google used to (still do?) use Google Docs as their recruitment tool for code screening.

Yep. That was the case when I went through two years ago, and a friend went through the process within the last month and also used Docs.

It does not.

This opens up some great possibilities. I noticed a jQuery plugin the other day that ingested JSON or could pull data from a supplied Google Doc. Seemed odd but makes sense when you see the direction Google Docs is headed.

They just need a Git integration with syntax highlighting for other languages and this might actually be useful. Although there are many web-IDEs simple tool like this would still be useful.

I cant seem to be able to run a closure. The editor says: no functions to run.

Consider this code: var i = (function () { var k = 1; return function () { return ++k; } } () );


Well this would form a good basis for an on line code editor. I am surprised they are using javascript instead of Go, Dart, or Python

JavaScript is already supported by the browsers, it seems like the obvious choice for me. Especially since it's supposed to be for manipulating google docs, which live on the browser. The alternative would be to run the code server side which seems silly when you have a js interpreter right there already.

They even have gui builder http://cl.ly/0t4740472r2p1E2p2F1N

Google is new Microsoft, They have no idea which products/apps they have...

Wow, why don't they publicise this and get Go and Dart working?

Funny, I ran into this this morning while trying to figure out to do condition formatting in Google Docs.

if you need excel-like desktop app, but with a decent scripting support (VBA sucks) check http://www.resolversystems.com/products/resolver-one/

Why use anything but its-all-text and vim?

It's CodeMirror - http://codemirror.net/

Tis a shame, there are far more comprehensive and impressive displays of what Code Mirror can do than this. CodeMirror makes the OP's link extremely trivial to implement.

edit: Sorry, this isn't meant to be a dig on the Google's Code Editor as much as it's meant to be praise of how impressive I find CodeMirror (and it's competitor/friend Ace).

> there are far more comprehensive and impressive displays of what Code Mirror can do than this.

Can you give some examples?

Filim Malena


Please collaborate to the conversation, you're obviously allowed to not like it but please explain why. "Yuck" just doesn't cut it.

I consider all these editors in the cloud a waste of effort.

The right place for a code editor is as a native application.

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact