Presenters, Use Code Snippets for Live Coding


Creating code live on the fly makes a more compelling demo, but actually typing those curly braces and semi-colons can kill a presentation. As hard as it is not to say “um”, it’s nigh impossible to not make a million typos on stage.

Code snippets, where you need to type only a short keyword to automatically insert a small piece of relevant code, are a great antidote. I learned this strategy from watching Burke Holland teach us about CoffeeScript. Most code editors and text editors support code snippets, and if yours doesn’t, you can use AutoHotKey to define a set of hotstrings.

Here’s an example of one of mine. In the Arduino IDE, I type:

`.ledhigh`

and AutoHotKey immediately replaces that with:

`digitalWrite(led, HIGH);<br />
delay(700);`

My snippets are short so that I can explain as I create the code, creating an experience for the audience that feels very much like live coding—but it’s live coding with flawless fingers.

I put my Arduino presentation snippets on GitHub. You’ll notice two tips there. First, I prefixed my hotstring abbreviations with a period to make conflicts unlikely. Second, I added a conditional at the top to make the hotstrings apply only when the Arduino IDE is active.

`#IfWinActive ahk_class SunAwtFrame`

I discovered the class of the window by using the Window Spy application that comes with AutoHotKey. I used the ahk_class instead of the window title because, although the Arduino IDE changes its window title based on the sketch it is showing, the class type of the window stays the same.

It’s tempting to launch into a presentation figuring the most exciting way to share code with the audience is to type it live. If you’ve ever actually done this, though, you know how devilishly your hands will betray you. At the other extreme, a wall of code on a slide will captivate your audience, at the expense of anything you might be saying at the time. Use code snippets to dole out code in explainable chunks, live but without the typos.

Intro to the Arduino at CodeMash