User Tools

Site Tools


metamod:perl_code_style

This is an old revision of the document!


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

FIXME

Script

FIXME

PHP Template

FIXME

metamod/perl_code_style.1278921968.txt.gz · Last modified: (external edit)