Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> The downside to the PIMPL idiom in C++ at least, is that you have double indirection.

PIMPL is just a tool. There’s no argument here that it should be used in all or even many cases. The fact that C++ has this tool and Rust does not is interesting.

PIMPL indeed has overhead. Both when writing the code and when calling the code. If a program crosses the PIMPL boundary many times then the calling overhead can be meaningful.

However if the API is small and the program spends more time “inside” the PIMPL than crossing the boundary the runtime overhead is trivial.

A key benefit of PIMPL is that, in some cases, you can have a very lightweight header than clearly expresses an API without making users include a ton of dependencies they don’t actually need. I shall not express my opinion on C++ headers.

Historically I have not liked PIMPL. My current project benefits from it a great deal. Most projects probably would not. Like I said, it’s just one of many tools.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: