| > what's the practical difference between NS::foo() and NS_foo() with regards to preventing name collisions. They both do the job. There’re 2 practical differences. 1. You can write `using namespace` inside functions or the whole .cpp files. This often makes the consuming code more readable. 2. Sometimes you want to replace implementations. With prefixes it gonna be massive changes likely to introduce new bugs. With namespaces, replace `using std::vector` with `using eastl::vector` and you’re done. > Even more often, I want to iterate over the values of an enum. I only need to do that rarely. When I do, I cast types like this: enum struct eParamKind : uint8_t
{
Bla, Blub, Foo, valuesCount
};
for( uint8_t i = 0; i < (uint8_t)eParamKind::valuesCount; i++ )
{
const eParamKind pk = (eParamKind)i;
// Whatever
}
> I won't let programming ergonomics be ruined in the name of "type safety".I disagree on ergonomics. VS makes much easier to consume API with strongly typed enums: ePar<Ctrl+Space>::f<Enter>, to type eParamKind::Foo It’s similar with namespaces versus prefixes BTW, IDE will first auto-complete the namespace, then only list members of that namespace once you type the `::` Update: another C++ feature relevant for game development is overloaded operators. Games often do non-trivial amount of math on small vectors, matrices and quaternions. Overloaded operators make sense for them. |
> replace `using std::vector` with `using eastl::vector` and you’re done.
The pipe dream of reusability.. If I ever happen to be in a situation where that will work, I'll happily use a text replace to change my identifiers. Or just link a different library if it has the same names.