Contact Us
Language

Any future problems from naming my math lib with unscoped v2, v3, v4, m3, m4? - General and Gameplay Programming - GameDev.net

tagsChina Hdmi Repeater Extender

If you have any trouble resetting your password, please contact us.

I am redoing some C++ engines. Get rid of GLM and fix my math library. I have been using e.g. ke::vec3 but just want to switch it to v3 etc... without having to

It can be seen everywhere in the .cpp file. Should I worry about name conflicts in the future? Is this a bad idea?

I marked the thread with "C++". I'm not surprised that it's useless.

You can also use it in the class/structure or namespace of the header file:

(Well, at least for me, this is something new that I haven't discovered until recently.)

Put the entire engine in the same namespace. In this way, you don't have to have name conflicts when using ::.

Hello there

, Mind if I ask why you want to get rid of GLM?

I personally don't like namespaces. This is mainly because I have seen people name things like "Camera" in their own namespaces more than once, and then use certain third-party libraries with their own "Camera", and there are still conflicts. My friend recently brought me an error caused by this exact problem. He was knocking for the first few hours, trying to figure out what was going on.

Said v1, v2, v3, etc. sound a bit like pushing it. The weird thing is that you might just give it up because no one else is crazy enough, ?. In my code, I have some sequences of uppercase letters, these prefixes are global prefixes, which has worked for me (so far). This may be because I rarely use global things, so almost all I need to worry about are class names, but they tend to have longer names anyway. In general, I don't like putting a lot of common names around the world, but if you are the only one doing this, you might avoid using it.

I personally don't like namespaces. This is mainly because I have seen people name things like "Camera" in their own namespaces more than once, and then use some third-party libraries with their own "Camera", and there are still conflicts.

But this is the solution:

Put the entire engine in the same namespace.

Although, it seems that everyone only uses 2 letters to represent the engine name space, so... :)

I personally like it very much. I use namespaces hierarchically, for example MeshProcessing::VectorFieldDesign::GenerateCurvatureField(). This is some typing, but I can see the dependencies without looking for included items, and I can easily find functions through Intellisense while typing.

In addition, VectorFieldDesign is just some functions, no member data or private functions are needed, so no classes are needed, and these things can still be grouped together using namespaces.

It is also particularly useful when using multiple math libraries or replacing one math library with another math library. I don't recommend using just one common namespace. For me, things like vectors and matrices are usually the most annoying problems in programming. Use 3 or 4 floating point numbers for vec3? Use 4x4 or 3x4 for conversion? Do you still need mat4x4? To SIMD or not to SIMD? Floating point and double precision templates?

Decades later, I still cannot answer all these questions, and it has always been a very likely substitute.

Mind if I ask why you want to get rid of GLM?

One argument may be performance: https://www.gamedev.net/forums/topic/709305-glm-vs-vs2019-for-simd/

At least that's the idea, but some people tend to use sentences to operate, and then things get messy. I have seen that the code can be compiled and then linked to the wrong routine when the parameters happen to be close enough (ie the friend question above). The namespace is more or less like having an extra long name, but if "used" is used everywhere where it disappears, then it has dubious value at that time. Please note that many people think that using "use namespace std;" is bad practice. The same logic that made this decision can also be applied to other namespaces.

The namespace is more or less like having an extra long name

If you make it more like a path, such as a file directory, it won't. This is a hierarchical structure, useful for organizing content. Long names cannot do this.

But agree otherwise, I only use "use" for core content such as vec3, and not for STL.

The namespace is more or less like having an extra long name, but if "used" is used everywhere where it disappears, then it has dubious value at that time.

"Using a proper loop structure is more or less like using structured code, but if you put the'goto' wherever it disappears, then it has dubious value at that time."

Don't do that

Effective usage of "use namespace", like there is

Are valid uses of "goto", but they are extremely rare (and always limited to specific functions).

Don't do that

I think the key is that you must either type a long name or increase the risk of conflict with "using". If you don’t have a namespace, you can usually write the prefix yourself, which is basically what I’m going to do, or you can use static variables in a class, which is something that some people have done before adding namespaces to the language . In any case, I found that I don't need them. If they work for you, that would be great.