This page describes the rules for writing and linking API element names in running text. Reference pages often mention other elements, and a reader has to tell from the sentence which element is meant before they follow a link. The links page covers link text and link formatting in general.
When text mentions a method or function, use the name with parentheses (open()). When the name is overloaded, add the parameter names (open(path, mode)), the same form the member heading uses; in a language whose overloads differ only by type, the types can stand in for the names (run(int)). Prefix the name with its class or interface unless the method is a member of the element the page documents or a sibling member on the same type (Component.run(int)). For a method in another package, include the package (Nav.Component.registerPath()).
Examples
- ✓ Call the
open() method, then call the Component.run(int) method on the servo.
- ✗ Call open, then call run on the servo.
- ✓ From another package, call the
Nav.Component.registerPath() function.
- ✓ The
nearest(timeoutMs, ids) overload ignores readings from beacons outside the list.
Rationale
The parentheses mark the name as callable. The parameter list tells overloads apart and matches the heading that a link lands on. The class or interface prefix tells the reader which type the method belongs to before they follow a link.
When you name a code element in code font, identify its element type on its first mention in each paragraph. The element type indicates what the name refers to: a definition in code, such as a class, interface, method, function, property, parameter, module, or exception, or a value created at run time, which is an object or an instance. The noun can follow the name, or another part of the sentence can identify the element type.
Examples
- ✓ The
release() function frees the buffer.
- ✓ If you call a lifecycle function, such as
release(), it overrides automatic cleanup operations.
- ✗ Call
release() to free the buffer.
- ✓ The system creates the
compA object when it creates an instance of the Component class. When it destroys the compA object, it calls the Component.destroy() method on the object.
- ✗ The system destroys the
compA class.
- ✓ The system manages the lifecycle of
Component objects.
- ✓ Register the
Transform component type before the first system runs.
- ✗ Register
Transform before the first system runs.
Rationale
The element type tells the reader whether a name refers to a class, a method, a value, or another element before they read on or follow a link. It also tells screen reader users what the name refers to, because code font alone doesn’t. This rule extends code-009, which adds a following noun so that a code name is never inflected.
When a programming concept and a class share a name, such as views and the Android View class, write the concept as an ordinary word: lowercase, without code font or an element type. Use the class name in code font, with its element type, only when the sentence refers to the class or to objects created from it.
Examples
- ✓ A view draws one part of the screen and handles input in that area.
- ✓ To create a custom view, extend the
View class.
- ✓ The layout holds a tree of
View objects.
- ✗ A
View draws one part of the screen.
- ✗ A View draws one part of the screen.
- ✓ A component holds the data for one aspect of an entity.
Rationale
A class and the idea it models often share a name, so the reader needs to know whether a sentence describes the idea, which holds in any program, or the class that the code defines. Code font and the element type mark the class, and the plain word marks the idea.
Use code font for the names of API classes, interfaces, methods, functions, properties, constants, and parameters. Link a name to its reference page on its first mention in a section, and keep the code font in the link text; after the first link in a section, use code font alone. Don’t link the element that the page documents to its own page; write it in code font without a link, and link within the page only when the reader needs a different section.
Examples
- ✓ Creates a
Session object. (First mention in the section.)
- ✓ The
Session object expires after an hour. (Later mention in the same section: code font, no link.)
- ✗ Returns a Session object.
- ✗ On the
Component class page: The Component class holds one aspect of an entity.
Rationale
Code font marks the name as an identifier, and one link per section lets the reader jump to the element’s reference page without turning every mention into a link. A page that links to itself sends the reader nowhere.
Include links to related elements and additional resources on reference pages.
Examples
Rationale
Links to related elements help a reader move from one element to the neighboring elements they’re likely to need next.