Coding Guidelines

From Integrics Wiki
Revision as of 16:53, 4 August 2017 by Acunningham (talk | contribs) (Initial version)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
  • All development
    • Use sentence case, without capital letters in the middle of sentences unless specifically required.
    • Comments should be limited to the following, unless there's a specific reason otherwise. Overuse of comments is discouraged.
      • A brief description at the top of files.
      • A copyright notice at the top of files.
      • A brief description of each 'paragraph' in long functions.
      • An explanation any section of code that may be counter-intuitive to someone reading the source.
  • Go specific
    • Always use "go fmt".
    • Always strip executables before distribution.
  • Perl specific
    • Use tabs instead of spaces for indentation.
    • Leave a space after negation: if ( ! $variable ) {
    • Leave a space after open bracket: if ( $variable ) {
    • Leave a space before close bracket: if ( $variable ) {
    • Do not leave a blank line after if, while, foreach, else, etc.
    • Do not leave a blank line before closing curly brackets of blocks.
    • Do not leave multiple consecutive blank lines.
    • If a list is very long, it should be spread across multiple lines. The last line before the closing round bracket should have a trailing comma.
    • Built-in Perl functions which can optionally have brackets, such as scalar(), should normally have brackets: scalar( @variable )
    • 'use' statements should be listed at the top of each file, in case-insensitive alphabetical order, unless otherwise necessary.
    • 'require' statements may be embedded within functions.
    • Hash references are normally given very short names, typically one letter, or two if necessary to be unambiguous.
    • Enumerated hash arrays should use " => " between keys and values, and ", " between values and keys.
    • Use of the Perl "<condition> ? <if true> : <if false>" construct is encouraged where thought appropriate.
    • Perl libraries should normally use @EXPORT_OK rather than @EXPORT.
    • Libraries should where possible name their functions starting with <library>_.