4 ms·
Maybe just me, but doesn't most C++ code being written today not use inheritance very much, and so make virtual dispatch moot?
by zabzonk 5mo ago
Maybe just me, but doesn't most C++ code being written today not use inheritance very much, and so make virtual dispatch moot?
- nly 5mo agoIt's still the most convenient way to implement type erasure, so no.
- gue-ni 5mo agoI think this is unfortunately wishful thinking, a lot of code is still written with traditional inheritance. It just makes unit testing with mocks much easier.
- bruce343434 5mo agoAre C++ concepts not enough?
- stingraycharles 5mo agoThere are codebases out there that don’t use a lot of TMP and prefer Java-like type management. To each their own, but yeah, your experience matches mine.
- pjmlp 5mo ago90's C++ you mean, a decade before Java came to be, and responsible for famous books like GoF.
- aardvark179 5mo agoThe GoF book came out in 94, and Java in 95.
- pjmlp 5mo agoYes, have I said otherwise? It is a book that plenty think it has Java in it, no it has Smalltalk and C++ and was published before Java came to be as you point out. The decade was about the book publishing date, rather all the C++ frameworks that came to the market since CFront 2.0 was made available in 1989, and yes it was exactly 7 years, if being pedantic.
- layer8 5mo ago90's C++ already had templates, so “Java-like” is a more succinct descriptor, it doesn’t imply the direction of historical ancestry.
- pjmlp 5mo agoYes, and? First of all they were extremely buggy back then, as anyone that actually used Stepanov's original implementation, from HP with docs hosted at SGI, will remember. Secondly, Turbo Vision, OWL, VCL, MacApp, PowerPlant, Tools.h++, RogueWave Collection Classes, MFC, wxWidgets, Gtkmm, Qt, PÖET, COM/OLE/ActiveX, CORBA, Copland, BeOS predate Java, not the other way around.
- layer8 5mo agoYou were criticizing the use of “Java-like”. IMO it gets the point across much better here than “90's C++”. It has nothing to do with what predates what.
- pjmlp 5mo agoYes, because it is completely wrong. It isn't writing C++ as Java, it is writing C++ as it was common between 1990 and 2011, before C++11 and other programming techniques took over in the C++ world, highly influenced by Andrei Alexandrescu's book "Modern C++ Design", published in 2001.
- deleted 5mo ago[deleted]
- pjmlp 5mo agoOnly on conference slides maybe, real production code looks quite different, including game engines like Unreal and Godot. CUDA frameworks, V8, LLVM and GCC, you name it.
- deleted 5mo ago[deleted]
- locknitpicker 5mo ago> Maybe just me, but doesn't most C++ code being written today not use inheritance very much, and so make virtual dispatch moot Most C++ code being written today is the same code that has been here for years. What compels you to believe things are rewritten on the spot? I mean, I personally know of flagship C++ projects that are still stuck in C++14 and earlier. Why would this change? Perhaps people should pay attention to the fact that C++ goes way out of its way to be backwards compatible.
- zabzonk 5mo agoWell, back when I wrote C++ for a living I tried to keep up with better practices and newish, more compact and sensible language features. So some code I might have written in the 1990s would almost always have overused inheritance, while when adding a feature in the 2010s, I would have minimised such use. I would expect most C++ devs to do something similar today.
- locknitpicker 5mo ago> Well, back when I wrote C++ for a living I tried to keep up with better practices and newish, more compact and sensible language features. That's fine, but definitely something that does not happen in professional settings. You simply don't look at a codebase with a few million LoC and decide on a whim that you are going on to, say, replace all raw pointers with smart pointers. That is not going to happen. That definitely did not happen at all. May I remind you that Google's C++ coding guidelines discourage exceptions because they do not have the resources to refactor all their code to be exception safe? Google doesn't have the man power but you do?
- zabzonk 5mo agoNot particularly relevant here, but may I point out that Google's C++ guidelines are generally seen as bad, and really only applicable to someone at Google scale, which you are almost certainly not.
- 5mo ago