Handmade Math » Forums » Why no OOP?
polyomino
david van brink
3 posts
#6813 Why no OOP?
1 year, 2 months ago

Hello!

(Tiny intro -- I'm David Van Brink, working on game Metareal, using my own OpenGL engine, math package, everything. Pretty sure I am down with the Handmade Philosophy...)

What is the objection or downside to OOP-ish-ness for a math package?

Cheers!
strangezak
Zakary Strange
44 posts
3 projects

A C++ Programmer working on Squad professionally, and Proportion during my free time.

#6821 Why no OOP?
1 year, 2 months ago

There's no reason for me to OOP this it would just add another level of abstraction onto the library that is not needed.

If you have any more questions just let me know

Thanks
- Zak

An angry programmer.
RJTracer
Lachlan Easton
14 posts

Technically a Programmer

#6831 Why no OOP?
1 year, 2 months ago

I'm struggling to envision what an OOP style math library would even look like. There's no data that needs to be encapsulated, I don't think any functions would be better as methods, inheritance is wholly unnecessary for vectors (if your vector3 is inheriting from vector2 then something has gone horribly wrong), and there isn't any dynamic dispatching that would call for the use of virtual methods.
polyomino
david van brink
3 posts
#6840 Why no OOP?
1 year, 2 months ago

Yes... I too would shun use of inheritance in this context, as unnecessary and potentially unperformant. (Vec3 extends Vec2, I agree, no thanks!)

But phrasing your data types as c++ classes gives some syntactic sugar at no (???) performance loss. Operator overloading is broadly reviled, of course, but even its most vigorous opponents sometimes condone its use when it aligns with mathematical notation. So,

1
2
3
addVec3(a, b) vs a+b
scaleVec3(x, a) vs x * a
lengthVec3(a) vs a.length()

and so on.

This is certainly a matter of taste. I personally prefer the latter of each, but the former is just as good. Taste is a 100% valid motivation for a design choice.

Are there issues beyond taste at play? (This is my actual & serious question, am I missing out on cycles with my approach?)


For amusement purposes only, my own are at
http://hexaflexagon.com/src/Metareal/MeLib/Source/MeMatrix.cpp
http://hexaflexagon.com/src/Metareal/MeLib/Source/MeQuat.cpp
http://hexaflexagon.com/src/Metareal/MeLib/Test/MeMatrixTests.cpp
http://hexaflexagon.com/src/Metareal/MeLib/Test/MeQuaternionsTest.cpp
Mr4thDimention
Allen Webster
252 posts
2 projects

Heyo

#6841 Why no OOP?
1 year, 2 months ago

Well I am not sure that operator overloading would qualify as OOP.

But if C compliance is a goal then operator overloading means maintaining an extra C++ only wrapper, which is definitely a downside. If C compliance isn't a goal though, then I don't know of anything about operator overloading that is strictly a downside.
strangezak
Zakary Strange
44 posts
3 projects

A C++ Programmer working on Squad professionally, and Proportion during my free time.

#6845 Why no OOP?
1 year, 2 months ago

Operator and function overloading can be turned on using a simple #define

An angry programmer.
polyomino
david van brink
3 posts
#6861 Why no OOP?
1 year, 2 months ago

Oh! Right on, CPPMODE has just the thing. Very elegant way to provide C and C++ support at same time.

Zak, if you want, feel free to incorporate the intrinsics mat4 multiply from mine (which I got somewhere else, cited in code). I found it made a huge performance difference. Although the way I did conditionalizing for mac/win/(nothing-else-yet) trivia was sort-of unsatisfying.

The MeQuat methods might also be of interest. Not that there's any shortage of possible sources out in the aether.

Cheers!