We have coding conventions on the wiki page, but it is not so clear for me as a starter. When I started to code, I found the code is not easy to read, one of the reasons is because the code formate. It would be great helpful if we can provide some more details coding guidelines, and make our code more clean and consistency.
Currently, I am following the Haiku Coding Guidelines
- Use tabs to indent blocks. Set your editor to 4 spaces per tab.
- Functions/classes in namespaces are not indented.
- In general you use one tab per expression level.
And use the script in VIM text editor to check the code before commit it.
In VIM, set 4 spaces per tab:
set tabstop=4
set shiftwidth=4
you can put them in your .vimrc file. attached is mine, and I just renamed the FuncHaikuCheck() to SynfigCheck()
:fu SynfigCheck()
call matchadd('Search', '\%>80v.\+', -1) " line over 80 char
call matchadd('Search', '^\s* \s*', -1) " spaces instead of tabs
call matchadd('Search', '\(for\|if\|select\|while\)(', -1)
"missing space after control statement
call matchadd('Search', '//\S', -1) " Missing space at comment start
call matchadd('Search', '\w[,=>+\-*;]\w', -1)
"operator without space around it (without false positive on
"templated<type>)
call matchadd('Search', '^[^#].*[^<]\zs\w*/\w', -1)
"operator without space around it (without false positive on
"#include <dir/file.h>)
call matchadd('Search', '^[^/]\{2}.*\zs[^*][=/+\-< ]$', -1)
"operator at end of line (without false positives on /* and */, nor
"char*\nClass::method())
call matchadd('Search', '^[^#].*\zs[^<]>$', -1)
" > operator at end of line (without false positive on #include <file.h>)
call matchadd('Search', '){', -1) " Missing space after method header
call matchadd('Search', '}\n\s*else', -1) " Malformed else
call matchadd('Search', '\s$', -1) "Spaces at end of line
call matchadd('Search', ',\S', -1) " Missing space after comma
call matchadd('Search', '^}\n\{1,2}\S', -1) " Less than 2 lines between functions
call matchadd('Search', '^}\n\{4,}\S', -1) " More than 2 lines between functions
:endfu
set tabstop=4
set shiftwidth=4