namespace box2d?

Rather than prefix everything with "b2", how about putting everything under a "box2d" (or "b2") namespace? I suppose there's trade offs between the two, and wondered if this language feature was intentionally avoided.
I like many features of C++, but namespaces is not one of them. I also suspect that using namespaces would make porting more difficult.
Thank you.
Erin Catto wrote:
I like many features of C++, but namespaces is not one of them. I also suspect that using namespaces would make porting more difficult.


C had namespaces as well.

Namespaces are defined the same way across all compilers, porting should not be an issue (all compilers interpret namespace { } and using namespace the same way).
In reality you could keep all of the b2 prefixes but just wrap the header in a namespace if you wanted to (then again even regular people can do that:

namespace box2D
{
#include "box2d.h"

typedef b2world world;
}
)

it'd be an interesting contrib, but not necessary at all; b2 does justice as a prefix for box2d and leaves the ugly scope resolution and possible name confliction out of the question.

-P
Wrapping one header like that doesn't work as the linker will fail.
I fail to see how moving every class from b2Something to b2::Something would make porting harder. Not only to most languages ported support namespaces (AS3, Java, C#, Python, at least), but it is clear how to reverse the process for the languages that don't. I should note that JBox2D already has stripped the b2's, and I'm likely to do it for AS3 as well.
A couple more things about name spaces:
- in my experience some debuggers fail on namespaces
- using name spaces makes coding harder. Either you fully qualify your names, which requires more typing, or you strip off the namespace with the "using" keyword and then you run into naming conflicts.

I've never seen a project use name spaces without difficulty. So far the b2 prefix has given me no difficulty.
Just wanted to say that I like the b2 prefix as it makes command completion a lot easier in my experience (smaller list of suggestions).
BorisTheBrave wrote:
Wrapping one header like that doesn't work as the linker will fail.


Thanks for clearing that up, I had never actually tried anything like that.

Using a named prefix would be the best method to keep all platforms ported the same way, and I agree with it not needing namespaces in the long run. In reality fully qualified names would be the same real deal as having b2 at the start (in fact you could name the namespace b2d or something), the only ugly part is the scope resolution, and of course name conflicts when using using.

My two Canadian cents anyways!

-P

Original thread: https://box2d.org/forum/viewtopic.php?t=4150