[Please do not mail me a copy of your followup]
<zSGAx.1903$Md3....@fx01.iad> thusly:
>snprintf vs. "<<" and ">>" should be sufficient to show
>how the readability (and maintainability) of C++ code is
>improved by selective use of C run-time library functions.
I disagree because of the large number of errors that I have seen
w.r.t. use of printf style functions over the years. You are, of
course, free to do whatever you want. But I will continue to counsel
against it based on many years of experience on many teams where
entire classes of bugs simply disappeared from our code because we
stopped using printf style code.
I would make an exception where the performance is important and measured
to be slower with stream insertion operators and this was the dominant
factor in the performance analysis. However, this is a case where we
are intentionally using more error-prone means to achieve a given end
because other factors are an overriding concern. Even here, there
are wrappers C++ around printf that can alleviate some, but not all,
of it's problems and these would be preferred over direct usage of printf.
>You, like Stefan, seem to think that only "pure" C++ is
>useful or valid, which is far from the actual truth.
I have no idea what "pure" C++ is according to you. I haven't said
any such thing in any of my posts.
I'm saying that C programming habits routinely introduce problems that
are easily avoided by using C++ programming habits instead. Among
other things, that means preferring the C++ standard library over the
C standard library. Please read that sentence carefully, because I
don't want it to be re-interpreted into another straw-man argument
about some absolutist style "demand".
>>By all means, if you want to write C, then please head on over to
>>comp.lang.c, contribute to the unix kernel, or whatever.
>
> Believe that I _have_ contributed to both the unix kernels and
>the linux kernels (and even the oracle RDBM core).
Great for you. Please do continue to write C and contribute to C
based projects as you see fit. However, I will continue to counsel
against C-style programming when programming in C++. While C++ may be
mostly compatible with C, my advice has been and will continue to be
that you should stop thinking C when writing C++ and think in C++
terms instead.
>>However,
>>please stop teaching people that writing good C++ means using C-isms.
>
> However, you have no right to make such a silly demand.
Where am I making a "demand"? That is you creating a straw man
argument by making up things I haven't said. I will continue to
advise and request that people stop using C style habits when
programming in C++.
>There
>are many cases where using C run-time library functions and C
>idioms in C++ code is perfectly valid. It's perfectly legal use
>of the C++ language as well.
Another straw-man argument. Nowhere have I said it was invalid or
illegal to use C style programming habits.
I have said, and will continue to say, that programming with C-isms
(e.g. using C style programming habits) is an error-prone, unnecessarily
low-level (e.g. devoid of higher levels of abstraction) and therefore
much more verbose than the C++ equivalent mechanisms.
>I tend to find appeals to authority less of interest than the
>experience gained over 30+ years developing very large C++ software projects.
My point was less an appeal to authority as simply pointing out that
I am not sone "lone usenet net.crank" in advocating this point of
view. It is, in fact, quite commonly advocated among the leading C++
practitioners in the field, which includes the designer of the language.
If you want to interpret that as an appeal to authority, then fine,
by all means ignore my advice as well as the similar advice of people
like Herb Sutter, Bjarne Stroustrup, James McNellis, Kate Gregory,
all the wonderful speakers at places like CppCon, C++ Now! and so-on.
I am not saying that automatically all those people agree with me 100%
on everything, but I am saying that the advice I've been giving here in
this newsgroup is consistent with the same advice I hear from them when
I listen to their talks on youtube or when I have had the pleasure of
talking to them in person.
I state my recommendations and advice based on real-world experience in
many teams at different companies over a long period of time. I have led
instruction in the C++ standard library to make teams aware of how C++
and the standard library provides tools for common programming problems
(such as string manipulation; which is how this whole tangent got started)
that are less error-prone than their C counterparts. As a result,
entire classes of problems simply disappeared from our code because we
stop writing code in the C style and embraced C++ fully.
>I don't believe in the fanatical pursuit of language purity at the
>expense of functionality, readability or performance.
The "fanatical pursuit of language purity" you speak of seems to be
embodied by the straw man arguments cited earlier in this post. I
don't even know what "language purity" means; you are the one who is
introducing these terms, not me.
I don't even understand how one can argue that C style programming
embraces more functionality than C++ style programming since you've
already admitted C++'s ability to be (largely) backwards compatible
with C.
Readability is a subjective phenomenon and I don't know any way to
objectively measure it in a manner that all programmers can agree with
the measurement. I am more than willing to describe examples of C style
programming that I think impair readability. It almost always is a
result of insufficient use of abstraction that impairs the ability to
express directly the intention of the programmer. In my day-to-day
programming within a team my suggestions to improve readability almost
always revolve around eliminating duplication, simplifying syntax and
introducing abstractions with intention revealing names in order to
improve readability.
As for performance there are specific examples where C++ code outperforms
C standard library functions and programming habits. There are also
cases where the performance of a C style approach, such as printf,
exceeds C++. However, the exception shouldn't become the rule. By that I
mean that simply because printf can outperform stream insertion for some
particular piece of code, doesn't mean that one should systematically
reject all things C++ for all things C. Nor does it mean "stream
insertion operators are bad" because most of the time the performance
difference isn't significant and there are advantages of stream
insertion operators over printf.
If you want to use printf and other C style programming habits
routinely, then my recommendation is to not program in C++ and instead
program in C. Then you can advocate C style programming practices to
the C community instead of advocating C style programming to the C++
community. I will continue to advocate C++ style programming habits
and the avoidance of C style programming habits to the C++ community.