Skip to content

Instantly share code, notes, and snippets.

@ethanrublee
Created December 3, 2012 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ethanrublee/4198381 to your computer and use it in GitHub Desktop.
Save ethanrublee/4198381 to your computer and use it in GitHub Desktop.

Coding Standards / Best Practices

Readable, solid code is our livelihood and a matter of professional courtesy. The code is not yours to maintain, it is everybody's. Others will have to read it. Don't make your coworkers lose a day debugging your code just because you were undisciplined.

Sutter/Alexandrescu/Meyers/Boost

This is the book

All of this book applies. Elaborations/modifications of individual items follow.

1. Compile Cleanly at High Warning Levels and leave -Werror turned on to guarantee this. If you need to disable certain warnings, do so carefully and in the smallest scope that you can:

set_source_files_properties(warnyfile.cpp
  PROPERTIES
  COMPILE_FLAGS -Wno-non-virtual-dtor)

No Tabs. No Trailing Whitespace.

Whitespace is important for diffing cleanly. We are a no tabs and no trailing whitespace code house (except where tabs are needs as in gnu makefiles). Please set your editor to not include tabs and not to save trailing whitespace.

In emacs land:

(add-hook 'before-save-hook 'delete-trailing-whitespace)
(setq-default indent-tabs-mode nil)

To help yourself from making the faux pas of committing evil invisible characters, try forcing git to dissallow it:

% cd my_git_repo
% cp .git/hooks/pre-commit.sample .git/hooks/pre-commit

You can also turn it on in your git diff via:

% git config --global core.whitespace tab-in-indent,trailing-space
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment