Debian Codegraph @

README-for-developers

raw
1 -------------------------------------------------
2 PLEASE ADHERE TO THESE RULES WHEN ADDING NEW CODE
3 -------------------------------------------------
4
5 This will help keep the code uniform and will greatly improve readability
6 of the code for new developers or old ones going back into the code after
7 several years.
8
9 -------------
10 GENERAL RULES
11 -------------
12
13 1) We follow HepMC 2 naming conventions:
14 - "snake_case" style of function and variable naming
15 - "CamelCase" style of class naming
16 - class/struct variables start from m_
17 - enum values are ALL-CAPS
18 - getters do not use 'get_' prefix
19 - setters use 'set_' prefix
20
21 2) Remember to mark 'const' functions accordingly
22
23 3) HepMC follows no-throw policy, as in: no part of the code
24 should throw an exception or use 'exit', etc. to end the program.
25 All critical cases should be checked and when needed,
26 an error should be printed.
27
28 4) Declare use of each std class separately.
29 'using std::vector' instead of 'using namespace std'
30
31 5) Use pre-defined macros for any text output outside of print() functions.
32 Precede any text with class and function name:
33
34 ERROR( "GenEvent::test: No particles in the event!" )
35 WARNING( "GenEvent::test: Only one particle present!" )
36 DEBUG( 3, "GenEvent::test: Has end vertex: " << (bool)end_vertex() )
37
38 DEBUG_CODE_BLOCK(
39 int x = 10*10;
40 DEBUG( 3, "GenEvent::test: This should be 100: " << x )
41 event->print();
42 )
43
44 6) Whenever you need an output for debugging, always use appropriately
45 commented DEBUG( 10, "info" ) block. This would make things easier if you
46 later decide it's worth to leave the debug info in the code.
47
48 7) DEBUG and DEBUG_CODE_BLOCK statements are not compile in release mode
49 so use them at will. To avoid information flooding use appropriate
50 debug levels for specific types of debug information:
51 - level 1 - critical, short info
52 - level 10 - less important, longer info
53
54 ------------
55 CODING STYLE
56 ------------
57
58 1) Do not use TABs to indent code.
59 2) Keep your code clean of trailing spaces
60 3) Keep in mind vertical code alignment. Especially in header files and
61 in variable initialization. Makes these sections much easier to quickly
62 glance over.
63
64 4) We use One True Brace Style, as in:
65
66 void function_name() {
67 // ...
68 }
69
70
71 --------------
72 COMMENTS STYLE
73 --------------
74
75 1) When writing a comment that goes into documentation, use
76 doxygen-style comments with keywords starting from '@', e.g.:
77
78 Comment block:
79
80 /**
81 * @file GenEvent.h
82 * @brief Definition of \b class GenEvent
83 *
84 * @class HepMC3::GenEvent
85 * @brief Stores event-related information
86 *
87 * Manages GenParticle and GenVertex objects
88 *
89 */
90
91 One-line comment:
92 int variable; //!< @todo This variable is probably useless
93
94 Parts that do not go into documentation (e.g. steps of an algorithm)
95 can be commented using usual // or /* */ comments.
96
97 2) Keep all of your code documented. Running: "cd doc/doxygen; make"
98 should give no warnings about missing documentation
99
100 3) Use @bug @todo keywords to mark problems found in the code. They go
101 on separate lists in the documentation so we can keep track of them
102 at any time. Remove these keywords after fixing the issue.