Kai-Uwe Bux said:
In terms of likelyhood of bugs, I think it's not so much a difference in
total number of bugs per line but a difference in distribution. The error
patterns will be different. The implicit coding style can help to avoid
many
bugs. If you put clean up code in the destructor, it will be very hard to
_not_ execute it at the appropriate point.
I definitely agree with different distribution. As theat "implicit" code the
ctors and dtors are executed, with healthy guidelines you can say goodby to
"uninitialized" and "leak" classes of bugs. This IME is a huge source with
great produce. Do I get your assertion right: you claim that we get similar
amount of other problems in the exchange? My observation has big
difference, I'd guss by 2 orders of magnitude or even more.
Exceptions in templated code, on
the other hand, can lurk at places where you don't espect them diverting
control flow to a point determined by the type of the exception thrown
(and
within a template, that can be an unknown type, whence the target of the
jump is unknown, too).
I don't get this part. IME I write the big majority of C++ code as
'exception transparent'. It is a very rare case I bother to look at
exception spec of any called stuff: just expect any letter may emit an
exception. (What may be close to reality too -- if the implementation just
use a string as temporary, you immediately gain bad_alloc potentially.)
While the situation where it actually matters is rare. And in those rare
situations you pay attention anyway.
This applies to any normal function. How templates bring in anything
fundamentally new? You can't tell what T is and dependent stuff actually
does -- but should you care more? There are some special cases where you
require a nothrow guarantee, say for dtors and swap() -- but it is the same
for nontemplates.
May our observations differ due to difference in basic view of code: my
based on 'any point is an exit; where we expect otherwise needs
documentation' and you go the opposite thinking default is nothrow?
On the other hand, not seeing those jumps written
explicitly, can improve readability of the code; and having client code
determine the target of the jump even allows for greater flexibility than
goto -- whether that is good or bad, I guess, depends on the perspective.
The difference in readability is heaven and hell ;-). With the insult
added to injury that all the "alternate" paths execute only "exceptionally",
but take over 80% of the source. Just killing the possibility of
abstraction. As instead of
DoSomething(par1, par2, par3);
that was the intention, at least you must write
if (DoSomething(par1, par2, par3))
{ some handling }
At every place in client code. I rather not even start what proliferation
occours if par1 above had a conversion, especially one involving memory
allocation. Eg. in function argument was string but par1 was "Hello world".
It will create a bunch of implicit, inisible code -- constructing a
temporary, destructing it, adding a throw point. I do not deny the
*possiblility* of surprise caused by any of those.
But if the intent was as written: call that very function with that very
argument, the explicit mass of code would be there as well, as a noise
making a 5 second review into a 5 minute one for that single command. And
if intent was different, the problem is not really in the implicit code --
and I'd think with black noise stripped it is easier to discover.
Also, the correct, but "inefficient" code is normally preference to fast but
buggy one; and we have great tools that count calls and elapsed time, so in
the time you do not spend on hunting bugs it's possible to pay attention to
the 2-3 spots where you can tune away a temporary.
In terms of better/worse software, I do not see any evidence either way.
I recall Mike Howard stating in Writing Secure Code, that conversion to use
*any* kind of "string class" instead of C counterpart lead to extreme drop
of critical problems that lurked for years. i experienced a ton of evidence
how RAII based code drops bug count (not only the immediately related ones),
development time, and overall health of the project and its development.
It
seems that other factors are much more decisive. In the end, it's not the
language alone but a tupel
(group of developers, languages used, toolchain, ...)
that influences overall quality of the result.
If by that you mean that any language or language feature will not solve any
problem (aka 'No silver bullets'), of course.
I think in assuming a good process with competent and motivated people.
(meaning they know their tools whatever those are). Having that, different
tools and language features DO create a big difference. Allowing to spend
the programmers' time on writing the meat instead of hand-crafting all the
"noise".
This is not to say that
changing a single element in the tupel does not have an effect. But in one
setting going from C to C++ can boost the quality and in another setting
it
can make things worse.
Well, if you take a working C team novive in C++ and just tell them to start
writing C++ code, picking up featires along the way it is sure recipe for
disaster. ;-) You need competence. No doubt, gaining it for C++ is way
more work. But the bright side is, it can be done with just a few C++ gurus
put in charge, who mentor the others and review all the code until everyone
is familiar wit the gotchas.
Upshot:
=======
It think, for any particular project, there is a practical difference in
choosing C++ or C or (insert other language here). Making the right choice
will improve work flow and quality of the developed program. However, what
the "right choice" is depends on many factors and the "right choice" is
not
uniform.
Sure.
I am not sure whether that qualifies as a "practical difference" in the
sense of your question. But surely, choosing C++ or C is a consideration
of
practical importance. I would, however, venture the following conjecture:
whether the explicit/implicit distinction will have any seizable weight in
choosing the language probably depends more on the developers involved
than
the task at hand.
And we know all too well, that people will chose "the familiar way".
Especially in stress. Even in cases where they already learned that their
familiar way is wrong in long and short term...