-
Notifications
You must be signed in to change notification settings - Fork 40
Code Style
athairus edited this page Mar 24, 2016
·
8 revisions
This is a code style guide for the project. For the sake of consistency, try to follow it!
- LF line endings (Windows: Git can be configured to automatically change line endings)
- utf8 encoding, no BOM
- Aim for 120-width columns. You can just barely go over, but try not to most of the time.
To enforce a consistent code style, athairus has written a .astylerc
with settings all C/C++ code written for the project will use. You can find it in the root directory of the Phoenix repo.
- Windows, Linux: Help -> About Plugins... OS X: Qt Creator-> About Plugins...
- Check "Beautifier" under C++
- Tools -> Options -> Beautifier
- Point Qt Creator to your copy of
astyle
- Check the first two options under Options
- (Optional) Copy .astylerc to your home folder to make it usable in all Qt Creator projects (and possibly more).
- (Optional) Set up a keyboard shortcut to invoke
astyle
- MOC macros like
Q_UNUSED()
should "stick" to the top of function definitions as they are not C++ code. - Newlines at the end of files.
- Don't have multiple blank lines.
int foo( int bar ) {
Q_UNUSED( bar );
doSomething();
doSomething();
doSomething();
}
if( foo ) {
bar();
}
if( foobar ) {
if( barfoo ) {
fubar();
} else {
// Execute secret code
*( int * )( 0 ) = 0xDEADBEEF;
}
barfoo();
}
master
Branch
Build Guide (obsolete)