User Tools

Site Tools


code_formatting_standards

Differences

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

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
code_formatting_standards [2009/11/04 18:09] dbw2code_formatting_standards [2022/02/10 13:34] (current) – external edit 127.0.0.1
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 and 'else' should be "cuddled" <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();
Line 21: Line 25:
     something()     something()
 }</code> }</code>
-    * Control structures should be followed by spaces, function names should not (see 'if' vs 'that' above) +  * Control structures should be followed by spaces, function names should not (see 'if' vs 'that' above)
-  * XML files +
-    * FIXME (4 space indents as well?) +
-  * Text files +
-    * Basic text files may use actual tab characters as needed+
  
 ===== Tool Specifics ===== ===== Tool Specifics =====
Line 35: Line 35:
 set expandtab set expandtab
 set backspace=indent,eol,start set backspace=indent,eol,start
-autocmd BufEnter ?akefile* set noet ts=4 sw=4  "use real tabs in Makefiles +autocmd BufEnter ?akefile*,*txt,*out,*csv,*.c,*.h,*.sql set noet "use real tabs in Makefiles, text files, C code, and SQL files
-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+
 </code> </code>
 In addition, the following VIM options have been recommended by a prominent Evergreen developer but are not actually format related :-) :<code> In addition, the following VIM options have been recommended by a prominent Evergreen developer but are not actually format related :-) :<code>
Line 55: Line 52:
 let loaded_matchparen = 1 let loaded_matchparen = 1
 </code> </code>
 +
 +==== GNU Emacs ====
 +
 +Add the following lines to your .emacs file and your code will meet the above standards for Perl.
 +
 +<code>
 +; Use cperl-mode by default
 +(defalias 'perl-mode 'cperl-mode)
 +
 +; cperl-mode doesn't have an add-style command, so we create our
 +; style in a defun.
 +(defun evergreen-perl-style ()
 +  "Set cperl-mode for Evergreen coding guidelines."
 +  (setq cperl-indent-level  4
 + cperl-brace-offset 0
 + cperl-continued-brace-offset 0
 + cperl-label-offset -4
 + cperl-continued-statement-offset 4
 + cperl-close-paren-offset -4
 + cperl-indent-parens-as-block t
 + cperl-tab-always-indent t
 + cperl-merge-trailing-else t
 + cperl-left-aligned-indent-comments t
 + indent-tabs-mode nil))
 +  
 +; cperl-mode hook
 +(add-hook 'cperl-mode-hook
 +   (lambda ()
 +     (evergreen-perl-style)))
 +</code>
 +
 +The above will use these style guidelines on all of your Perl sources. More advanced users might want to configure other styles for different projects and check buffer-file-name to switch styles on a per-buffer basis. You might also want to look into setting many of the cperl-electric-* variables or cperl-hairy. They add a lot of neat features for automatic code completion in Perl.
  
 ==== perltidy ==== ==== perltidy ====
-The following options are recommended for using perltidy to format your Perl code:+The following options are recommended when using perltidy to format your Perl code:
   * -b : Backup and modify in place   * -b : Backup and modify in place
   * -ce : Enable the "cuddled else" style   * -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! 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.1257376146.txt.gz · Last modified: 2022/02/10 13:33 (external edit)

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.