Skip to main content
gamedev.net
🔒 Locked

Templated Vector

Started by Silly_con 8 replies 550+ views
Original Post
Silly_con
Silly_con
When you do a 3D vector class, that will be 99% of times a float vector, its a good idea to have a class using float explicit, or have too a class with type template ? (the template version is fast to program, only replace float by T and add some <T> ...)
Teknofreek
Teknofreek
I'm sure you'll get varying opinions on this, but I'm firmly of the mind that you should just hard-code it to use floats if that's what you expect to be using in your engine. Flexibility is great...when you need it. However, adding extra complexity to support something you'll most likely not need just makes things more cumbersome for your usual case.

-John
John
wendigo23
wendigo23
I agree with the freak. I have the most success when I keep things as simple as possible. If you need the extra fanciness later, well, at least your simple first solution didn't take a lot of time.
Jingo
Jingo
I would prefer making it a template, and then making a typedef for float. That way you could extend it to doubles for more precise vectors, or to ints or whatever. Who knows what the future holds. I don't think adding a template parameter adds much complexity.
Washu
Washu
A vector is a rather general purpose construct, so the chances are fairly high that you will want to reuse the existing code for other projects. Thus making it a more generic construct, such as using templates, would be advisable.
In time the project grows, the ignorance of its devs it shows, with many a convoluted function, it plunges into deep compunction, the price of failure is high, Washu's mirth is nigh.
Silly_con
Silly_con
Thanks for your points of view, I believe that I do it in the two ways, and later I'll select what to use :)
GroZZleR
GroZZleR
If you're of the lazy type, just typedef it.

template <typename T> class CVector3 { ... }
typedef CVector3<float> CVector3f;

...

CVector3f FloatVector;
Timkin
Timkin
Quote:
Original post by GroZZleR
CVector3f FloatVector;

Hehe... you can pick the MSVC programmers a mile away! ;)

Personally, I agree with Washu on this one. First assess the likelihood of reuse of your code. If you're never going to see it again and it's never going to need to be maintained (which is highly unlikely) then go with what requires the least work.

If you are at all likely to reuse your code (and you should almost always be thinking about how to minimise writing common code from scratch), then you should seriously consider generalising the code and fascilitating easy specialisation of the code for specific projects. Thus, templating your vector and permitting typedefs would be one option and a good way to go IMO.

Cheers,

Timkin
Ademan555
Ademan555
? whats so msvc about that? is it somehow non standard compliant? (im curious... because i like standards... really...) lol

thanks
-Dan
When General Patton died after World War 2 he went to the gates of Heaven to talk to St. Peter. The first thing he asked is if there were any Marines in heaven. St. Peter told him no, Marines are too rowdy for heaven. He then asked why Patton wanted to know. Patton told him he was sick of the Marines overshadowing the Army because they did more with less and were all hard-core sons of bitches. St. Peter reassured him there were no Marines so Patton went into Heaven. As he was checking out hi
snk_kid
snk_kid
Quote:
Original post by Ademan555
? whats so msvc about that? is it somehow non standard compliant? (im curious... because i like standards... really...) lol

thanks
-Dan


i think he was just referring to his coding conventions, its some kind of pseudo hungarian notation [sick][lol]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.