[haiku-development] Haiku Coding Guidelines Issues

  • From: "Ryan Leavengood" <leavengood@xxxxxxxxx>
  • To: haiku-development@xxxxxxxxxxxxx
  • Date: Tue, 4 Sep 2007 14:35:19 -0400

Here are quite a few things I am wondering about in regards to the
coding guidelines:

In constructors does the colon always come before the parent class
constructor call, or can a member initializer be there too if there is
no parent class?

For example, assume Foo has no parent class, which is correct?

Foo::Foo(int32 param)
        fMember2(param - 1),


Foo::Foo(int32 param)
        : fMember1(param),
        fMember2(param - 1),

The * for pointers is always located by the variable or method name,
right? There are examples of this, but it isn't spelled out
explicitly. For example:

class Example {

                const char *Name();

                BString *fName;

Simple getters and setters can just be coded in the class declaration
right? Using the above example class declaration, Name() could be:

                const char *Name() { return fName->String(); }


Getters should not use the word "Get", but setters do use Set, right?
For example:

        const char *Name();
        void SetName(const char *name);

Is it preferred to "line up" the members of class declarations with
tabs or not? It would probably be better to be explicit about this.
Lining up looks better but could require more maintenance. StyledEdit
has examples of what I mean by lining up.

The preferred order of things in headers and cpp files should probably
be explicit. For example the declaration of constants or static
methods should be where in header files? Before or after the class
declaration? What about in cpp files? Should the constants be first,
then static methods, then the constructor, etc.?

In headers is it preferable to include the headers for classes
referenced in the header, or should simple declarations be used for
classes which are only referred to? For example if a class subclasses
BView and has a BString and BButton member, the header should include
<View.h> but what about the string and button? We seem to be
inconsistent about this.

If the header for a file already includes a system header, should that
file include it too? My gut says no, but I've seen this in the code,
especially in cases where the header includes all the referenced files
instead of just declaring the needed classes.

Are there rules for when more than one class can be defined in the
same file? Is it only acceptable when the second class is only used by
the first?

Do we want to establish a certain "style" for how the BApplication
subclass is handled? I like Axel's style (at least what I have seen in
PowerStatus and Sudoku), which is to have an [AppName].cpp which
contains the application class declaration, implementation and the
main method. The associated [AppName].h just has constant declarations
(like for the app signature.) I suppose we don't have to have a
standard for this, but it wouldn't hurt. Right now there are probably
4 or 5 slightly different styles of this in use.

What are the rules for wrapping long lines? The same as long if
conditions, where the line should be broken on an operator with the
operator on the next line? Example:


Opening brackets ({) should always be on the end of the first line,
except for case statements, right?

OK I think that is all I can come up with for now.


Other related posts: