Tech /

Minimalist Code Style





edit SideBar

Minimalist Code Style

Objective

A C coding style which:

  • is concise
  • minimizes diffs for common maintenance and refactoring tasks
  • is stable under automated indent tools (indent, uncrustify)
  • is generally independent of brace-style
  • easily greppable

Common Maintenance Tasks

  • Modify a function declaration
  • Modify a struct or enum

General

  • No horizontal alignment (this includes comment boxes)

List elements

Function parameter lists

  • Separate lines for:
    • Return and storage type
    • Function name
    • Parameters
  • Comma-decl style for parameters
extern return_type_t
Function(
         int param1
         , int param2
         , int param3
        );

Enumerations

  • Mandatory last element
enum Enumeration {
   ZEROTH = 0,   /**! Short description */
   FIRST = 1,
   SECOND = 2,

   /** Mandatory last element */
   LAST
};

Expressions

  • Separate lines for each argument
  • New indent for each sub-expression
    if (booleanA
        && booleanB
        || (booleanC
            && booleanD
           )
       )
    {

    }
Recent Changes (All) | Edit SideBar Page last modified on 18 August 2016, at 12:44 PM UTC Edit Page | Page History
Powered by PmWiki