Sunday, January 12, 2014

Programming Style

Every programmer will have a style of programming, the way they write the programs. But, when you work as a team, it would be very useful if you and your team follow one 'programming style' for code readability and consistency. 
Here are some of the standard practices:
  • Adhere to the existing style
    • If a source file already has a style, please adhere to the existing style
  • Indent Code Blocks
    • Use 4 space indented code blocks, making it 4 spaces make room of more code within 80 columns.
    •  Use expanded tabs. By this way your code won't look different in different environments
  • Follow only one brace-opening style
    • C++ Style
      if.(...).{
       ... 
      }
    • C Style(K&R)
      if.(...) 

      ... 
      }
  • Use White-spaces between keywords, variables, operators for better readability
    if.(x.>.10).{ 
    ... 
    }
  • Use a Standard Naming Convention
    • Use uppercase for macros
    • Add prefix for macros within a module to avoid conflict with global
    • "UpperCamelCase" for classes, structs, enums, constants and typedefs (use nouns)
    • "lowerCamelCase" for functions, variables, parameters  even for abbreviations (use verb for function names)
    • Use 'get', 'set' - function prefixes. 'is' prefix for functions which returns Boolean(true or flase) value
Reference: Read "The Elements of C++ Programming Style."

No comments:

Post a Comment