One of the issues with modern coding is the barriers to getting started. As I wrote in Can't Code There From Here, programming languages used to just be available, already configured at your command prompt, but now to start coding you have to download, and install, and then update, and then add code library upon mysterious code library. To quote my previous posting:
We've frontloaded one of the most tedious parts of computing, setting up a working coding environment, into the beginning of every code adventure.
And in an environment where there are constant cybersecurity issues, including attacks on coding supply chains, it's not exactly comfortable either to watch line after line of mysterious installs scrolling across the screen, or to try to wade through dependency alerts every time you try to write some simple code.
For these reasons, I've found Jupyter Notebooks in Google Colaboratory to be quite refreshing, as it's all already set up for you to access from your Google Account. No downloads, no install, just Internet ("cloud") coding. It is a research offering, so be mindful that it may go away at any time, but for now it gets you back to being able to code without any setup.
The good news is it is very straightforward on-screen. You can have text blocks, with, well, text (in Markdown) and separate executable Python code blocks. You can mix text and code blocks for a verbose, explanatory coding style.
File Access
Getting files (e.g. CSV data files) into Colaboratory is fairly straightforward. To get files from your Google Drive you have to mount the drive
from google.colab import drive
drive.mount('/content/drive')
and then get an authentication code. There's information on the Colaboratory site - Mounting Google Drive locally.
Once mounted your actual Google drive will typically be one layer down, /content/drive/My Drive/
You can also access files from your local file system, and apparently there is some kind of direct access to Google spreadsheets as well.
.ipynb files
The sort-of bad news is that the nicely formatted text and code within a Jupyter environment turns into a jumble of JSON when saved in the .ipynb plain text format. You can't really work with Notebook .ipynb files outside of Jupyter. It's all chunks of
"cells": [
{
"cell_type": "markdown",
etc.
UPDATE 2021-04-04: I didn't realise that a Jupyter Notebook really is a notebook, in the sense that it preserve the last state of its output. I was wondering why a small .ipynb notebook file that I emailed to myself was 1MB, but it's because the .ipynb stores the last output state (including charts). I only found this out when viewing a notebook I had downloaded from Colaboratory and then uploaded to GitHub. Clicking on the notebook in GitHub shows not just the code and text, but all the outputs from the last code run at each stage.
If you don't intend to also share the outputs from your last code run, clear the contents before sharing a notebook.
Thanks to Juan Miguel Lavista on Twitter for additional information making this clear.
END UPDATE
GitHub Integration
In theory you can integrate Colaboratory directly with GitHub, but that means full read/write access.
If you're not keen on tying your Google Account and GitHub account together in this way, you can just do a more indirect download and upload pathway.
Colaboratory can read files directly from GitHub with no special permissions, just go to File -> Open notebook and select the GitHub tab. It didn't behave the way I expected when I put in a GitHub URL, but it worked fine when I put in my username.
Within GitHub itself there's not a lot you can do with a notebook file, as far as GitHub is concerned it's a "non-code file".
UPDATE 2021-04-04: As indicated in the previous section, you can view a Jupyter Notebook as basically a web page, including any outputs that were saved with it, by clicking on the .ipynb link in GitHub. END UPDATE
End Program
And that's about it. It is not of course exactly a free-for-all. There are some kind of RAM and disk limits that you will hit at a certain point.
If you do want to go the locally-installed route, there are several options for Jupyter Notebooks including Anaconda and Microsoft Visual Studio Code (for Windows, Mac, and Linux), but they require not only the aforementioned multiple dependency levels of downloads, but in a work environment may also require passing a proxy parameter if your web connection goes through a proxy.
Comments