Use typewriter font for code inside prose

There’s a useful tradition of using a typewriter font, or more generally some monospaced font, for bits of code sprinkled in prose. The practice is analogous to using italic to mark, for example, a French mot dropped into an English paragraph. In HTML, the code tag marks content as software code, which a browser typically will render in a typewriter font.

Here’s a sentence from a new article on Python at Netflix that could benefit a few code tags.

These features (and more) have led to increasingly pervasive use of Python in everything from small tools using boto to talk to AWS, to storing information with python-memcached and pycassa, managing processes with Envoy, polling restful APIs to large applications with requests, providing web interfaces with CherryPy and Bottle, and crunching data with scipy.

Here’s the same sentence with some code tags.

These features (and more) have led to increasingly pervasive use of Python in everything from small tools using boto to talk to AWS, to storing information with python-memcached and pycassa, managing processes with Envoy, polling restful APIs to large applications with requests, providing web interfaces with CherryPy and Bottle, and crunching data with scipy.

It’s especially helpful to let the reader know that packages like requests are indeed packages. It helps to clarify, for example, whether Wes McKinney has been stress testing pandas or pandas. That way we know whether to inform animal protection authorities or to download a new version of a library.

8 thoughts on “Use typewriter font for code inside prose

  1. And if you’re using a monospaced font, make sure you use the family. I’ve seen many websites built on Mac that use Monaco as their monospaced font but fail to specify the fallback. This renders whole code blocks in a default font.

    A simple font-family: Monaco,monospace would solve the issue. I’m not talking about news websites but about programmer focused sites like Socket.io and slim-lang.com (These sites had only Monaco until recently).

  2. Chris Meisenzahl (@speedmaster)

    Interesting, I just started looking at Python, might try to learn it.

  3. Agree about code listings in general. But it’s not clear that program names, when used outside of a code context, or outside the context of showing how to run the program, should be monospaced. Do we monospace LaTeX, e.g.? Or Microsoft Word? etc.

  4. Yawar: I agree that’s fuzzy. I would set libraries in monospace but not programs. I think that’s conventional. And it makes sense: program names are generally capitalized and more familiar.

    I’d set command line utility names like sed in monospace because they are not capitalized and because they’re conceptually more like libraries for the shell than like programs. Also, some of them are common words like top and nice.

  5. Martin and Dmitry: Good points.

    Allowing zeros does make things more difficult, maybe impossible. Certainly impossible to brute force by computer. Maybe there are theoretical ways to limit, for example, the number of primes of the form 1000….0003, but that’s a much harder question.

Comments are closed.