Hacker News new | ask | show | jobs
by nanolith 2723 days ago
For instance, pulling in the STL for an interface header instead of encapsulating these details. :-)

No one is claiming that we should ignore performance all together. But, understanding through profiling where performance issues are and designing toward a faster implementation is more important than trying to inline definitions up front.

1 comments

Do you also write all your functions to pass large inputs by value until a profiler says you can pass a const reference?

Some implementation details are so well understood that you really don't need a profiler to do what is probably the right thing by default.

> Do you also write all your functions to pass large inputs by value until a profiler says you can pass a const reference?

No, but neither do I pass types that fit in a native integer by const reference because copies should be avoided at all costs. There is always a tradeoff.

> Some implementation details are so well understood that you really don't need a profiler to do what is probably the right thing by default.

Avoiding any and all indirection at all costs is not one of these.

The pImpl pattern, much like virtual methods, function pointers, etc., are each tools. Indirection is a trade-off that is either worth the expense in cache misses or is not. The cost is not so cut and dried as others in the thread have assumed.

Avoiding any and all indirection at all costs is not one of these.

"Any and all"? Perhaps not. However, I believe the context here was standard library headers. Those are full of small, often-used functions, so avoiding idioms based on indirection such as pImpl is about as close to a black and white rule as you're ever going to find in the programming world.

Nowhere did I say that pImpls should only be used. That was only one of several strategies I discussed.

The article may have discussed standard headers, but it was neither titled to indicate that it was talking about only standard headers, nor are the problems it discussed localized only to standard headers. My original comment did not limit the discussion to only standard headers.