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);
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.

Related Articles:

About Sharon Cichelli

I am a Headspring Senior Consultant, developing custom enterprise software for our clients and leading training classes on the latest Microsoft technologies. I blog about .NET development, best practices in agile software development, and my nerdy hobbies.
This entry was posted in arduino, Conference and tagged . Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • http://pedroreys.com/ Pedro Reys

    I’ve used this ScriptManager in the past http://bit.ly/1OITpM 

    I will give AutoHotKey a try.

    Thanks for sharing! :P

  • Carlos Ribas

    Very nice.  This is one of the things I really like about watching Apple presentations (WWDC).  They almost always do it this way.  Hi, btw.

  • John Teague

    The problem I have with code snippets in a presentation is that it’s a little too much like magic.  You’re talking and then poof! There’s Code! 

    The typos and the curly braces are not what gets you.  It’s when you don’t know what direction you want to go. When people get in trouble live coding during a presentation is when it’s the first time you’ve written the code.  Doing live coding does not absolve you from being prepared.  It makes it harder.  

  • rsanchez1

    What if you have a wall of code, but you highlight it on the fly? As you go through the code, it gets highlighted so the audience can follow you at the pace you want.

    • Carlos Ribas

      I think that depends on the highlighting.  Often, highlighting really hurts syntax highlighting and thus impairs readability.

  • Alper Sunar

    Having seen this technique in action, I can say that it is a brilliant idea. It allows the presenter to build the example step by step and makes it really easy for the attendees to follow what is happening.