summaryrefslogtreecommitdiffstats
path: root/CODING
diff options
context:
space:
mode:
authorTon Voon <tonvoon@users.sourceforge.net>2004-11-19 15:58:00 (GMT)
committerTon Voon <tonvoon@users.sourceforge.net>2004-11-19 15:58:00 (GMT)
commit870988ff0cde7aff6794e9a6a27904562cad9291 (patch)
treecb8ad5b7524d8213faf726fbb51f43c3a0a02c69 /CODING
parentd3d4440d89768fd13283e5daf5a9b338a8c11892 (diff)
downloadmonitoring-plugins-870988ff0cde7aff6794e9a6a27904562cad9291.tar.gz
Added perl coding guidelines, from Programming Perl book (Andreas Ericsson)
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@913 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'CODING')
-rw-r--r--CODING80
1 files changed, 79 insertions, 1 deletions
diff --git a/CODING b/CODING
index 634b6e5..1581065 100644
--- a/CODING
+++ b/CODING
@@ -4,6 +4,7 @@ code that is consistent with the existing core plugins.
4The primary goals of these standards are internal consistency, and 4The primary goals of these standards are internal consistency, and
5readability in a wide range of environments. 5readability in a wide range of environments.
6 6
7
71. C Language Programming 81. C Language Programming
8 9
9All code should comply with the requirements of the Free Software 10All code should comply with the requirements of the Free Software
@@ -33,6 +34,83 @@ characters
33e) The opening brace of an if or while block is on the same line as 34e) The opening brace of an if or while block is on the same line as
34the end of the conditional expression (the '-br' option). 35the end of the conditional expression (the '-br' option).
35 36
37
362. Perl Language Programming 382. Perl Language Programming
37 39
38<To Be Written> 40Taken from the O'Reilly book "Programming Perl" (3rd edition, pages 604-606) with
41modifications for clarity and to cohere with C coding standards.
42
43*) Always check the return code of system calls.
44
45a) Use tab indentation.
46
47b) Put space before the opening brace of a multiline block.
48
49c) A short block may be put on one line, including braces.
50
51d) Never omit the semicolon.
52
53e) Surround most operators with space.
54
55 $x = 5; # do this
56 $y=5; # don't do this
57
58f) Surround a "complex" subscript (inside brackets) with space.
59
60g) Put empty lines between chunks of code that do different things.
61
62*) Always check the return code of system calls.
63
64h) Put a newline between closing brace and else or elsif.
65
66i) Do not put space between a function name and its opening parenthesis.
67
68j) Do not put space before a semicolon.
69
70k) Put space after each comma.
71
72l) Break long lines after an operator (but before 'and' and 'or', even when
73spelled as && and ||)).
74
75*) Always check the return code of system calls.
76
77m) Line up corresponding items vertically.
78
79n) Use redundant parentheses only where it increases readability.
80
81o) An opening brace should be put on the same line as its preceding keyword,
82if possible; otherwise, line them up vertically.
83
84 while ($condition) {
85 # do something
86 }
87
88 while ($this_condition and $that_condition and $some_other_condition
89 and $this_really_really_really_long_condition)
90 {
91 # do something
92 }
93
94p) Do things the most readable way. For instance:
95
96 open(FOO, $foo) or die "Can't open $foo: $!";
97
98is better than
99
100 die "Can't open $foo: $!" unless open(FOO, $foo);
101
102because the second way hides the main point of the statement in a modifier.
103
104q) Just because an operator lets you assume default arguments doesn't mean
105that you should always use them. The defaults are there for lazy programmers
106writing one-shot, non-shared programs. If you want your program to be readable,
107consider supplying the argument.
108
109r) Choose mnemonic identifiers. That is, don't name your variables $h, $c
110and $w. Try $hostaddress, $critical and $warning instead ($host, $crit and
111$warn is OK too).
112
113s) Use underscore to split words in long identifiers. That is, use
114$service_port instead of $ServicePort as the former is much more readable.
115
116*) Always check the return code of system calls.