4 ms·
> C++ encourages coding style that leads to very complicated execution flow. Multiple inheritance. Can you bring another example that leads to "complicated exe
by 10098 12y ago
> C++ encourages coding style that leads to very complicated execution flow. Multiple inheritance.
Can you bring another example that leads to "complicated execution flow" because literally no one uses multiple inheritance (the only exception being when a class needs to implement multiple interfaces).
> Operator overloading.
Very useful feature. Enables you to write readable expressions for actual mathematical objects (e.g. complex numbers, quaternions) and used to implement things like smart pointers. Yes, you should exercise caution when using it.
> Exceptions
Exceptions are useful if used to report errors, not to control program flow. Also, nobody "discourages" from handling errors - you should do it if you have enough context to properly handle the error, otherwise you don't have much choice other than to propagate the exception up.
- vardump 12y agoEven single inheritance with multiple subclasses makes following the potential code paths mentally as many times harder as there are classes that extend or override the common base class. Operator overloading; looks like we agree. Exceptions do control flow, even if you just use them to report errors. They're often effectively hidden gotos.
- 10098 12y ago> Even single inheritance with multiple subclasses makes following the potential code paths mentally as many times harder as there are classes that extend or override the common base class But that is a property of inheritance and virtual functions, not something inherent to C++. You could be using another object-oriented language and the logic would be as hard to follow. We could discuss why or why not that property is problematic, but that would be straying from the topic, which is C++. > Exceptions do control flow, even if you just use them to report errors. They're often effectively hidden gotos. Again, same logic can be applied to any language that supports exceptions.
- mhogomchungu 12y ago>Even single inheritance with multiple subclasses makes following the potential code paths mentally as many times harder as there are classes that extend or override the common base class. Composition over inheritance is a technique used to reduce this problem. [1] http://en.wikipedia.org/wiki/Composition_over_inheritance http://en.wikipedia.org/wiki/Composition_over_inheritance