> C isn’t simpler for C-style programming than C++ is [...]
Is Stroustrup really arguing that C is not simpler than C++? How can it not be simpler? C++ is essentially C with a ton of features added on top.
> C isn’t simpler for C-style programming than C++ is [...]
Is Stroustrup really arguing that C is not simpler than C++? How can it not be simpler? C++ is essentially C with a ton of features added on top.
"No. C isn’t simpler for C-style programming than C++ is, nor “closer to the hardware,” nor indeed more efficient. I have yet to see a program that can be written better in C than in C++. I don’t believe such a program could exist. By “better” I mean smaller, more efficient, or more maintainable."
Firstly, I'm sure what he's writing there is predicated on the C++ STL being available, the use of which will in turn increase compilation times, because there's a lot of templated code to compile.
I cannot see how you would implement strlen or malloc in C++ (EDIT: as efficiently and/or) more efficiently than C, particularly when you take casting void into account. It's not a far stretch then to imagine writing drivers and so on, where idiomatic C++ would be a distraction compared to C.
In the above his metrics, smaller, more efficient, more maintainable - I can't see any features that C++ has that will allow them to be proven true.
Any program that has to interact with a C library - Stroustroup would suggest library then to be wrapped to make it behave according to C++ style - if so - if the code is just calling a few library functions, C will be shorter and better by all his metrics.
The most convincing is maintainability, but C++ has many more ways to skin a cat than C, so where C had the overhead of understanding someone else's data structure, C++ pretty much does too.
the use of which will in turn increase compilation times
sure, but that does not makes anything he says about it less true. You could even argue it has nothing to do with the discuession at all.
I cannot see how you would implement strlen or malloc in C++ more efficiently than C
He says "C is not more efficient" which means "C++ is as effecient, or more efficient". Which in turns means you are right, and he does not imply you are not (that's the "as efficient" part). Yeeha, you're both right, no need to start a war.
Stroustroup would suggest library then to be wrapped to make it behave according to C++ style
I'd rather think he'd suggest the library should have been written in C++ in the first place. Which is definitely shorter and better by his metrics.
The most convincing is maintainability
which again comes down to the "as efficient" part then.
I am saying that I think that it will take more C++ than C to write malloc or strlen, because of casting to void, so I am saying he's wrong. I could be mistaken however.
I think a wrapper is less of stretch, to suggest that a library be rewritten in C++ as a defence of the simplicity of C++ would suggest a very large amount of cognitive dissonance.
While this is technically true, I have in the past measured this, and the difference on my code when optimising was < 5%, so I think nothing to worry about.
http://tech.slashdot.org/comments.pl?sid=4410261&cid=4533254...
Obviously, what's being compiled is not exactly equivalent but the time difference is startling.
Then of course by moving to a C++ compiler, the temptation is to use features that take forever to compile!
While implementing strlen faster in c++ is harder, implementing qsort faster is easier, as you have the option of compiling a version with the size of type, and comparator, known and inlinable.
Also, you could use a constexpr version of strlen on strings known at compiletime, and be sure the compiker will optimise out the call, unlike in C where you just have to hope the compiler will
Stroustrup made a bold claim that no program exists, I pointed out strlen and malloc - that there exist programs that can be written more efficiently by his metric - your e.g. qsort, I do not dispute, but I refuted his claim. I didn't say implementing strlen faster, I merely said implementing strlen is not by any of his metrics a superior experience in C++.
C would just use hardcoded strings or defines, with sizeof(). This is also a possibility in C++, but I was talking about the implementation of strlen not the usage.
Even the assumption that implementing, e.g., a memory allocation algorithm in C++ is not more comfortable than in C, does no lead to the conclusion that writing a device driver (your example) in C++ is not more comfortable than doing it in C.
But you do admit they are programs! That was all I was trying to do, refute his ridiculous claim - albeit with something marginally less ridiculous. How about a program calling a C library?
The driver thing doesn't automatically lead to the conclusion - but it's not a far stretch to picture it being so. A simple thought exercise does not make a water tight argument.
I can imagine writing certain parts of drivers being better under his metrics in C++ than C but I don't see it in black and white terms like he does. I can see the opposite being the case also.
All that needs to happen for Stroustrup to be wrong is for one program to exist that beats his metrics in C instead of C++.
No, I don't – not in the sense that Stroustrup was using the term "program". strlen or malloc are not programs in the way that this term is commonly understood. His claim is not ridiculous, unless you're nitpicking by using definitions which are just not useful for the discussion at hand (i.e., is C++ better suited for developing non-trivial software).
As for the driver example: I guess we'll just have to agree to disagree, unless someone actually implements a device driver in C and in C++ ;-)
The only project I know of that publishes in multiple languages, vtd-xml - the C++ library has 40k lines of code versus C which is 60k. I don't dispute that C can be more verbose - but it's not a stretch of the imagination to think there's a program somewhere out there that meets Stroustrup's requirements better in C than C++.
Not sure at what point we will have a certain agreement on what is trivial and what isn't. Here's an example of someone writing a lot of code to wrap a C library in to C++, and then doing a few calls to it.
http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper...
[1] http://www.johndcook.com/blog/2011/11/11/simple-versus-easy/
(FWIW, I don't fully agree with even that statement. C++ makes using e.g. enums with bitmasks much harder than C.)