Coding style I'm using

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() :mrgreen:

: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

What did you miss from our coding guidelines that you find better on Haiku?
-G

I would like to clarify a bit: I don’t mean which coding style is better than other. The coding style is more for consistency.

Because, I read our guide line before, but I didn’t have ideas how to apply them in my code, since it is just a few lines without any examples

We can use spaces or tabs on indentation, but it is not that easy, how about one coder use spaces on indentation, then other contributor picks his code, but the later guy prefers tabs? We need some more clear on this kind of thing.

And in our guide, we din’t mention how spaces should be apply to a tab, 4 spaces or 8 spaces? the results will totally different, when we apply them to

After read Haiku’s, I can easily apply the style in my code now. here I would like to make thing more clear, I don’t against our code style, I am a new guy in this area, A simple sentance, as the above quoted from our wiki, can not guide me to code in a good way, and our existing code are more or less don’t following our guide.

If we can have some more details guidelines, it would help us to make our code more consistency, and will help the new comers a lot when he reads our code.

I take advantages from Haiku’s guidelines, but I am following ours as much as I can. :mrgreen:

Again, CONSISTENCY is the most important thing.