Hacker News new | ask | show | jobs
by bregma 2118 days ago
The "zero-cost abstraction" concept is that you don't pay for something you don't use. If you use a smart pointer, you pay for it. If you don't use a smart pointer, it's zero cost.

Any argument that smart pointers are not zero cost to the language because they have a cost when you use them is a classic straw man argument.

1 comments

I think there might be a terminology mixup here but he probably meant zero-overhead abstraction. And in any case, the point he's making is not a strawman argument.
OK, let's substitute "overhead" for "cost in the argument.

Premise one: C++ has zero overhead for most of its features, like smarts pointers: if you don't use them, they cost nothing.

Premise two: using features like smart pointers adds a cost to your C++ program.

Conclusion (due to the strawman logical fallacy): C++ is not zero overhead because there exists a feature that has a cost if you use it.

I'd like to see the reasoning that leads to the same conclusion without resorting to the strawman logical fallacy.

He talked about more than just unique_ptr if you actually watch the video, but I don't even get why you're dying to have such a pointless argument here. When you see free lunches offered somewhere, do you start arguing with people how everyone is wrong and there is such a thing as a free lunch too? Is it so hard to actually take the point and just move on instead of dissecting it like a mathematical theorem?