code_formatting_standards
This is an old revision of the document!
Table of Contents
Code Formatting Standards
This page is a work in progress and currently NOT official!
General Conventions
As a general rule, Evergreen contributions should follow these basic conventions.
- Code
- Indents should be 4 spaces
- Lines should be kept at 80 characters or less if possible
- Tokens should be separated by whitespace (i.e '$this = 1' not '$this=1')
- Opening braces should be on the same line as the corresponding token and 'else' should be "cuddled"
if ($this) { that(); } else { something(); }
not
if ($this) { that(); } else { something() }
- Control structures should be followed by spaces, function names should not (see 'if' vs 'that' above)
- XML files
- (4 space indents as well?)
- Text files
- Basic text files may use actual tab characters as needed
Tool Specifics
Vim
The following Vim options or something similar (often set via .vimrc) will help with proper indentation:
set tabstop=4 set softtabstop=4 set shiftwidth=4 set expandtab set backspace=indent,eol,start autocmd BufEnter ?akefile* set noet ts=4 sw=4 "use real tabs in Makefiles autocmd BufEnter *txt set noet ts=4 sw=4 "use real tabs in txt files autocmd BufEnter *out set noet ts=4 sw=4 "use real tabs in txt files autocmd BufEnter *csv set noet ts=4 sw=4 "use real tabs in txt files
In addition, the following VIM options have been recommended by a prominent Evergreen developer but are not actually format related :
set hlsearch vnoremap < <gv vnoremap > >gv set nobk set whichwrap=b,s,<,>,[,] set smartcase filetype on syntax enable au BufNewFile,BufRead *.xhtml setf html au BufNewFile,BufRead *.bsh setf java au BufNewFile,BufRead *.ftl setf html set bg=dark let loaded_matchparen = 1
perltidy
The following options are recommended for using perltidy to format your Perl code:
- -b : Backup and modify in place
- -ce : Enable the "cuddled else" style
Example:
perltidy -ce -b Object.pm
This will tidy Object.pm and move your original to Object.pm.bak. Note that this will clobber an existing Object.pm.bak file!
code_formatting_standards.1257376146.txt.gz · Last modified: 2022/02/10 13:33 (external edit)