3 ms·
'zero cost' is what makes some things possible. If your perspective is one where CPU and memory is effectively infinite then yes, who cares about zero cost. T
by wvenable 5y ago
'zero cost' is what makes some things possible. If your perspective is one where CPU and memory is effectively infinite then yes, who cares about zero cost. The last C++ project I worked on I had like 32k of storage and some kilobyte sized amount of RAM. If C++'s abstractions weren't zero cost it would have been impossible to use in this environment. Java, C#, Go -- none of these are even close to possible.
Why wouldn't I just use C? Because of improved programmer productivity and readability of the code.
The reason C++ exists as a language today (and why Rust is it's direct competitor) is because of zero-cost abstractions. Because in many situations programmer productivity and compiler complexity is second to performance.
- yyyk 5y agoMy takeaway wasn't 'never abstract'. That's obviously absurd. Even C itself has abstractions which it tries to make zero cost. Only that it's sometimes not worth it in the language, and C++ neglected to look at the other costs in the past.
- wvenable 5y agoNo, that's the point of C++. If you want a language that doesn't do zero cost abstractions, there are plenty to chose from. If you want a language a step above C that gives you fine-grained control over exactly what code is generated and memory allocated than you have very few choices. You're basically just arguing that C++ shouldn't be C++ (and Rust shouldn't be Rust). We already have plenty of languages that provide high-level "costly" abstractions. The reason we need C/C++/Rust is for that zero-cost aspect. Historically, there were much fewer choices for languages and arguably C++ has been used for building applications that didn't need zero-cost features. But now we have plenty of alternatives and C++ still exists for that valuable niche that it provides. This is the reason Rust was created -- to provide this level of control without the baggage of C++.