4 ms·
Linus’s point was also that C++ makes extensive use of function/method name overloading (is polymorphism) and this can make code hard to read. Not only is this
by cletus 6y ago
Linus’s point was also that C++ makes extensive use of function/method name overloading (is polymorphism) and this can make code hard to read. Not only is this not possible in C but the feature tends to be overused in C++.
- zozbot234 6y agoRust generally uses function/method polymorphism based on traits (aka type classes), that's far less prone to overuse and abuse than overloading in C++.
- hellofunk 6y agoIs this form of polymorphism done at runtime and thus incurs a similar overhead to the C++ virtual?
- steveklabnik 6y agoThere are two ways of doing it. The way most people use most of the time does not, it's statically dispatched. The other way is dynamically dispatched, though there are some differences from the way that C++ virtual works. They should be roughly the same in that case, though.
- estebank 6y agoIt depends, you have access to both capabilities. By default if you're only dealing with an impld trait then it will use static dispatch. If you are passing around that same object as a trait objects, it will use dynamic dispatch and you can also impl Traits on other traits, which are always used as trait objects (vtable) but that have some restrictions on what they can look like. If you rely on the Deref trait to make it look like you have inheritance (but in reality it is composition) it will be the same as the later using dynamic dispatch.
- fluffything 6y agoYou can pick whether you want to do this at run-time or compile-time. The default is compile-time.
- wheels 6y ago> Not only is this not possible in C ... There are lots of object systems in C that have polymorphism via function pointers.
- jcelerier 6y agoThe linux kernel is full of those
- CydeWeys 6y agoI agree with this critique, but a good IDE helps, as does lint rules preventing egregious misuses (or even outlawing operator overloading entirely). As one example, many Java/C# linters prevent the use of non-curly-braced single line control statements entirely. The language allows them, but many codebases do not.