1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>56.1. Formatting</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets Vsnapshot" /><link rel="prev" href="source.html" title="Chapter 56. PostgreSQL Coding Conventions" /><link rel="next" href="error-message-reporting.html" title="56.2. Reporting Errors Within the Server" /></head><body id="docContent" class="container-fluid col-10"><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">56.1. Formatting</th></tr><tr><td width="10%" align="left"><a accesskey="p" href="source.html" title="Chapter 56. PostgreSQL Coding Conventions">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="source.html" title="Chapter 56. PostgreSQL Coding Conventions">Up</a></td><th width="60%" align="center">Chapter 56. PostgreSQL Coding Conventions</th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="error-message-reporting.html" title="56.2. Reporting Errors Within the Server">Next</a></td></tr></table><hr /></div><div class="sect1" id="SOURCE-FORMAT"><div class="titlepage"><div><div><h2 class="title" style="clear: both">56.1. Formatting</h2></div></div></div><p>
Source code formatting uses 4 column tab spacing, with
tabs preserved (i.e., tabs are not expanded to spaces).
Each logical indentation level is one additional tab stop.
</p><p>
Layout rules (brace positioning, etc.) follow BSD conventions. In
particular, curly braces for the controlled blocks of <code class="literal">if</code>,
<code class="literal">while</code>, <code class="literal">switch</code>, etc. go on their own lines.
</p><p>
Limit line lengths so that the code is readable in an 80-column window.
(This doesn't mean that you must never go past 80 columns. For instance,
breaking a long error message string in arbitrary places just to keep the
code within 80 columns is probably not a net gain in readability.)
</p><p>
To maintain a consistent coding style, do not use C++ style comments
(<code class="literal">//</code> comments). <span class="application">pgindent</span>
will replace them with <code class="literal">/* ... */</code>.
</p><p>
The preferred style for multi-line comment blocks is
</p><pre class="programlisting">
/*
* comment text begins here
* and continues here
*/
</pre><p>
Note that comment blocks that begin in column 1 will be preserved as-is
by <span class="application">pgindent</span>, but it will re-flow indented comment blocks
as though they were plain text. If you want to preserve the line breaks
in an indented block, add dashes like this:
</p><pre class="programlisting">
/*----------
* comment text begins here
* and continues here
*----------
*/
</pre><p>
</p><p>
While submitted patches do not absolutely have to follow these formatting
rules, it's a good idea to do so. Your code will get run through
<span class="application">pgindent</span> before the next release, so there's no point in
making it look nice under some other set of formatting conventions.
A good rule of thumb for patches is <span class="quote">“<span class="quote">make the new code look like
the existing code around it</span>”</span>.
</p><p>
The <code class="filename">src/tools/editors</code> directory contains sample settings
files that can be used with the <span class="productname">Emacs</span>,
<span class="productname">xemacs</span> or <span class="productname">vim</span>
editors to help ensure that they format code according to these
conventions.
</p><p>
If you'd like to run <span class="application">pgindent</span> locally
to help make your code match project style, see
the <code class="filename">src/tools/pgindent</code> directory.
</p><p>
The text browsing tools <span class="application">more</span> and
<span class="application">less</span> can be invoked as:
</p><pre class="programlisting">
more -x4
less -x4
</pre><p>
to make them show tabs appropriately.
</p></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="source.html" title="Chapter 56. PostgreSQL Coding Conventions">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="source.html" title="Chapter 56. PostgreSQL Coding Conventions">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="error-message-reporting.html" title="56.2. Reporting Errors Within the Server">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 56. PostgreSQL Coding Conventions </td><td width="20%" align="center"><a accesskey="h" href="index.html" title="PostgreSQL 15.7 Documentation">Home</a></td><td width="40%" align="right" valign="top"> 56.2. Reporting Errors Within the Server</td></tr></table></div></body></html>
|