My favorites | Sign in
Logo
                
Search
for
Updated Mar 14, 2009 by mark.sch...@gmail.com
CodingStandards  
Maatkit Coding Standards

Introduction

Coding standards provide consistently formatted source code that makes it easier to create commercial grade Perl programs that are easier to understand, modify, maintain and used by others. There are plenty standards available, but we believe the following standard is easy to implement. With a properly configured editor, there’s no need for manual formatting of Perl code. Let your editor do the heavy lifting.

Getting Started

The defacto standard for developing Perl programs is the Dog book, formally, Perl Best Practices by Damian Conway, http://oreilly.com/catalog/9780596001735/. Maatkit coding standard implements as much of the Dog book as possible.

Configuring VIM

VIM can be configured as a Perl IDE by installing the perl-support plug-in. Perl-support can be found:

http://www.vim.org/scripts/script.php?script_id=556

Example .vimrc or .gvimrc file

set autoindent                    "Preserve current indent on new lines
set textwidth=78                  "Wrap at this column
set backspace=indent,eol,start    "Make backspaces delete sensibly
 
set tabstop=3                     "Indentation levels every three columns
set expandtab                     "Convert all tabs typed to spaces
set shiftwidth=3                  "Indent/outdent by three columns
set shiftround                    "Indent/outdent to nearest tabstop
 
set matchpairs+=<:>               "Allow % to bounce between angles too

set iskeyword+=:                  "Perl double colons are valid part of
                                  "identifiers.

set lines=40
set columns=85
set number

set statusline=%<%f%h%m%r%=%{&ff}\ %l,%c%V\ %P

filetype plugin on

"reread .vimrc file after editing
autocmd BufWritePost $HOME/.vimrc source $HOME/.vimrc

" use visual bell instead of beeping
set vb

" incremental search
set incsearch

" syntax highlighting
set bg=light
syntax on

" autoindent
autocmd FileType perl set autoindent|set smartindent

" show matching brackets
autocmd FileType perl set showmatch

" check perl code with :make
"autocmd FileType perl set makeprg=perl\ -c\ %\ $*
"autocmd FileType perl set errorformat=%f:%l:%m
"autocmd FileType perl set autowrite

" dont use Q for Ex mode
map Q :q

" make tab in v mode ident code
vmap <tab> >gv
vmap <s-tab> <gv

" make tab in normal mode ident code
nmap <tab> I<tab><esc>
nmap <s-tab> ^i<bs><esc>

" paste mode - this will avoid unexpected effects when you
" cut or copy some text from one window and paste it in Vim.
set pastetoggle=<F11>

" Tlist Config
nnoremap <silent> <F8> :TlistToggle<CR>

" perltidy mappings
map <F2> <ESC>:%! perltidy<CR>
map <F3> <ESC>:'<,'>! perltidy<CR>

" Perl test files as Perl code
au BufRead,BufNewFile *.t set ft=perl

“perl-support plugin info
let g:Perl_AuthorName   = ''
let g:Perl_AutherRef    = ''
let g:Perl_Email        = ''

Configuring Emacs

TODO – I don’t use Emacs, if you do and could write up how to configure for the Maatkit standard, please email me: mark.schoonover@gmail.com

Configuring Your_favorite_editor

TODO - If you use an editor that’s not listed above, I’d like to hear from you. Since Maatkit runs on a wide range of operating systems, I’d like to document those editors that are popular on those systems. For example, Mac OSX.

Tidying Up

PerlTidy, http://perltidy.sourceforge.net/ is a tool to format Perl code.

Example .perltidyrc file:

-l=78   # Max line width is 78 cols
-i=3    # Indent level is 4 cols
-ci=3   # Continuation indent is 4 cols
-st     # Output to STDOUT
-se     # Errors to STDERR
-vt=2   # Maximal vertical tightness
-cti=0  # No extra indentation for closing brackets
-pt=1   # Medium parenthesis tightness
-bt=1   # Medium brace tightness
-sbt=1  # Medium square bracket tightness
-bbt=1  # Medium block brace tightness
-nsfs   # No space before semicolons
-nolq   # Don't outdent long quoted strings
-wbb="% + - * / x != == >= <= =~ !~ < > | & >= < = **= += *= &= <<= &&= -= /= |= >>= ||= .= %= ^= x="   

Perl Program Template

A Maatkit skeleton file can be found in:

skeleton/skeleton.pl

Module Template

A Maatkit Perl module template can be found here: http://code.google.com/p/maatkit/source/detail?r=3165

Additional Information

Common Module Abbreviations: http://code.google.com/p/maatkit/wiki/CommonModuleAbbreviations

Hosted by Google Code