Basically, I was working on a project and thought to myself that I could do a much better job at being more consistent with the over all layout of my code and I was wondering if there were certain rules or guidelines that SFML uses for its source and how that process works. When I talk about consistency, I am mainly talking about how the layout of each file is structured in terms of what things go where and in what order, and how things are named.
How does everyone here keep their stuff clean and consistent? Do you have your own set of rules you follow? Does it even matter to you?
To me it matters a lot. I follow these guidelines in my code:
- I use camel case and avoid abbreviations like the plague;
- I create a namespace for the project's classes;
- My classes have public interface first, then protected, then private;
- In class declarations: first enums, then member variables, then member functions;
- I use spaces and empty lines to make the code more readable (to me);
- All the code is formatted with Artistic Style (http://"http://astyle.sourceforge.net/"), and looks like this:
#include <iostream>
using namespace std;
class Singleton
{
public:
static Singleton & getInstance()
{
static Singleton singleton;
return singleton;
}
void print()
{
cout << "I'm a singleton!" << endl;
}
private:
Singleton() {}
Singleton( const Singleton & );
Singleton & operator=( const Singleton & );
};
int main()
{
Singleton::getInstance().print();
return 0;
}
What I need to improve is the comments. I don't comment nearly as much as I should.