summaryrefslogtreecommitdiff
path: root/devel/STYLE.rst
blob: 86c4df463a412929b9f69842f69f9ee49bfd25db (plain) (blame)
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
======================================
 Code Style Guide for Project Horizon
======================================
:Author:
  * **A. Wilcox**, documentation writer
:Copyright:
  © 2019 Adélie Linux Team.  CC BY-NC-SA-4.0 open source licence.



Introduction
============

This style guide describes how the program code for Project Horizon is
written and styled.

The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT",
"SHOULD", "SHOULD NOT", "RECOMMENDED",  "MAY", and "OPTIONAL" in this
document are to be interpreted as described in `RFC 2119`_.

.. _`RFC 2119`: https://tools.ietf.org/html/rfc2119



Directory Layout
================

Tools that are applicable for use in the Runtime Environment and the
Installation Environment MUST be placed in the ``tools`` directory, in their
own subdirectory.

Tools that are used in the Installation Environment only MUST be placed in a
new top-level directory.

Implementation of HorizonScript keys MUST be written in a file in the
``hscript`` directory that describes the general category of their purpose.
For example, a metadata key belongs in ``meta.cc``.  If a key does not fit in
to any of the categories that currently exist, a new category MUST be created
for it.



Code Style
==========

Naming Conventions
------------------

C++ classes MUST be in the ``Horizon::`` namespace, and MUST be in CamelCase.

Variables MUST be all lowercase with underscores separating words.


Indentation
-----------

Tab stops MUST be 4 spaces.  Hard tabs MUST NOT be used.

Parenthetical statements that span multiple lines MUST have their continuation
aligned after the parenthetical.  For example:

::
    if(this->function() == "Fox" &&
       that->function() != "Vulpes")


Layout
------

Opening curly braces MUST be on the same line as the last line of the statement
that they open.  Closing curly braces MUST be on a separate line.

Closing curly braces MUST be indented at the same level as the statement they
are closing.  For example:

::
    if(foo) {
        bar();
    }


Commenting
----------

Comments MUST be written in complete, concise English sentences.

Blocks of code that are directly traceable to a requirement SHOULD have a REQ
comment, such as:

::
    /* REQ: Runner.Validate.foo */
    valid = foo->validate();
    ...

All methods MUST have a comment preceding their definition explaining their
purpose.  Methods SHOULD also use Doxygen-style notation for describing their
parameters, return values (if any), and side-effects (if any).


Encapuslation
-------------

C++ classes that are meant to be public API (that is, consumed by external
software) MUST use the PImpl_ pattern to encapsulate their members.

.. _PImpl: https://en.cppreference.com/w/cpp/language/pimpl