Wiki

Clone wiki

fuppes-fork / Style Guide

Fuppes has a style guide and we use the popular program AStyle to enforce that style. We do not have any stylistic rules that cannot be enforced by AStyle and, therefore, if you want to see what the styleguide is then just look in the 'astylerc' file in the projects root directory. You may ask why we use a style guide? Here are our reasons:

  • When you make a pull request to the repository we only see what you have changed, there are never lines in the pull request that are unimportant.
  • It allows the entire codebase to look the same.
  • It is very easy to maintain and literally costs nothing for you if you setup the git pre-commit hook below.

When you make a pull request we expect the code to be formatted with AStyle by the time we go to read it. Ideally you have formatted the code with AStyle before every commit. We don't really want to make a big deal out of this, we really want it to be a "set and forget" affair.

For your convinience, if you wish to run AStyle manually then we have a script prepared that does that in the scripts directory:

./scripts/run_astyle.bash 

Google Style Guide

I happen to agree with most of the coding conventions in Google's Style guide. If you follow all of the common "best-practices" that that document outlines then I will be more than happy. However the major exceptions that I have to their coding style are:

  • The use of Boost C++ libraries; I say the more boost you can leverage the better.
  • The use of exceptions; we do not have big bulky codebases that we have to maintain and exceptions are a good way to make sure that you model code correctly

Modelines

In order to help you maintain the code format as you write the code we have provided you with the concept of Modelines. There is a vim modeline and a TexMate modeline at the top of every C++ file in the entire project and there is a script in the scripts directory that you can use to maintain those modelines.

These modelines are there for your convinience, if you wish to use a different editor then you must make sure that you follow the style guide.

Git Pre-Commit Hook

Here is a handy git pre-commit hook that you can use to run AStyle before every commit:

#!/bin/bash -e

echo "Running AStyle before commit"
ASTYLE=${ASTYLE:-astyle}
case `$ASTYLE --version 2> /dev/null` in
  Artistic*)
      ;;
  default)
      echo "fuppes git pre-commit hook:"
      echo "Did not find astyle, please install it before continuing."
      exit 1
      ;;
esac

formattedFiles=$(./scripts/run_astyle.bash "--formatted" | sed 's|formatted\ *||')
echo "$formattedFiles"
if [ "x$formattedFiles" != "x" ]
then
   git add $formattedFiles
else
   echo "No files to commit."
fi
echo "Successfully ran astyle before commit."

exit 0

Make sure that you put the file at .git/hooks/pre-commit AND that the file is executable! If the file is not executable then it will not be run.

Updated