4 ms·
Which ones?
by rewmie 3y ago
Which ones?
- jb1991 3y agoThere are discussions in many places about this, including right here on HN. I encourage you to Google it. Here are some examples: https://news.ycombinator.com/item?id=24537267 https://news.ycombinator.com/item?id=24537267 https://www.cppstories.com/2018/01/pimpl/#pros-and-cons https://www.cppstories.com/2018/01/pimpl/#pros-and-cons It used to be a widely advertised technique maybe a decade ago, but it has long gone out of style.
- rewmie 3y agoI feel you're just adding noise to an otherwise interesting discussion. If all you have to add is handwave over "Pimpl has so many other drawbacks" and to reply "google them" when asked to substantiate your baseless claim, I feel it was preferable if you sat this discussion out. The noise you add is particularly silly as all your references point is the pointer dereferencing drawback I already pointed out and you claimed there were more.
- vvanders 3y agoHeap fragmentation is another, pimpl works but it's really papering over limitations in the pre-processor and header model that leaks details to downstream consumers.
- rewmie 3y ago> Heap fragmentation is another For the rare cases where potential pimpl users care about heap allocations, there's a pimpl variant called fast pimpl with replaces the heap allocation with a opaque member variable that holds memory to initialize the impl object. Since C++11 the opaque object can be declared with std::aligned_storage.
- andreidd 3y agostd::aligned_storage has been deprecated since C++23
- vvanders 3y agoIf you don't care about heap allocations then why are you using C++ :)
- jb1991 3y agoExactly this. Pimpl idiom is just a bandaid and typically goes against the main benefits of the language.
- rewmie 3y ago> Exactly this. Pimpl idiom is just a bandaid and typically goes against the main benefits of the language. No, not really. The pimpl idiom is a basic technique that is employed to "improve the software development lifecycle", which is a description straight from Microsoft. https://learn.microsoft.com/en-us/cpp/cpp/pimpl-for-compile-time-encapsulation-modern-cpp https://learn.microsoft.com/en-us/cpp/cpp/pimpl-for-compile-... Even Microsoft's Herb Sutter himself has quite a few articles on the virtues of pimpls and how to implement them. If you think they are wrong, are you planning on reaching out to them to correct them and to try to educate them on the matter? That would be something.
- jb1991 3y agoHerb Sutter's main discussions on this are nearly 15 years old lol. Like I said above, pimpl went out of style maybe a decade ago due to advancements in language design, learning about its flaws, etc.
- rewmie 3y ago> pimpl went out of style maybe a decade ago This is a meaningless statement. As others in this discussion already stated repeatedly, pimpl is a very basic and fundamental C++ idiom that is pervasive in all application, and some frameworks are notorious for using them extensively even right now, as is the case of Qt. At most, all you can claim is that you developed an irrational dislike of pimpls, but developers are renowned for making poor decisions and even introducing bugs, so it's worth what it's worth. I mean, some developers even in this day and age still complain about the whole notion of design patterns. Are these blends of opinions worth taking into consideration?
- jb1991 3y ago> all your references point is the pointer dereferencing drawback I already pointed out I think maybe you didn't read through both the items I linked or the many others that come from a simple google query. One of my links for example points out the memory fragmentation issues, which can also affect performance, as another commenter here has also pointed out. There's more to the story than pointer de-referencing or memory context -- many drawbacks worth knowing about. There is nothing baseless here; there are pros and cons. But it's not in good form to ask people for details that are easily looked up on a topic as well-known as this one. We are not a reference source for you.
- deleted 3y ago[deleted]