5 ms·
Digraphs and Trigraphs seem pretty silly to me. Multiple inheritance is bad, but idk how much code would break if it were removed.
by correct_horse 6y ago
Digraphs and Trigraphs seem pretty silly to me. Multiple inheritance is bad, but idk how much code would break if it were removed.
- mehrdadn 6y agoMultiple inheritance is vital to C++. You wouldn't want to remove it any more than you'd remove interfaces from Java. It would break all kinds of things. With you on digraphs and trigraphs, though.
- pkolaczk 6y agoOnly if you write C++ like Java. But there are also coding styles heavily based on templates, and then the use of multiple, or any inheritance is rare. Rust and Go can do without inheritance at all.
- jcelerier 6y ago> Only if you write C++ like Java. But there are also coding styles heavily based on templates, and then the use of multiple, or any inheritance is rare. It's super common to implement mix-ins, which is as based on templates as it's possible to be, with multiple inheritance, e.g. struct featureA { int x; }; struct featureB { const char* foo{}; void print(); }; etc and then template<typename... Args> struct mixin: Args... { template<typename... CtorArgs> mixin(CtorArgs... args) : Args{args}... { } }; using foobar = mixin<featureA, featureB>; void f() { foobar{123, "foo"}.print(); }
- MaxBarraclough 6y ago> It's super common Curiously recurring, even! [0] Although what you're showing seems to be a variation on the curiously recurring template pattern, as the classes being mixed are listed 'symmetrically' without much regard for which will inherit from which. I found a blog post on 'mixin classes', which are like the CRTP but invert the inheritance relation. [1] What you've shown seems to be a third way. [0] https://en.wikipedia.org/wiki/Curiously_recurring_template_pattern https://en.wikipedia.org/wiki/Curiously_recurring_template_p... [1] https://www.fluentcpp.com/2017/12/12/mixin-classes-yang-crtp/ https://www.fluentcpp.com/2017/12/12/mixin-classes-yang-crtp...
- jcelerier 6y agoyes, it's not proper CRTP but I did not want to spend too much time on that... just show that multiple inheritance has its uses even in fairly generic, non-OOP code :-)
- gpderetta 6y agoCRTP is a common use case. Also inheritance is often used to implement type level recursion (although this is significantly less needed now that we have argument packs).
- gpderetta 6y agoHeavy template base code uses inheritance all the time. But here is no expectation of is-a relationship there, it is purely for code reuse. In template code, the is-a is better expressed as modelling a concept (which is done mostly via structural typing, not nominal typing). It is unfortunate that there is no explicit way to distinguish OOP is-a from code reuse, other than the presence of virtual functions in base classes, but in my 15 years of professional use of c++ I can't remember it ever being an issue.
- ncmncm 6y agoRight. Sometimes language features support an architectural pattern, sometimes they are just mechanism. And sometimes the same feature is one, sometimes the other. There is no shame in it. Language features are there to be used.
- gumby 6y agoDigraphs and trigraphs were removed (in C++17 IIRC). Non-twos-complement arithmetic and non-IEEE-754 floating point have also been removed.
- humanrebar 6y agoTrigraphs were removed. Digraphs are still in the language.