News for hackers. Stuff that matters.
Re:Why I don't spend time with Modern C++ anymore by leni536 on Wednesday May 18, 2016 @07:39AM (#11721184)
>There's tricks

You mean PIMPL?

Re:Why I don't spend time with Modern C++ anymore by adrianratnapala on Wednesday May 18, 2016 @08:06AM (#11721301)
Yes, I think so, though I was never truly clear on what PIMPL was supposed to mean.

I am referring to writing a base class in the header and then doing the actual implementation in a derived class visible only inside one .cpp file. There are some other tricks you can do too, such as using pointers-to-incomplete types.

When I do any of these tricks, find that someone else later comes and makes a changes that introduces the extra #includes after all.

Re:Why I don't spend time with Modern C++ anymore by hellofunk on Wednesday May 18, 2016 @08:18AM (#11721348)
PIMPL means "pointer to implementation" and the reason you and your colleagues are having difficulty with it is because you don't understand it, and therefore should not be using it, or, investing the time to understand it before trying to use it.

>every class has its own .cpp and .h file

Wrong. There are so many high-quality and widely-used libraries that are "header only".

>When I do any of these tricks, find that someone else later comes and makes a changes that introduces the extra #includes after all.

It is possible to write sloppy code in any language, and also to receive low-quality contributions from anyone else to your code. This is not unique to C++. That's why it is important that everyone in a team be on the same page about how code is organized.

>I am referring to writing a base class in the header and then doing the actual implementation in a derived class visible only inside one .cpp file.

This is not the PIMPL idiom, though it is halfway right.

Re:Why I don't spend time with Modern C++ anymore by aspiringuser on Wednesday May 18, 2016 @04:54PM (#11725870)
PIMPL pattern is great for reducing compilation time and creating stable user-facing APIs but it has a runtime cost. The "implementation" part is usually heap allocated and calling its methods have extra overhead of crossing the pointer to implementation barrier.
Re:Why I don't spend time with Modern C++ anymore by hellofunk on Thursday May 19, 2016 @02:54AM (#11728524)
With the use of link-time optimization, most of the overhead of using pimpl idiom is removed. Both the outter wrapper functions as well as the implementation functions can be inlined, making the function calls effectively like a normal class implemented inside a header.
Re:Why I don't spend time with Modern C++ anymore by aspiringuser on Thursday May 19, 2016 @06:56AM (#11729259)
The heap allocation for the implementation won't be removed by LTO.
Re:Why I don't spend time with Modern C++ anymore by hellofunk on Thursday May 19, 2016 @07:27AM (#11729368)
I'm inclined to agree that for objects that are going to be created and destroyed very often, especially in tight loops, PIMPL is not an ideal idiom. I wouldn't use it to generate fleeting effects in graphics, for example.

For objects that are used in setting up parts of a system and that will persist for long periods of time, maybe even the lifetime of the app, PIMPL is particularly well-suited for such classes. Classes that might manage networking, or encompass an entire part of app's running architecture, etc.

Re:Why I don't spend time with Modern C++ anymore by hendzen on Thursday May 19, 2016 @11:30PM (#11735399)
Thw complexity and overheead of PIMPL is justified in one scenario, and one scenario only - when you are writing a shared library and need to maintain a stable ABI. Otherwise it is complete overkill.