6 ms·
Most of my personal issues aren't with C++ syntax as such (although it also has many problems). My main gripes are: 1. Very slow compilation. 2. Poor encapsul
by colonwqbang 3y ago
Most of my personal issues aren't with C++ syntax as such (although it also has many problems). My main gripes are:
1. Very slow compilation.
2. Poor encapsulation, adding private functions requires recompiling all dependents, see (1).
3. Comically huge symbols make debugging much harder than it needs to be -- today gdb OOM'd my 16GB laptop when trying to form a backtrace of a typical QT application coredump.
Unfortunately it doesn't seem like cppfront can fix these issues. It may still be a worthwhile effort in other respects, of course.
- ThouYS 3y agounder what circumstances does (2) hold? for vanilla methods it's no problem
- loeg 3y agoIf you touch a header, even private only, includers will rebuild. Modules might fix this.
- phkahler 3y ago>>> 2. Poor encapsulation, adding private functions requires recompiling all dependents >> under what circumstances does (2) hold? To add a private member variable or function, you need to put it in the class definition in the header file. Then anything that includes the header needs to be recompiled.
- ThouYS 3y agothey don't need to be. dependents will continue functioning, because ABI hasn't changed
- jstimpfle 3y agoNow explain that to my build system. But even if you managed to do that, first compilation is still much slower than it should be, because anlot of headers have to be included (transitively) to allow even declaring these fields and methods.
- hkwerf 3y agoAdmittedly, adding a private member variable changes the object size and thus the ABI and thus requires recompilation of dependencies. Thinking about that, is there any case in which private functions can end up in a vtable? In that case, it'd break ABI too.
- NekkoDroid 3y ago> is there any case in which private functions can end up in a vtable? Yes, but it generally isn't something that is done. https://godbolt.org/z/5oPovKzoT https://godbolt.org/z/5oPovKzoT
- colonwqbang 3y agoC++ build systems are typically based on file timestamps. Modifying a header file triggers recompilation of all translation units including that header. There are workarounds like pimpl (aka. C style encapsulation). But this requires extra boilerplate and indirection. C++ modules might fix it at some point, but after 35 years of not having them in C++ most real life codebases aren't set up that way and may never be.
- gumby 3y agoI don't think of pimpl as a tool for speeding up compilation, but for black box encapsulation. If the compile time (when adding a method) is really an issue you can chop up and reconfigure your include files. A pain, but perhaps saves you time in the long run. Of course (waves hands) modules will magically improve things...someday.
- colonwqbang 3y agoI think it can be both things. Haven't you ever seen someone do struct Thing; struct OtherThing; in lieu of just including "thing.h"? I see it frequently in real life code bases and I can't see a reason for it other than compilation time optimisation.
- gumby 3y agoSure, I do that all the time too. But you can't call a method (or look inside Thing, or pass it as an argument, only a pointer to it) without including the definition. Hmm, there might be some interesting linker hacks to patch things up post compilation. But then you'd want some way to do the forward declaration for cases where Thing could have been passed in registers...
- DerekL 3y agoThis is sometimes required to break dependency cycles. Also, you can use this to rearrange declarations in the same file.
- germandiago 3y ago
- jstimpfle 3y agoAdding private functions or fields requires changing the class declarations, which requires rebuilding any code that includes that class deckaration. It shouldn't be like that, especially for methods which shouldnt change anything about the class ABI. Even worse, this dependency is transitive. Dependencies to allow defining these private methods an fields are exposed too, forcing inclusion of headers to all members of the class, even if it's only implementation details.
- MindSpunk 3y agoAdding methods changes the vtable layout so there's no way to not recompile all the dependents. There's no solution to this unless private functions are guaranteed to not be virtual.
- AnimalMuppet 3y agoUm... isn't that guaranteed? What would it mean for a private function to be virtual? It can't be overridden by a different implementation in a child class...
- zetafunction 3y ago`final` prevents a child class from overriding a method. `private` does not.
- Findecanor 3y agoYes, you can have a private virtual member function, and it can be overridden in a child class (unless declared final), apparently. I too thought that sounded insane, so I just looked it up. I've been programming C++ for twenty five years and the thought of wanting to do this have never ever occurred to me...
- AnimalMuppet 3y agoTIL.
- usefulcat 3y agoIt could make sense if you have a method that you want derived classes to be able to override but not to be able to call directly. This is, admittedly, a pretty niche case but certainly not inconceivable.
- zetafunction 3y agoExcept the derived class can simply change the visibility of the override, so...
- jokoon 3y agoI laughed at (3) Although QT is not a tiny framework, and I don't really know if modern C++ tools are really good enough for this sort of problem, since C++11 to 20 probably caused those tools to explode in memory consumption But I am not surprised at all. I remember around 2013, I would use bullet physics and the Ogre3D engine, and I had to tell visual C++ to increase its memory capacity because the compiler would refuse to continue.
- a_t48 3y ago3) is forcing me to incorporate a symbol strip/upload to sentry piping at $WORK because Eigen debug symbols cause our build sizes to explode.
- jmac01 3y agoHow is dependency management not in this list hahaha holy crap c++ is so fucking shit to work with in this regard compared to another "modern" language.
- deleted 3y ago[deleted]