Coding guidelines

These rules apply to perl and php, unless otherwise mentioned.

General rules

spaces instead of tabs

indent is 4 spaces

cuddled else:

if ($a > $b) {
$a++;
} else {
$b++;
}

Line-length: usually <80 characters, not more than 120 chars

translate parameter from @_ to names in first line of sub

Documentation

POD(perl)/Doxygen(php) API documentation for modules, close to code

POD(perl) documentation for scripts (pod2usage)

Name-convention

variables: lower case, underscore splits words

constants: upper case, underscore splits words

functions: lower case, underscore splits words

modules/classes: upper case first, camel case splits words

Perltidy configuration

The following Perltidy configuration can be used as a guideline for formatting the code in Metamod.

# make some defaults explicit to document the decision
--indent-columns=4
--cuddled-else
--indent-block-comments
--paren-tightness=1
--square-bracket-tightness=1
--brace-tightness=1
--block-brace-tightness=0
-nbl
-nsbl
--static-block-comments
# deviations from the default
--maximum-line-length=120
--continuation-indentation=4
--opening-brace-always-on-right
--closing-token-indentation=0

Perl Template

Modules

Script

PHP Template