chapter eight

8 Code guidelines for authors

 

This document provides comprehensive guidelines for formatting, annotating, and presenting code in your manuscript. Following these standards will ensure your code is clear, accessible, and easy for readers to follow, both in print and digital formats.

Code is a central teaching tool in technical books. Manning uses a system of code annotations—explanatory notes placed alongside code—to help readers understand key concepts without having to flip back and forth in the text. This document covers how to format your code, create effective annotations, and organize your code samples for maximum reader benefit.

Definitions and types of code

Before diving into formatting and annotation, it’s important to understand the terminology used throughout these guidelines:

  • Listings: Code that the reader is meant to type in as part of an example or walkthrough. Listings get a heading and are typically longer, multi-line examples.
  • Snippets: Shorter pieces of code, such as command-line commands, output, syntax definitions, or simple examples. Snippets are often inline or follow a paragraph and do not get a listing heading.

Any code—listing, snippet, or command-line example—can be annotated.

Formatting your code

Proper formatting ensures your code is readable and typesets correctly in both print and digital formats.

Presenting code listings

Code annotation guidelines

When to use annotations

Types of code annotations

General stylistic and formatting guidelines

Creating standalone annotations

Special annotation techniques

Hedgehog diagrams

Organizing and labeling code samples

Preparing code for upload

Quick reference tips

Visual distinction: code snippet vs. code listing