Comment by nrhrjrjrjtntbt

2 months ago

What is the best way to show code?

I really want to show some code. Like 4-5 lines to give a gist.

The advice is:

> 1. do not show a slide full of code.

Not "do not show code". Focused snippets are fine, you just need to distill the code to make sure it's just the essence of what you want to show and that it's easy to read (naming is important).

4-5 lines can be really effective. After all, if you're at a software conference, you're probably speaking to a bunch of programmers about programming, and code is your universal language.

But already 7-10 lines is stretching it, and any more than that, and it's a lot harder to get your point across because people spend so much time trying to parse the code sample.

The problem is that cutting down the code and coming up with an example that explains everything you want in just 4-5 lines is really hard — "if I had more time, I'd have written a shorter letter" and all that.

  • When I need more than a couple lines of code, I'll highlight in red the parts the audience should focus on.

I ruthlessly make the code examples as simple as possible. Eliminate everything but the point you're trying to make. I'll adjust the font to fill the slide.

  • And it doesn't have to even be code that compiles, unless it's about the language design and it really really matters for that presentation. You can yadda yadda whatever you want. Syntax doesn't exist anymore, just use greyed out "..." for the uninteresting parts.

Just do it. There's nothing wrong with it, if that's the kind of talk you want to give.

Look at stuff by david beazley, matt godbolt or casey muratori. They all have talks which focus on small pieces of code and i'm sure it's a tremendous effort to frame that well enough and pace it appropriately, but it sure works for them (and me watching their talks).