Again - do not complain when people respond to your ad hominem remarks
with ad hominem remarks. If you want people to respond politely, be
polite yourself. (I won't be repeating this again - either you
understand, or you do not.)
>
>> Take a concrete example: resource management.
>>
>> In C resource management is transparent but manual, the programmer has
>> to track what has been allocated and know when to free it. This,
>> along with the opportunity for error, gets quite complex when a
>> resource is shared, especially between threads.
>>
>> In C++, adding some extra complexity in the language (constructors and
>> automatic object destruction) removes the complexity and the
>> opportunities for error from the user code.
>>
>> The code is still doing the same work and may well compile down to
>> equivalent assembler. The overall complexity remains constant.
>
> Two problems: this assumes complexity is a scalar, which it
> isn't, and that it is simply additive, which it also isn't.
>
Complexity is not a simple or well-defined concept. It is unreasonable
to suggest that it is exactly "constant", or to suggest it is or is not
additive, without first defining it rigorously and finding a way to
quantify it.
However, it /is/ reasonable to say it can be moved around a bit,
increased and decreased, split up, and handled in different ways. It
that may increase or decrease the total complexity (however that may be
defined), but at least it will give you modular parts where each has
clearly lower complexity.
> Furthermore it ignores the cost of all the other complexity in
> C++ that must be paid whether the program needs it or not. Very
> few programs, if any, need all of the complex features that C++
> provides.
Very few, if any, /use/ the complex features of C++.
The C++ language is designed to be "zero extra cost" - if you don't need
a feature, you should not pay for it either in terms of understanding
the language, writing the source code, or at run-time size and speed.
It does not met that aim, but it comes reasonably close in many ways.
Thus you can make classes, use RAII for resource control, have
unique_ptr's for memory handling, store data in std::vectors, work with
std::string - all without ever writing or seeing the word "template", or
understanding rvalue references, or getting your head around
"enable_if". Many of C++'s more complex features exist primarily so
that the standard library (and other libraries) can be written, so that
application code writers can get efficient code without having to
understand these complexities.
It doesn't always work out, of course, but that is an aim.
> I think it was Tony Hoare who pointed out that a
> programming language shouldn't the union of all features needed
> by any program, but rather the intersection of features needed
> in every program. Otherwise essentially every program is paying
> a complexity cost for some unneeded features.
>
It was indeed Tony Hoare who said that.
And if you look at the progression of the C++ language, rarely is
something added to the core language if it could alternatively be put in
the library. Core language changes are added if they significantly ease
programming, or if they allow more useful (or more efficient) library code.
As an example, C99 added support for complex numbers to the language.
It is part of the language, whether you use them or not - even though
only a very tiny percentage of programs use them. C++ did not put them
in the language - they put them in a library.
But you can't take features out of a language and retain backwards
compatibility. C and C++ both suffer from that - and users pay the
costs as well as benefiting.
In every programming language, except perhaps Bart's personal language
for his personal use, every programmer and every program pays something
in complexity costs for features they don't need.