4 ms·
I haven't written C++ with any significance in a few years, and done little with Rust at all. So while I don't feel qualified to speak to the comparison at the
by chao- 11y ago
I haven't written C++ with any significance in a few years, and done little with Rust at all. So while I don't feel qualified to speak to the comparison at the core of the blog post, I did find the first example to be disingenuous. It rests entirely on assuming the C++ programmer will rely on inheritance to achieve polymorphism, simply because they can?
Additionally, the C++ example doesn't produce the same output ("Value: (x: 7)" and "Value: (x: 5, y: 10)"). The addition of that goal might lead the programmer to treat the C++ version of print_me as something more abstract, accepting a string and having class Foo and class Bar simply return their own string representations.
I acknowledge that the premise was "a beginner C++ developer", getting hyped up about inheritance and using it as the only tool in their toolbelt, but how many people are learning C++ as a first language these days? It used to be the norm, back in the OO-will-save-us-all heydey, but has anyone run into it lately?
- bluejekyll 11y agoDon't forget about how awesome C++'s multiple inheritance is! <sarcasm/> edit: It's worth the down votes on this. Multiple inheritance is pure evil and confusion. In fact, even in Java I now rely on aggregation over inheritance. http://stackoverflow.com/questions/269496/inheritance-vs-aggregation http://stackoverflow.com/questions/269496/inheritance-vs-agg...
- GFK_of_xmaspast 11y agoc++ is a great language but a lot of the inheritance system is regrettable at best.
- mercurial 11y agoUnfortunately, in some languages, inheritance of abstract classes is the only way to get the equivalent of interfaces. That said, yeah, the less class inheritance, the better. Ideally, work in a language where interfaces can include default implementations.
- bluejekyll 11y agoTotally, no problem with default implementations as long as they are generic. Java finally supports this, as well as Rust and others.