4 ms·
I've only written a little of each, but my impression is that C has mostly remained a focused, effective language for careful systems programming. While C++ has
by _bxg1 8y ago
I've only written a little of each, but my impression is that C has mostly remained a focused, effective language for careful systems programming. While C++ has become a sprawling cthulhu of leaky abstractions and other nasty foot-guns and people only use it because "it's as fast as C but sorta feels like a higher-level language". And that therefore Rust is a strict improvement over C++, but not necessarily C.
- rocqua 8y agoHonestly I tend to use c++ as C with easy strings for user feedback.
- hedora 8y agoI thought this way too until I worked with competent C++ devs on a modern code base. (By my definition of “competent,” no one ever encountered by the Rust brigade bloggers is competent, fwiw). At some point, I realized that C++ is a language for implementing new languages in a way that is backward compatible with existing programs. Templates are Turing complete (lazily evaluated, purely functional, and side-effect free), so whatever your language of choice can do can be backported to C++ (granted, painfully, but probably less painfully than throwing out all your legacy code and starting from scratch). On top of this, C++ supports zero-cost abstraction, so it will get very close to low level C performance (including constant propagation, loop unrolling, type-unsafe transformations, hoisting, inlining, etc, etc) even if you throw piles of lambdas and encapsulated methods at it. The costs, of course, are that the compiler is slooooowww, and you inherit all the memory safety warts of C by default. (Emphasis on “by default”, because memory safe subsets of C++ are perfectly workable.)
- jasonhansel 8y agoThe problem is that (in my experience) it's very hard to reach that level of competence. I certainly haven't, so I feel safer with Rust.
- saagarjha 8y ago> Templates are Turing complete (lazily evaluated, purely functional, and side-effect free), so whatever your language of choice can do can be backported to C++ (granted, painfully, but probably less painfully than throwing out all your legacy code and starting from scratch). This does not logically follow, since templates are evaluated at compile time and hence have restrictions on what they can do. > C++ supports zero-cost abstraction, so it will get very close to low level C performance (including constant propagation, loop unrolling, type-unsafe transformations, hoisting, inlining, etc, etc) even if you throw piles of lambdas and encapsulated methods at it. You do have to be careful with what you're doing, though. > the compiler is slooooowww I mean, it's not like the Rust compiler is fast either…
- _bxg1 8y ago"since templates are evaluated at compile time and hence have restrictions on what they can do" This statement doesn't make any sense. A Lisp program can be fully converted to run at compile time; it'll just be lacking in I/O opportunities.
- atq2119 8y agoTemplates are not quite side-effect free, although it takes some effort to run into that. See http://b.atch.se/posts/constexpr-counter/ http://b.atch.se/posts/constexpr-counter/ for a delicious exploit of that fact.