6 ms·
I'm sort of a C++/Stroustrup fan I guess, but this confused me: > C isn’t simpler for C-style programming than C++ is [...] Is Stroustrup really arguing that
by fhd2 13y ago
I'm sort of a C++/Stroustrup fan I guess, but this confused me:
> 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.
- deletes 13y agoC is not simpler as C++ as you can program( with a few minor differences ) in C++ using C style. In that case both are equally complex.
- Sharlin 13y agoHis point is that actually you don't want to write plain C - you want to pick some C++ features that considerably reduce the complexity of your code.
- bstamour 13y agoCorrect. Even if you simply changed all of your dynamic arrays to std::vectors, the code you write is now simpler, easier to reason about, and pretty much memory leak-free.
- barrkel 13y agoYour statement that, effectively, C++ can do everything C can, plus more, has the direct logical implication that C++ is absolutely more complex, not equally complex. (FWIW, I don't fully agree with even that statement. C++ makes using e.g. enums with bitmasks much harder than C.)
- recentdarkness 13y agoHe's just saying that if you write C in C++ it's as 'simple' as C itself. > C++ is essentially C with a ton of features added on top. You would just not use those 'ton of features on top'
- fhd2 13y agoEven unused code arguably adds to the overall complexity. But maybe that's what he meant, yeah.
- saurik 13y agoUnused code adds to the complexity of a project you manage. However, you did not write the compiler: you are writing a program using the compiler. You don't have any unused code: you just have access to features you will choose not to use.
- sz4kerto 13y agoThe complexity of feature set of a language does not translate to complexity of programming in the given language. That's because if the problem is complex, then it might be easier to learn the more complex language features than solving the problem with simple language features.
- fhd2 13y ago"Simple" and "easy" mean two very different things [1]. [1] http://www.johndcook.com/blog/2011/11/11/simple-versus-easy/ http://www.johndcook.com/blog/2011/11/11/simple-versus-easy/
- stephen_g 13y agoThose added features make for simpler code - I mean, almost anything that does string handling or requires dynamic arrays is way easier to do in C++.
- Sharlin 13y agoIndeed. A simple language leads to complex code. And code complexity is the thing that needs to be avoided, not language complexity. You could write a Turing-complete language with a single instruction, for instance "subtract and branch if negative", and it would probably be the simplest language in the world, but writing anything nontrivial in it would be horribly complicated.
- eliasmacpherson 13y agoThat whole paragraph is ridiculous. I'm commenting but really I should abstain because I feel I am lowering the tone with yet another great religious debate: C vs. C++. "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.
- stinos 13y ago[note: I use both C and C++ heavily, and I think you are interpreting Bjarne wrong here] 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.