MySQL 8.0.33
Source Code Documentation
coding_guidelines.h
Go to the documentation of this file.
1/* Copyright (c) 2017, 2023, Oracle and/or its affiliates.
2
3This program is free software; you can redistribute it and/or modify
4it under the terms of the GNU General Public License, version 2.0,
5as published by the Free Software Foundation.
6
7This program is also distributed with certain software (including
8but not limited to OpenSSL) that is licensed under separate terms,
9as designated in a particular file or component or in included license
10documentation. The authors of MySQL hereby grant you an additional
11permission to link the program and your derivative works with the
12separately licensed software that they have included with MySQL.
13
14This program is distributed in the hope that it will be useful,
15but WITHOUT ANY WARRANTY; without even the implied warranty of
16MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17GNU General Public License, version 2.0, for more details.
18
19You should have received a copy of the GNU General Public License
20along with this program; if not, write to the Free Software
21Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
22
23/**
24 @page CPP_CODING_GUIDELINES_FOR_NDB_SE C++ Coding Guidelines for NDB Cluster
25
26 The ndbcluster plugin (storage/ndb/plugin) uses the same coding
27 style as the rest of the MySQL Server code.
28
29 The rest of the NDB code has a long history, and uses
30 many coding styles. When modifying and extending
31 existing source files or modules, the coding style already
32 used in that code should be followed in terms of
33 indentation, naming conventions, etc. For completely new
34 code, the MySQL Server conventions (with exceptions below)
35 should probably be followed.
36
37 Do not make changes to NDB code purely for the sake of
38 changing from one formatting style to another. It just causes
39 merge annoyances and makes patches harder to read, and we do
40 not expect the style to ever become 100% consistent across
41 all of the source code. However, it is okay to fix inconsistent
42 style in lines that are changed for other reasons.
43
44 One convention that should be followed for all new or
45 modified code is that class member variables should be named
46 with lowercase words separated by underscores '_', and prefixed
47 with 'm_'. Like this:
48 ~~~~~~~~~~~~~~~~
49 const char *m_my_class_member;
50 ~~~~~~~~~~~~~~~~
51
52 - @subpage BRACES
53 - @subpage ASSIGNMENT
54 - @subpage USE_OF_NDBREQUIRE
55*/
56
57/**
58 @page BRACES Braces
59
60 <p>if, while, etc. *must* always have braces, and each brace
61 should be on a separate line.</p>
62
63 Good example:
64 ~~~~~~~~~~~~~~~~
65 if (a == b)
66 {
67 dosomething();
68 }
69 ~~~~~~~~~~~~~~~~
70
71 Bad example:
72 ~~~~~~~~~~~~~~~~
73 if (a == b) {
74 dosomething();
75 }
76 ~~~~~~~~~~~~~~~~
77
78 Inline methods inside class (struct) are okay to write as shown
79 below (i.e., opening brace is on the same line as the function
80 declaration).
81 ~~~~~~~~~~~~~~~~
82 struct A
83 {
84 A() {
85 }
86 }
87 ~~~~~~~~~~~~~~~~
88*/
89
90/**
91 @page ASSIGNMENT Assignment
92 ~~~~~~~~~~~~~~~~
93 a = 3; // ok
94 a= 3; // not ok
95 ~~~~~~~~~~~~~~~~
96*/
97
98/**
99 @page USE_OF_NDBREQUIRE Use of ndbrequire
100
101 In the NDB kernel code, the ndbrequire() facility has
102 historically been widely used. However, most of this is now
103 considered misuse, and use of ndbrequire() should generally be
104 avoided. Over time, we want to remove most or all
105 ndbrequire() instances.
106
107 There are three different classes of ndbrequire() usage, with
108 corresponding replacement as follows:
109
110 - Verification of code logic: Hitting this is a real bug,
111 and the error message should be written accordingly. For this use, one
112 option is ndbassert() (only enabled in debug builds), or
113 we might need to add ndbchecklogic() or similar.
114
115 - Hitting a configurable limit, which cannot be handled
116 gracefully: For this, use ndbrequireErr(). The
117 error message should suggest a configuration change to correct the
118 problem, or refer to a section in the manual for
119 more information.
120
121 - Hitting hardcoded limits: We should really try to avoid
122 this, but if it is unavoidable, or if it is a limit we
123 think we will never hit, use ndbrequireErr() and add an
124 appropriate error message.
125*/