We've worked over half a year with Bullet now and it's safe to say that there are a number of constructions and formatting issues in Bullet that, well... are not so transparent
I'd like to start this thread on possible code improvements, simply to share my ideas of improvements with others as well.
A non-complete list, in random order. Feel free to add suggestions here as well!
LinearMath
Apart from all the math functions, the current setup also contains several helper files that really don't have anything to do with linear math. E.g., btAlignedObjectArray.h, btAlignedAllocator.h, btIDebugDraw.h, btRandom.h and a bunch more. Perhaps it's an idea to introduce a helper folder? Or even more finegrained: a helper and a memory folder? Math = math, file access = file access, memory = memory... anyhow, you get the point
btScalar.h contains setup info and helper functions
Simply look at btScalar.h and you'll see what's wrong with it. My guess is that this is the result of evolutionary programming, but it makes absolutely no sense to define asserts, version info, platform specific compiler pragmas, operator new overloads etc in that particular file. Perhaps it's an idea to clean it up and separate it over various other files (and NOT place them in LinearMath )
assert inconsistent
The library contains several calls to btAssert, but also various calls to assert.h. It would be best to use one consistent name: btAssert. Furthermore the current way of nullifying the asserts e.g.:
Code: Select all
#define btFullbtAssert(x)
Namespaces
Unfortunately bullet doesn't seem to use any namespaces. Is there any reason for this design? IMO it would be more logical to at least setup the namespaces in the same way you organize the directory structure.
No smart pointers
Currently bullet uses raw pointers all over the place. From a memory safety perspective, perhaps it would be an idea to look at the Boost smart pointer implementations?
Inconsistent naming conventions
Bullet seems to be adopting the Camel Casing convention, however there are several occasions in the code where this is not the case. For instance look at btDbvt.cpp, this class contains functions that are called recursedeletenode, removeleaf etc, making it hard for a programmer to read.
Inconsistent indenting
The code contains several examples of non-consistent indenting. Simply look at btDbvt.cpp again. The implementation starts at column 1. That file really is a mess to be honest Perhaps it is an idea to run an automated formatter like:
http://astyle.sourceforge.net/
on the complete trunk? Never tried it though, but perhaps it prettifies the code in such a way that it is more readable for everyone.
C-Style casts all over the place
Apart from a few static_casts, the code hardly contains any C++ like casts. A good example of potential pitfalls for that:
http://www.informit.com/guides/content. ... seqNum=134
Inconsistent usage of constness
There are a lot of methods out there in Bullet that could be declared const, look at all the getters for instance. However this seems not to be enforced. Some getters simply aren't declared const. The other way around: in some cases I even found setters that were declared const, making me wonder why they were called setters in the first place.
Max chars per line
In our company we maintain a max character limit of 100 characters, forcing coders to write code that is readable without scrolling. It's an easy rule that can be easily enforced by configuring your editor. In Bullet there are lines that go well beyond the 200 characters, making it hard for programmers to understand the code.
That's it for now. I'll save the rest for later Please do note that this is not an attack in any way on Erwin or anyone who contributed to Bullet. Bullet is a great product, but if you look at it realistically you cannot deny that it also suffers from a lot of design and formatting issues. My idea is to get an overview of these weaknesses so perhaps we can draw a roadmap of some sort to address them.
Cheers,
Martijn