User Tools

Site Tools


code_formatting_standards

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
code_formatting_standards [2009/11/04 17:33] – created dbw2code_formatting_standards [2010/03/16 15:08] dbw2
Line 3: Line 3:
 ===== General Conventions ===== ===== General Conventions =====
 As a general rule, Evergreen contributions should follow these basic conventions. As a general rule, Evergreen contributions should follow these basic conventions.
-  * Code +  * Indents - tabs vs. spaces 
-    * Indents should be spaces +    * The general rule for all files needing indentation is space indents, no literal tabs 
-    * Lines should be kept at 80 characters or less if possible +    * The following file types are **exceptions** to this rule 
-    * Tokens should be separated by whitespace (i.e '$this = 1' not '$this=1'+      - Code written in C 
-    * Opening braces should be on the same line as the corresponding token <code>+      - Database schema/code files (.sql files) 
 +      - Makefiles 
 +      - Plain text files 
 +  * 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" <code>
 if ($this) { if ($this) {
     that();     that();
 +} else {
 +    something();
 }</code>not<code> }</code>not<code>
 if ($this) if ($this)
 { {
     that();     that();
 +}
 +else
 +{
 +    something()
 }</code> }</code>
 +  * Control structures should be followed by spaces, function names should not (see 'if' vs 'that' above)
  
 +===== Tool Specifics =====
 +==== Vim ====
 +The following Vim options or something similar (often set via .vimrc) will help with proper indentation:<code>
 +set tabstop=4
 +set softtabstop=4
 +set shiftwidth=4
 +set expandtab
 +set backspace=indent,eol,start
 +autocmd BufEnter ?akefile*,*txt,*out,*csv,*.c,*.h,*.sql set noet "use real tabs in Makefiles, text files, C code, and SQL files
 +</code>
 +In addition, the following VIM options have been recommended by a prominent Evergreen developer but are not actually format related :-) :<code>
 +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
 +</code>
  
 +==== perltidy ====
 +The following options are recommended when using perltidy to format your Perl code:
 +  * -b : Backup and modify in place
 +  * -ce : Enable the "cuddled else" style
 +Example: <code>perltidy -ce -b Object.pm</code> 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.txt · Last modified: 2022/02/10 13:34 by 127.0.0.1

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

© 2008-2022 GPLS and others. Evergreen is open source software, freely licensed under GNU GPLv2 or later.
The Evergreen Project is a U.S. 501(c)3 non-profit organization.