This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
pod/.gitignore - remove redundant perlmacos.pod entry
[perl5.git] / pod / perldocstyle.pod
CommitLineData
4fb67a97
JM
1=encoding utf8
2
3=head1 NAME
4
5perldocstyle - A style guide for writing Perl's documentation
6
7=head1 DESCRIPTION
8
9This document is a guide for the authorship and maintenance of the
10documentation that ships with Perl. This includes the following:
11
12=over
13
14=item *
15
16The several dozen manual sections whose filenames begin with "C<perl>",
17such as C<perlobj>, C<perlre>, and C<perlintro>. (And, yes, C<perl>.)
18
19=item *
20
21The documentation for all the modules included with Perl (as listed by
22L<C<perlmodlib>|perlmodlib>).
23
24=item *
25
26The hundreds of individually presented reference sections derived from
27the L<C<perlfunc>|perlfunc> file.
28
29=back
30
31This guide will hereafter refer to user-manual section files as I<man
32pages>, per Unix convention.
33
34=head2 Purpose of this guide
35
36This style guide aims to establish standards, procedures, and philosophies
37applicable to Perl's core documentation.
38
39Adherence to these standards will help ensure that any one part of
40Perl's manual has a tone and style consistent with that of any other. As
41with the rest of the Perl project, the language's documentation
42collection is an open-source project authored over a long period of time
43by many people. Maintaining consistency across such a wide swath of work
44presents a challenge; this guide provides a foundation to help mitigate
45this difficulty.
46
47This will help its readers--especially those new to Perl--to feel
48more welcome and engaged with Perl's documentation, and this in turn
49will help the Perl project itself grow stronger through having a larger,
50more diverse, and more confident population of knowledgeable users.
51
52=head2 Intended audience
53
54Anyone interested in contributing to Perl's core documentation should
55familiarize themselves with the standards outlined by this guide.
56
57Programmers documenting their own work apart from the Perl project
58itself may also find this guide worthwhile, especially if they wish
59their work to extend the tone and style of Perl's own manual.
60
61=head2 Status of this document
62
63This guide was initially drafted in late 2020, drawing from the
64documentation style guides of several open-source technologies
65contemporary with Perl. This has included Python, Raku, Rust, and the
66Linux kernel.
67
68The author intends to see this guide used as starting place from
69which to launch a review of Perl's reams of extant documentation, with
70the expectation that those conducting this review should grow and modify
71this guide as needed to account for the requirements and quirks
72particular to Perl's programming manual.
73
74=head1 FUNDAMENTALS
75
76=head2 Choice of markup: Pod
77
78All of Perl's core documentation uses Pod ("Plain Old Documentation"), a
79simple markup language, to format its source text. Pod is similar in
80spirit to other contemporary lightweight markup technologies, such as
81Markdown and reStructuredText, and has a decades-long shared history
82with Perl itself.
83
84For a comprehensive reference to Pod syntax, see L<C<perlpod>|perlpod>.
85For the sake of reading this guide, familiarity with the Pod syntax for
86section headers (C<=head2>, et cetera) and for inline text formatting
87(C<CE<lt>like thisE<gt>>) should suffice.
88
89Perl programmers also use Pod to document their own scripts, libraries,
90and modules. This use of Pod has its own style guide, outlined by
91L<C<perlpodstyle>|perlpodstyle>.
92
93=head2 Choice of language: American English
94
95Perl's core documentation is written in English, with a preference for
96American spelling of words and expression of phrases. That means "color"
97over "colour", "math" versus "maths", "the team has decided" and not
98"the team have decided", and so on.
99
100We name one style of English for the sake of consistency across Perl's
101documentation, much as a software project might declare a four-space
102indentation standard--even when that doesn't affect how well the code
103compiles. Both efforts result in an easier read by avoiding jarring,
104mid-document changes in format or style.
105
106Contributors to Perl's documentation should note that this rule
107describes the ultimate, published output of the project, and does not
108prescribe the dialect used within community contributions. The
109documentation team enthusiastically welcomes any English-language
110contributions, and will actively assist in Americanizing spelling and
111style when warranted.
112
113=head3 Other languages and translations
114
115Community-authored translations of Perl's documentation do exist,
116covering a variety of languages. While the Perl project appreciates
117these translation efforts and promotes them when applicable, it does not
118officially support or maintain any of them.
119
120That said, keeping Perl's documentation clear, simple, and short has a
121welcome side effect of aiding any such translation project.
122
123(Note that the Chinese, Japanese, and Korean-language README files
124included with Perl's source distributions provide an exception to this
125choice of language--but these documents fall outside the scope of this
126guide.)
127
128=head2 Choice of encoding: UTF-8
129
130Perl's core documentation files are encoded in UTF-8, and can make use
131of the full range of characters this encoding allows.
132
133As such, every core doc file (or the Pod section of every core module)
134should commence with an C<=encoding utf8> declaration.
135
136=head2 Choice of underlying style guide: CMOS
137
138Perl's documentation uses the L<Chicago Manual of
139Style|https://www.chicagomanualofstyle.org> (CMOS), 17th Edition, as
140its baseline guide for style and grammar. While the document you are
141currently reading endeavors to serve as an adequate stand-alone style guide
142for the purposes of documenting Perl, authors should consider CMOS the
143fallback authority for any pertinent topics not covered here.
144
145Because CMOS is not a free resource, access to it is not a prerequisite
146for contributing to Perl's documentation; the doc team will help
147contributors learn about and apply its guidelines as needed. However, we
148do encourage anyone interested in significant doc contributions to
149obtain or at least read through CMOS. (Copies are likely available
150through most public libraries, and CMOS-derived fundamentals can be
151found online as well.)
152
153=head2 Contributing to Perl's documentation
154
155Perl, like any programming language, is only as good as its
156documentation. Perl depends upon clear, friendly, and thorough
157documentation in order to welcome brand-new users, teach and explain the
158language's various concepts and components, and serve as a lifelong
159reference for experienced Perl programmers. As such, the Perl project
160welcomes and values all community efforts to improve the language's
161documentation.
162
163Perl accepts documentation contributions through the same open-source
164project pipeline as code contributions. See L<C<perlhack>|perlhack> for
165more information.
166
167=head1 FORMATTING AND STRUCTURE
168
169This section details specific Pod syntax and style that all core Perl
170documentation should adhere to, in the interest of consistency and
171readability.
172
173=head2 Document structure
174
175Each individual work of core Perl documentation, whether contained
176within a C<.pod> file or in the Pod section of a standard code module,
177patterns its structure after a number of long-time Unix man page
178conventions. (Hence this guide's use of "man page" to refer to any one
179self-contained part of Perl's documentation.)
180
181Adhering to these conventions helps Pod formatters present a Perl man
182page's content in different contexts--whether a terminal, the web, or
183even print. Many of the following requirements originate with
184L<C<perlpodstyle>|perlpodstyle>, which derives its recommendations in
185turn from these well-established practices.
186
187=head3 Name
188
189After its L<C<=encoding utf8> declaration|/Choice of encoding: UTF-8>, a
190Perl man page I<must> present a level-one header named "NAME" (literally),
191followed by a paragraph containing the page's name and a very brief
192description.
193
194The first few lines of a notional page named C<perlpodexample>:
195
196 =encoding utf8
197
198 =head1 NAME
199
200 perlpodexample - An example of formatting a manual page's title line
201
202=head3 Description and synopsis
203
204Most Perl man pages also contain a DESCRIPTION section featuring a
205summary of, or introduction to, the document's content and purpose.
206
207This section should also, one way or another, clearly identify the
208audience that the page addresses, especially if it has expectations
209about the reader's prior knowledge. For example, a man page that dives
210deep into the inner workings of Perl's regular expression engine should
211state its assumptions up front--and quickly redirect readers who are
212instead looking for a more basic reference or tutorial.
213
214Reference pages, when appropriate, can precede the DESCRIPTION with a
215SYNOPSIS section that lists, within one or more code blocks, some very
216brief examples of the referenced feature's use. This section should show
217a handful of common-case and best-practice examples, rather than an
218exhaustive list of every obscure method or alternate syntax available.
219
220=head3 Other sections and subsections
221
222Pages should conclude, when appropriate, with a SEE ALSO section
223containing hyperlinks to relevant sections of Perl's manual, other Unix
224man pages, or appropriate web pages. Hyperlink each such cross-reference via
225C<LE<lt>...E<gt>>.
226
227What other sections to include depends entirely upon the topic at hand.
228Authors should feel free to include further C<=head1>-level sections,
229whether other standard ones listed by C<perlpodstyle>, or ones specific
230to the page's topic; in either case, render these top-level headings in
231all-capital letters.
232
233You may then include as many subsections beneath them as needed to meet
234the standards of clarity, accessibility, and cross-reference affinity
235L<suggested elsewhere in this guide|/Apply one of the four documentation
236modes>.
237
238=head3 Author and copyright
239
240In most circumstances, Perl's stand-alone man pages--those contained
241within C<.pod> files--do not need to include any copyright or license
242information about themselves. Their source Pod files are part of Perl's
243own core software repository, and that already covers them under the
244same copyright and license terms as Perl itself. You do not need to
245include additional "LICENSE" or "COPYRIGHT" sections of your own.
246
247These man pages may optionally credit their primary author, or include a
248list of significant contributors, under "AUTHOR" or "CONTRIBUTORS"
249headings. Note that the presence of authors' names does not preclude a
250given page from L<writing in a voice consistent with the rest of Perl's
251documentation|/The documentation speaks with one voice>.
252
253Note that these guidelines do not apply to the core software modules
254that ship with Perl. These have their own standards for authorship and
255copyright statements, as found in C<perlpodstyle>.
256
257=head2 Formatting rules
258
259=head3 Line length and line wrap
260
261Each line within a Perl man page's Pod source file should measure 72
262characters or fewer in length.
263
264Please break paragraphs up into blocks of short lines, rather than
265"soft wrapping" paragraphs across hundreds of characters with no line
266breaks.
267
268=head3 Code blocks
269
270Just like the text around them, all code examples should be as short and
271readable as possible, displaying no more complexity than absolutely
272necessary to illustrate the concept at hand.
273
274For the sake of consistency within and across Perl's man pages, all
275examples must adhere to the code-layout principles set out by
276L<C<perlstyle>|perlstyle>.
277
278Sample code should deviate from these standards only when necessary:
279during a demonstration of how Perl disregards whitespace, for example,
280or to temporarily switch to two-column indentation for an unavoidably
281verbose illustration.
282
283You may include comments within example code to further clarify or label
284the code's behavior in-line. You may also use comments as placeholder
285for code normally present but not relevant to the current topic, like
286so:
287
288 while (my $line = <$fh>) {
289 #
290 # (Do something interesting with $line here.)
291 #
292 }
293
294Even the simplest code blocks often require the use of example
295variables and subroutines, L<whose names you should choose with
296care|/Use meaningful variable and symbol names in examples>.
297
298=head3 Inline code and literals
299
300Within a paragraph of text, use C<CE<lt>...E<gt>> when quoting or
301referring to any bit of Perl code--even if it is only one character
302long.
303
304For instance, when referring within an explanatory paragraph to Perl's
305operator for adding two numbers together, you'd write "C<CE<lt>+E<gt>>".
306
307=head3 Function names
308
309Use C<CE<lt>...E<gt>> to render all Perl function names in monospace,
310whenever they appear in text.
311
312Unless you need to specifically quote a function call with a list of
313arguments, do not follow a function's name in text with a pair of empty
314parentheses. That is, when referring in general to Perl's C<print>
315function, write it as "C<print>", not "C<print()>".
316
317=head3 Function arguments
318
319Represent functions' expected arguments in all-caps, with no sigils, and
320using C<CE<lt>...E<gt>> to render them in monospace. These arguments
321should have short names making their nature and purpose clear.
322Convention specifies a few ones commonly seen throughout Perl's
323documentation:
324
325=over
326
327=item *
328
329EXPR
330
331The "generic" argument: any scalar value, or a Perl expression that
332evaluates to one.
333
334=item *
335
336ARRAY
337
338An array, stored in a named variable.
339
340=item *
341
342HASH
343
344A hash, stored in a named variable.
345
346=item *
347
348BLOCK
349
350A curly-braced code block, or a subroutine reference.
351
352=item *
353
354LIST
355
356Any number of values, stored across any number of variables or
357expressions, which the function will "flatten" and treat as a single
358list. (And because it can contain any number of variables, it must be
359the I<last> argument, when present.)
360
361=back
362
363When possible, give scalar arguments names that suggest their purpose
364among the arguments. See, for example, L<C<substr>'s
365documentation|perlfunc/substr>, whose
366listed arguments include C<EXPR>, C<OFFSET>, C<LENGTH>, and C<REPLACEMENT>.
367
368=head3 Apostrophes, quotes, and dashes
369
370In Pod source, use straight quotes, and not "curly quotes": "Like
371 this", not “like this”. The same goes for apostrophes: Here's a
372 positive example, and here’s a negative one.
373
374Render em dashes as two hyphens--like this:
375
376 Render em dashes as two hyphens--like this.
377
378Leave it up to formatters to reformat and reshape these punctuation
379marks as best fits their respective target media.
380
381=head3 Unix programs and C functions
382
383When referring to a Unix program or C function with its own man page
384(outside of Perl's documentation), include its manual section number in
385parentheses. For example: C<malloc(3)>, or C<mkdir(1)>.
386
387If mentioning this program for the first time within a man page or
388section, make it a cross reference, e.g. C<LE<lt>malloc(3)E<gt>>.
389
390Do not otherwise style this text.
391
392=head3 Cross-references and hyperlinks
393
394Make generous use of Pod's C<LE<lt>...E<gt>> syntax to create hyperlinks
395to other parts of the current man page, or to other documents entirely
396-- whether elsewhere on the reader's computer, or somewhere on the
397internet, via URL.
398
399Use C<LE<lt>...E<gt>> to link to another section of the current man page
400when mentioning it, and make use of its page-and-section syntax to link to
401the most specific section of a separate page within Perl's
402documentation. Generally, the first time you refer to a specific
403function, program, or concept within a certain page or section, consider
404linking to its full documentation.
405
406Hyperlinks do not supersede other formatting required by this guide; Pod
407allows nested text formats, and you should use this feature as needed.
408
409Here is an example sentence that mentions Perl's C<say> function, with a
410link to its documentation section within the C<perlfunc> man page:
411
412 In version 5.10, Perl added support for the
413 L<C<say>|perlfunc/say FILEHANDLE LIST> function.
414
415Note the use of the vertical pipe ("C<|>") to separate how the link will
416appear to readers ("C<CE<lt>sayE<gt>>") from the full page-and-section specifier
417that the formatter links to.
418
419=head3 Tables and diagrams
420
421Pod does not officially support tables. To best present tabular data,
422include the table as both HTML and plain-text representations--the
423latter as an indented code block. Use C<=begin> / C<=end> directives to
424target these tables at C<html> and C<text> Pod formatters, respectively.
425For example:
426
427 =head2 Table of fruits
428
429 =begin text
430
431 Name Shape Color
432 =====================================
433 Apple Round Red
434 Banana Long Yellow
435 Pear Pear-shaped Green
436
437 =end text
438
439 =begin html
440
441 <table>
442 <tr><th>Name</th><th>Shape</th><th>Color</th></tr>
443 <tr><td>Apple</td><td>Round</td><td>Red</td></tr>
444 <tr><td>Banana</td><td>Long</td><td>Yellow</td></tr>
445 <tr><td>Pear</td><td>Pear-shaped</td><td>Green</td></tr>
446 </table>
447
448 =end html
449
450The same holds true for figures and graphical illustrations. Pod does
451not natively support inline graphics, but you can mix HTML C<<< <img> >>> tags
452with monospaced text-art representations of those images' content.
453
454Due in part to these limitations, most Perl man pages use neither tables
455nor diagrams. Like any other tool in your documentation toolkit,
456however, you may consider their inclusion when they would improve an
457explanation's clarity without adding to its complexity.
458
459=head2 Adding comments
460
461Like any other kind of source code, Pod lets you insert comments visible
462only to other people reading the source directly, and ignored by the
463formatting programs that transform Pod into various human-friendly
464output formats (such as HTML or PDF).
465
466To comment Pod text, use the C<=for> and C<=begin> / C<=end> Pod
467directives, aiming them at a (notional) formatter called "C<comment>". A
468couple of examples:
469
470 =for comment Using "=for comment" like this is good for short,
471 single-paragraph comments.
472
473 =begin comment
474
475 If you need to comment out more than one paragraph, use a
476 =begin/=end block, like this.
477
478 None of the text or markup in this whole example would be visible to
479 someone reading the documentation through normal means, so it's
480 great for leaving notes, explanations, or suggestions for your
481 fellow documentation writers.
482
483 =end comment
484
485In the tradition of any good open-source project, you should make free
486but judicious use of comments to leave in-line "meta-documentation" as
487needed for other Perl documentation writers (including your future
488self).
489
490=head2 Perlfunc has special rules
491
492The L<C<perlfunc> man page|perlfunc>, an exhaustive reference of every
493Perl built-in function, has a handful of formatting rules not seen
494elsewhere in Perl's documentation.
495
496Software used during Perl's build process
497(L<Pod::Functions|Pod::Functions>) parses this page according to certain
498rules, in order to build separate man pages for each of Perl's
499functions, as well as achieve other indexing effects. As such,
500contributors to perlfunc must know about and adhere to its particular
501rules.
502
503Most of the perfunc man page comprises a single list, found under the
504header L<"Alphabetical Listing of Perl Functions"|perlfunc/Alphabetical
505Listing of Perl Functions>. Each function reference is an entry on that
506list, made of three parts, in order:
507
508=over
509
510=item 1.
511
512A list of C<=item> lines which each demonstrate, in template format, a
513way to call this function. One line should exist for every combination
514of arguments that the function accepts (including no arguments at all,
515if applicable).
516
517If modern best practices prefer certain ways to invoke the function
518over others, then those ways should lead the list.
519
520The first item of the list should be immediately followed by one or
521more C<XE<lt>...E<gt>> terms listing index-worthy topics; if nothing
522else, then the name of the function, with no arguments.
523
524=item 2.
525
526A C<=for> line, directed at C<Pod::Functions>, containing a one-line
527description of what the function does. This is written as a phrase, led
528with an imperative verb, with neither leading capitalization nor ending
529punctuation. Examples include "quote a list of words" and "change a
530filename".
531
532=item 3.
533
534The function's definition and reference material, including all
535explanatory text and code examples.
536
537=back
538
539Complex functions that need their text divided into subsections (under
540the principles of L<"Apply section-breaks and examples
541generously"|/Apply section-breaks and examples generously>) may do so by
542using sublists, with C<=item> elements as header text.
543
544A fictional function "C<myfunc>", which takes a list as an optional
545argument, might have an entry in perlfunc shaped like this:
546
547 =item myfunc LIST
548 X<myfunc>
549
550 =item myfunc
551
552 =for Pod::Functions demonstrate a function's perlfunc section
553
554 [ Main part of function definition goes here, with examples ]
555
556 =over
557
558 =item Legacy uses
559
560 [ Examples of deprecated syntax still worth documenting ]
561
562 =item Security considerations
563
564 [ And so on... ]
565
566 =back
567
568=head1 TONE AND STYLE
569
570=head2 Apply one of the four documentation modes
571
572Aside from "meta" documentation such as C<perlhist> or C<perlartistic>,
573each of Perl's man pages should conform to one of the four documentation
574"modes" suggested by L<I<The Documentation System> by Daniele
575Procida|https://documentation.divio.com>. These include tutorials,
576cookbooks, explainers, and references--terms that we define in further
577detail below.
578
579Each mode of documentation speaks to a different audience--not just
580people of different backgrounds and skill levels, but individual readers
581whose needs from language documentation can shift depending upon
582context. For example, a programmer with plenty of time to learn a new
583concept about Perl can ease into a tutorial about it, and later expand
584their knowledge further by studying an explainer. Later, that same
585programmer, wading knee-deep in live code and needing only to look up
586some function's exact syntax, will want to reach for a reference page
587instead.
588
589Perl's documentation must strive to meet these different situational
590expectations by limiting each man page to a single mode. This helps
591writers ensure they provide readers with the documentation needed or
592expected, despite ever-evolving situations.
593
594=head3 Tutorial
595
596A tutorial man page focuses on B<learning>, ideally by I<doing>. It
597presents the reader with small, interesting examples that allow them to
598follow along themselves using their own Perl interpreter. The tutorial
599inspires comprehension by letting its readers immediately experience
600(and experiment on) the concept in question. Examples include
601C<perlxstut>, C<perlpacktut>, and
602C<perlretut>.
603
604Tutorial man pages must strive for a welcoming and reassuring tone from
605their outset; they may very well be the first things that a newcomer to
606Perl reads, playing a significant role in whether they choose
607to stick around. Even an experienced programmer can benefit from the
608sense of courage imparted by a strong tutorial about a more advanced
609topic. After completing a tutorial, a reader should feel like they've
610been led from zero knowledge of its topic to having an invigorating
611spark of basic understanding, excited to learn more and experiment
612further.
613
614Tutorials can certainly use real-world examples when that helps make for
615clear, relatable demonstrations, so long as they keep the focus on
616teaching--more practical problem-solving should be left to the realm
617of cookbooks (as described below). Tutorials also needn't concern
618themselves with explanations into why or how things work beneath the
619surface, or explorations of alternate syntaxes and solutions; these are
620better handled by explainers and reference pages.
621
622=head3 Cookbook
623
624A cookbook man page focuses on B<results>. Just like its name suggests,
625it presents succinct, step-by-step solutions to a variety of real-world
626problems around some topic. A cookbook's code examples serve less to
627enlighten and more to provide quick, paste-ready solutions that the
628reader can apply immediately to the situation facing them.
629
630A Perl cookbook demonstrates ways that all the tools and techniques
631explained elsewhere can work together in order to achieve practical
632results. Any explanation deeper than that belongs in explainers and
633reference pages, instead. (Certainly, a cookbook can cross-reference
634other man pages in order to satisfy the curiosity of readers who, with
635their immediate problems solved, wish to learn more.)
636
637The most prominent cookbook pages that ship with Perl itself are its
638many FAQ pages, in particular C<perlfaq4> and up, which provide short
639solutions to practical questions in question-and-answer style.
640C<perlunicook> shows another example, containing a bevy of practical code
641snippets for a variety of internationally minded text manipulations.
642
643(An aside: I<The Documentation System> calls this mode "how-to", but
644Perl's history of creative cuisine prefers the more kitchen-ready term
645that we employ here.)
646
647=head3 Reference
648
649A reference page focuses on B<description>. Austere, uniform, and
650succinct, reference pages--often arranged into a whole section of
651mutually similar subpages--lend themselves well to "random access" by
652a reader who knows precisely what knowledge they need, requiring only
653the minimum amount of information before returning to the task at hand.
654
655Perl's own best example of a reference work is C<perlfunc>, the
656sprawling man page that details the operation of every function built
657into Perl, with each function's documentation presenting the same kinds
658of information in the same order as every other. For an example of a
659shorter reference on a single topic, look at C<perlreref>.
660
661Module documentation--including that of all the modules listed in
662L<C<perlmodlib>|perlmodlib>--also counts as reference. They follow
663precepts similar to those laid down by the C<perlpodstyle> man page, such
664as opening with an example-laden "SYNOPSIS" section, or featuring a
665"METHODS" section that succinctly lists and defines an object-oriented
666module's public interface.
667
668=head3 Explainer
669
670Explainer pages focus on B<discussion>. Each explainer dives as deep as
671needed into some Perl-relevant topic, taking all the time and space
672needed to give the reader a thorough understanding of it. Explainers
673mean to impart knowledge through study. They don't assume that the
674student has a Perl interpreter fired up and hungry for immediate examples
675(as with a tutorial), or specific Perl problems that they need quick
676answers for (which cookbooks and reference pages can help with).
677
678Outside of its reference pages, most of Perl's manual belongs to this
679mode. This includes the majority of the man pages whose names start with
680"C<perl>". A fine example is C<perlsyn>, the Perl Syntax page, which
681explores the whys and wherefores of Perl's unique syntax in a
682wide-ranging discussion laden with many references to the language's
683history, culture, and driving philosophies.
684
685Perl's explainer pages give authors a chance to explore Perl's penchant
686for L<TMTOWTDI|perlglossary/TMTOWTDI>, illustrating alternate and even
687obscure ways to use the language feature under discussion. However, as
688the remainder of this guide discusses, the ideal Perl documentation
689manages to deliver its message clearly and concisely, and not confuse
690mere wordiness for completeness.
691
692=head3 Further notes on documentation modes
693
694Keep in mind that the purpose of this categorization is not to dictate
695content--a very thorough explainer might contain short reference
696sections of its own, for example, or a reference page about a very
697complex function might resemble an explainer in places (e.g.
698L<C<open>|perlfunc/open FILEHANDLE,MODE,EXPR>). Rather, it makes sure
699that the authors and contributors of any given man page agree on what
700sort of audience that page addresses.
701
702If a new or otherwise uncategorized man page presents itself as
703resistant to fitting into only one of the four modes, consider breaking
704it up into separate pages. That may mean creating a new "C<perl[...]>"
705man page, or (in the case of module documentation) making new packages
706underneath that module's namespace that serve only to hold additional
707documentation. For instance, C<Example::Module>'s reference documentation
708might include a see-also link to C<Example::Module::Cookbook>.
709
710Perl's several man pages about Unicode--comprising a short tutorial, a
711thorough explainer, a cookbook, and a FAQ--provide a fine example of
712spreading a complicated topic across several man pages with different
713and clearly indicated purposes.
714
715=head2 Assume readers' intelligence, but not their knowledge
716
717Perl has grown a great deal from its humble beginnings as a tool for
718people already well versed in C programming and various Unix utilities.
719Today, a person learning Perl might come from any social or
720technological background, with a range of possible motivations
721stretching far beyond system administration.
722
723Perl's core documentation must recognize this by making as few
724assumptions as possible about the reader's prior knowledge. While you
725should assume that readers of Perl's documentation are smart, curious,
726and eager to learn, you should not confuse this for pre-existing
727knowledge about any other technology, or even programming in
728general--especially in tutorial or introductory material.
729
730=head3 Keep Perl's documentation about Perl
731
732Outside of pages tasked specifically with exploring Perl's relationship
733with other programming languages, the documentation should keep the
734focus on Perl. Avoid drawing analogies to other technologies that the
735reader may not have familiarity with.
736
737For example, when documenting one of Perl's built-in functions, write as
738if the reader is now learning about that function for the first time, in
739any programming language.
740
741Choosing to instead compare it to an equivalent or underlying C function
742will probably not illuminate much understanding in a contemporary
743reader. Worse, this can risk leaving readers unfamiliar with C feeling
744locked out from fully understanding of the topic--to say nothing of
745readers new to computer programming altogether.
746
747If, however, that function's ties to its C roots can lead to deeper
748understanding with practical applications for a Perl programmer, you may
749mention that link after its more immediately useful documentation.
750Otherwise, omit this information entirely, leaving it for other
751documentation or external articles more concerned with examining Perl's
752underlying implementation details.
753
754=head3 Deploy jargon when needed, but define it as well
755
756Domain-specific jargon has its place, especially within documentation.
757However, if a man page makes use of jargon that a typical reader might
758not already know, then that page should make an effort to define the
759term in question early-on--either explicitly, or via cross reference.
760
761For example, Perl loves working with filehandles, and as such that word
762appears throughout its documentation. A new Perl programmer arriving at
763a man page for the first time is quite likely to have no idea what a
764"filehandle" is, though. Any Perl man page mentioning filehandles
765should, at the very least, hyperlink that term to an explanation
766elsewhere in Perl's documentation. If appropriate--for example, in the
767lead-in to L<C<open> function's detailed reference|perlfunc/open
768FILEHANDLE,MODE,EXPR>--it can also include a very short in-place
769definition of the concept for the reader's convenience.
770
771=head2 Use meaningful variable and symbol names in examples
772
773When quickly sketching out examples, English-speaking programmers have a
774long tradition of using short nonsense words as placeholders for
775variables and other symbols--such as the venerable C<foo>, C<bar>, and
776C<baz>. Example code found in a programming language's official,
777permanent documentation, however, can and should make an effort to
778provide a little more clarity through specificity.
779
780Whenever possible, code examples should give variables, classes, and
781other programmer-defined symbols names that clearly demonstrate their
782function and their relationship to one another. For example, if an
783example requires that one class show an "is-a" relationship with
784another, consider naming them something like C<Apple> and C<Fruit>, rather
785than C<Foo> and C<Bar>. Similarly, sample code creating an instance of
786that class would do better to name it C<$apple>, rather than C<$baz>.
787
788Even the simplest examples benefit from clear language using concrete
789words. Prefer a construct like C<for my $item (@items) { ... }> over
790C<for my $blah (@blah) { ... }>.
791
792=head2 Write in English, but not just for English-speakers
793
794While this style guide does specify American English as the
795documentation's language for the sake of internal consistency, authors
796should avoid cultural or idiomatic references available only to
797English-speaking Americans (or any other specific culture or society).
798As much as possible, the language employed by Perl's core documentation
799should strive towards cultural universality, if not neutrality. Regional
800turns of phrase, examples drawing on popular-culture knowledge, and
801other rhetorical techniques of that nature should appear sparingly, if
802at all.
803
804Authors should feel free to let more freewheeling language flourish in
805"second-order" documentation about Perl, like books, blog entries, and
806magazine articles, published elsewhere and with a narrower readership in
807mind. But Perl's own docs should use language as accessible and
808welcoming to as wide an audience as possible.
809
810=head2 Omit placeholder text or commentary
811
812Placeholder text does not belong in the documentation that ships with
813Perl. No section header should be followed by text reading only "Watch
814this space", "To be included later", or the like. While Perl's source
815files may shift and alter as much as any other actively maintained
816technology, each released iteration of its technology should feel
817complete and self-contained, with no such future promises or other loose
818ends visible.
819
820Take advantage of Perl's regular release cycle. Instead of cluttering
821the docs with flags promising more information later--the presence of
822which do not help readers at all today--the documentation's
823maintenance team should treat any known documentation absences as an
824issue to address like any other in the Perl project. Let Perl's
825contributors, testers, and release engineers address that need, and
826resist the temptation to insert apologies, which have all the utility in
827documentation as undeleted debug messages do in production code.
828
829=head2 Apply section-breaks and examples generously
830
831No matter how accessible their tone, the sight of monolithic blocks of
832text in technical documentation can present a will-weakening challenge
833for the reader. Authors can improve this situation through breaking long
834passages up into subsections with short, meaningful headers.
835
836Since every section-header in Pod also acts as a potential end-point for
837a cross-reference (made via Pod's C<LE<lt>...E<gt>> syntax), putting
838plenty of subsections in your documentation lets other man pages more
839precisely link to a particular topic. This creates hyperlinks directly
840to the most appropriate section rather than to the whole page in
841general, and helps create a more cohesive sense of a rich, consistent,
842and interrelated manual for readers.
843
844Among the four documentation modes, sections belong more naturally in
845tutorials and explainers. The step-by-step instructions of cookbooks, or
846the austere definitions of reference pages, usually have no room for
847them. But authors can always make exceptions for unusually complex
848concepts that require further breakdown for clarity's sake.
849
850Example code, on the other hand, can be a welcome addition to any mode
851of documentation. Code blocks help break up a man page visually,
852reassuring the reader that no matter how deep the textual explanation
853gets, they are never far from another practical example showing how it
854all comes together using a small, easy-to-read snippet of tested Perl
855code.
856
857=head2 Lead with common cases and best practices
858
859Perl famously gives programmers more than one way to do things. Like any
860other long-lived programming language, Perl has also built up a large,
861community-held notion of best practices, blessing some ways to do things
862as better than others, usually for the sake of more maintainable code.
863
864=head3 Show the better ways first
865
866Whenever it needs to show the rules for a technique which Perl provides
867many avenues for, the documentation should always lead with best
868practices. And when discussing some part of the Perl toolkit with many
869applications, the docs should begin with a demonstration of its
870application to the most common cases.
871
872The C<open> function, for example, has myriad potential uses within Perl
873programs, but I<most of the time> programmers--and especially those new
874to Perl--turn to this reference because they simply wish to open a
875file for reading or writing. For this reason, C<open>'s documentation
876begins there, and only descends into the function's more obscure uses
877after thoroughly documenting and demonstrating how it works in the
878common case. Furthermore, while engaging in this demonstration, the
879C<open> documentation does not burden the reader right away with detailed
880explanations about calling C<open> via any route other than the
881best-practice, three-argument style.
882
883=head3 Show the lesser ways when needed
884
885Sometimes, thoroughness demands documentation of deprecated techniques.
886For example, a certain Perl function might have an alternate syntax now
887considered outmoded and no longer best-practice, but which a maintainer
888of a legacy project might quite reasonably encounter when exploring old
889code. In this case, these features deserve documentation, but couched in
890clarity that modern Perl avoids such structures, and does not recommend
891their use in new projects.
892
893Another way to look at this philosophy (and one L<borrowed from our
894friends|https://devguide.python.org/documenting/#affirmative-tone> on
895Python's documentation team) involves writing while sympathizing with a
896programmer new to Perl, who may feel uncertain about learning a complex
897concept. By leading that concept's main documentation with clear,
898positive examples, we can immediately give these readers a simple and
899true picture of how it works in Perl, and boost their own confidence to
900start making use of this new knowledge. Certainly we should include
901alternate routes and admonitions as reasonably required, but we needn't
902emphasize them. Trust the reader to understand the basics quickly, and
903to keep reading for a deeper understanding if they feel so driven.
904
905=head2 Document Perl's present
906
907Perl's documentation should stay focused on Perl's present behavior,
908with a nod to future directions.
909
910=head3 Recount the past only when necessary
911
912=for comment
913The principles of this section caused a lot of lively discussion and
914debate among p5p when first proposed in October 2020. I am keeping the
915recommendations nonspecific, and expect this section to receive a lot of
916further refinement as we start to apply it to core docs.
917
918When some Perl feature changes its behavior, documentation about
919that feature should change too, and just as definitively. The docs have
920no obligation to keep descriptions of past behavior hanging around, even if
921attaching clauses like "Prior to version 5.10, [...]".
922
923Since Perl's core documentation is part of Perl's source distribution,
924it enjoys the same benefits of versioning and version-control as the
925source code of Perl itself. Take advantage of this, and update the text
926boldly when needed. Perl's history remains safe, even when you delete or
927replace outdated information from the current version's docs.
928
929Perl's docs can acknowledge or discuss former behavior when warranted,
930including notes that some feature appeared in the language as of some
931specific version number. Authors should consider applying principles
932similar to those for deprecated techniques, L<as described above|/Show
933the lesser ways when needed>: make the information present, but not
934prominent.
935
936Otherwise, keep the past in the past. A manual uncluttered with
937outdated instruction stays more succinct and relevant.
938
939=head3 Describe the uncertain future with care
940
941Perl features marked as "experimental"--those that generate warnings
942when used in code not invoking the L<C<experimental>|experimental>
943pragma--deserve documentation, but only in certain contexts, and even
944then with caveats. These features represent possible new directions for
945Perl, but they have unstable interfaces and uncertain future presence.
946
947The documentation should take both implications of "experimental"
948literally. It should not discourage these features' use by programmers
949who wish to try out new features in projects that can risk their
950inherent instability; this experimentation can help Perl grow and
951improve. By the same token, the docs should downplay these features' use
952in just about every other context.
953
954Introductory or overview material should omit coverage of experimental
955features altogether.
956
957More thorough reference materials or explanatory articles can include
958experimental features, but needs to clearly mark them as such, and not
959treat them with the same prominence as Perl's stable features. Using
960unstable features seldom coincides with best practices, and
961documentation that L<puts best practices first|/Lead with common cases
962and best practices> should reflect this.
963
964=head2 The documentation speaks with one voice
965
966Even though it comes from many hands and minds, criss-crossing through
967the many years of Perl's lifetime, the language's documentation should
968speak with a single, consistent voice. With few exceptions, the docs
969should avoid explicit first-person-singular statements, or similar
970self-reference to any individual's contributor's philosophies or
971experiences.
972
973Perl did begin life as a deeply personal expression by a single
974individual, and this famously carried through the first revisions of its
975documentation as well. Today, Perl's community understands that the
976language's continued development and support comes from many people
977working in concert, rather than any one person's vision or effort. Its
978documentation should not pretend otherwise.
979
980The documentation should, however, carry forward the best tradition that
981Larry Wall set forth in the language's earliest days: Write both
982economically and with a humble, subtle wit, resulting in a technical
983manual that mixes concision with a friendly approachability. It avoids
984the dryness that one might expect from technical documentation, while
985not leaning so hard into overt comedy as to distract and confuse from
986the nonetheless-technical topics at hand.
987
988Like the best written works, Perl's documentation has a soul. Get
989familiar with it as a reader to internalize its voice, and then find
990your own way to express it in your own contributions. Writing clearly,
991succinctly, and with knowledge of your audience's expectations will get
992you most of the way there, in the meantime.
993
994Every line in the docs--whether English sentence or Perl
995statement--should serve the purpose of bringing understanding to the
996reader. Should a sentence exist mainly to make a wry joke that doesn't
997further the reader's knowledge of Perl, set it aside, and consider
998recasting it into a personal blog post or other article instead.
999
1000Write with a light heart, and a miserly hand.
1001
1002=head1 INDEX OF PREFERRED TERMS
1003
1004L<As noted above|/Choice of underlying style guide: CMOS>, this guide
1005"inherits" all the preferred terms listed in the Chicago Manual of
1006Style, 17th edition, and adds the following terms of particular interest
1007to Perl documentation.
1008
1009=over
1010
1011=item built-in function
1012
1013Not "builtin".
1014
1015=item Darwin
1016
1017See L<macOS|/macOS>.
1018
1019=item macOS
1020
1021Use this term for Apple's operating system instead of "Mac OS X" or
1022variants thereof.
1023
1024This term is also preferable to "Darwin", unless one needs to refer
1025to macOS's Unix layer specifically.
1026
1027=item man page
1028
1029One unit of Unix-style documentation. Not "manpage". Preferable to "manual page".
1030
1031=item Perl; perl
1032
1033The name of the programming language is Perl, with a leading capital
1034"P", and the remainder in lowercase. (Never "PERL".)
1035
1036The interpreter program that reads and executes Perl code is named
1037"C<perl>", in lowercase and in monospace (as with any other command
1038name).
1039
1040Generally, unless you are specifically writing about the
440416fb 1041command-line C<perl> program (as, for example, L<C<perlrun>|perlrun>
4fb67a97
JM
1042does), use "Perl" instead.
1043
1044=item Perl 5
1045
1046Documentation need not follow Perl's name with a "5", or any other
1047number, except during discussions of Perl's history, future plans,
1048or explicit comparisons between major Perl versions.
1049
1050Before 2019, specifying "Perl 5" was sometimes needed to distinguish
1051the language from Perl 6. With the latter's renaming to "Raku", this
1052practice became unnecessary.
1053
1054=item Perl 6
1055
1056See L<Raku|/Raku>.
1057
1058=item Perl 5 Porters, the; porters, the; p5p
1059
1060The full name of the team responsible for Perl's ongoing maintenance
1061and development is "the Perl 5 Porters", and this sobriquet should
1062be spelled out in the first mention within any one document. It may
1063thereafter call the team "the porters" or "p5p".
1064
1065Not "Perl5 Porters".
1066
1067=item program
1068
1069The most general descriptor for a stand-alone work made out of
1070executable Perl code. Synonymous with, and preferable to, "script".
1071
1072=item Raku
1073
1074Perl's "sister language", whose homepage is L<https://raku.org>.
1075
1076Previously known as "Perl 6". In 2019, its design team renamed the
1077language to better reflect its identity as a project independent from
1078Perl. As such, Perl's documentation should always refer to this language
1079as "Raku" and not "Perl 6".
1080
1081=item script
1082
1083See L<program|/program>.
1084
1085=item semicolon
1086
1087Perl code's frequently overlooked punctuation mark. Not "semi-colon".
1088
1089=item Unix
1090
1091Not "UNIX", "*nix", or "Un*x". Applicable to both the original operating
1092system from the 1970s as well as all its conceptual descendants. You may
1093simply write "Unix" and not "a Unix-like operating system" when
1094referring to a Unix-like operating system.
1095
1096=back
1097
1098=head1 SEE ALSO
1099
1100=over
1101
1102=item *
1103
1104L<perlpod|perlpod>
1105
1106=item *
1107
1108L<perlpodstyle|perlpodstyle>
1109
1110=back
1111
1112=head1 AUTHOR
1113
1114This guide was initially drafted by Jason McIntosh
1115(jmac@jmac.org), under a grant from The Perl Foundation.
1116
1117=for comment Additional contributors can get listed here (and this
1118comment deleted), when there are some.