I want to make a fairly complicated mathematical library for a personal project and then have a visualization/GUI to go along with it to demonstrate the maths - nothing hardcore like topology but just show the outcome and have some small animations to demonstrate.

The library will involve matrix operations and I'd like it to be completely object-oriented. I was thinking of going with C++ or C# because of the operator overloading feature.

It will be great to just go:

C = A + B * (C + E);

rather than

C = A.add(B.multiply(C.add(E)));

That's what it would look like in Java. Are there any other consequences to operator overloading other than possibly being confusing?

It seems like it will be a hassle to integrate a nice GUI to a C++ library.

  • 1
    With regards to C++ and GUIs, there are plenty of C++ libraries that make it easy to do simple GUIs. Which is generally the case with C/C++: There's always (at least one) library for it, but it probably ain't standard, so you have to spend time researching your choices and setting one of them up.
    – Ixrec
    Jul 12, 2015 at 21:48
  • 1
    With regards to Java, Google's telling me that existing Java matrix libraries use the syntax A.add(B).multiply(C).add(E), so it's not quite as bad as your post implies. I'm done now.
    – Ixrec
    Jul 12, 2015 at 21:53
  • @Ixrec That is a different operation though. Your code does ((A + B) * C) + E, OP's method example does A + (B * (C + E)).
    – user7043
    Jul 12, 2015 at 22:02
  • Using operator overloading it's difficult to search for references of an operator. Anyway, for math ops usually it's worth to use overloading, since it's much easier to read the calculations. Jul 12, 2015 at 22:54
  • 1
    Operator overloading in C# uses classes. It is baked into the language structure as such, and since the language designers are some pretty smart people, if the OO is good enough for them, it's probably good enough for you. With that said, perhaps you can explain in greater detail which aspects of OO are important to you in this specific case? Jul 12, 2015 at 23:45

1 Answer 1


OO is not about syntax. Just because you use object.function() vs function(object), that doesn't mean you are now "doing OO."

OO is about sending messages to objects to inform them about events, without knowing or caring how they will react to those events.

Vector math is not OO in nature and it would be a mistake to try to force it into an OO context.

In short, operator overloading will not "maintain OO" but maintaining OO is not a worthy goal when writing a math library.

[Edit] Before someone asks something like "what about C++'s vector class, isn't that OO?"

No C++'s vector class, and classes like it, are not OO. They are a form of modular programming. Just wrapping your data up in a package and giving it a name is not what OO is about.

  • "Just wrapping your data up in a package and giving it a name is not what OO is about." I disagree. Abstracting away the data and putting a new spin on it is exactly what OO is about, and I think vector qualifies in this case.
    – Neil
    Jul 13, 2015 at 6:12
  • I refer you to The C++ Programming Language section 2.4 where Bjarne discusses Modular Programming "also known as the data-hiding principle."
    – Daniel T.
    Jul 13, 2015 at 11:24
  • 1
    Calling it "data-hiding principle" doesn't mean that it isn't OO. Also, while I'm sure Bjarne is a very smart person, you're appealing to authority.
    – Neil
    Jul 13, 2015 at 12:38
  • I'm not appealing to authority, I'm acknowledging expertise. I could continue to refer to other experts in this field, but you apparently don't care what experts in the field say. In any case, this is not an appropriate forum for a debate on what OO "really means." If you have a different answer to this question, then by all means answer it.
    – Daniel T.
    Jul 13, 2015 at 13:00
  • Sincerely, I meant no offense. I just thought that that phrase was incorrect. Clearly creating a class only to fill it up with static methods is not the point of OO even if you could. However vector has state, and it is abstracting away array growth for you. That is something.
    – Neil
    Jul 13, 2015 at 14:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.