4 ms·
The author uses C and C++ interchangeably, but these are two distinct languages. Although technically a superset of C, C++ has constructs and paradigms which m
by delegate 10y ago
The author uses C and C++ interchangeably, but these are two distinct languages.
Although technically a superset of C, C++ has constructs and paradigms which make you think in totally different ways.
In fact C++ introduces many language features which (should) protect programmers from 'C' mistakes in their C++ code.
For example, in modern C++ you shouldn't manage memory directly, but use smart pointers and containers. You can, but you shouldn't.
And there are dozens of such recommendations. Which is the right approach, imho. You can still do the low-level dangerous stuff if you feel brave, but officially you should stick to the 'safe' paradigms that the language now offers.
However, the paradigms that C enforces on you are the paradigms of how to do things fast. You wear no protection so you are much more nimble, but much more vulnerable at the same time. Which is good for some types of projects, but not for all.
- palunon 10y agoC++ is not even technically a superset of C... `auto` has very different meanings in both languages, and you can't omit the return type of an int-returning function in C++
- david-given 10y agoHave you ever tried to compile an old C program which extensively used variables called 'old' and 'new' with a C++ compiler? I have. Also, C++ doesn't allow implicit casts from void* to any pointer type, which is a common C idiom.
- deleted 10y ago[deleted]
- kbart 10y ago"The author uses C and C++ interchangeably, but these are two distinct languages" Sure they are. C/C++ are often cobbled together in a sense that they are both low level, non-memory safe and non-type safe languages, as opposite to high level, safe, memory managed (aka "modern") languages.
- johannes1234321 10y agoC++ is a type-safe language (unless you use C-features like void*, which you shouldn't in C++) it is high-level (thanks to templates likely more high-level than many others). If you think of C++ as "C with classes" then you can mix them, but C++ evolved quite a lot with C++11 and following standards and implementations.
- kbart 10y agoI somewhat agree with that, but unlike in most other modern languages, type-safety is not enforced, thus you can't call it a pure type-safe language even though you can write programs in type-safe way. Same with low/high level -- you can use C++ as low level (C with classes) or as high level according to modern C++ standards (C++11, C++14) and best practices. There's no strict classification, I just wanted to highlight C++ similarities with C.
- johannes1234321 10y agoThe C++-fan would say you have the tools to ignore type safety, so you can opt-out. But that's of course a matter of perspective. A good, modern, tutorial should only teach type-safe tools to beginners.
- KKKKkkkk1 10y agoSpeaking of type safety, has modern C++ solved the object slicing problem yet?
- TheCoelacanth 10y agoYes, they're called references.
- dbaupp 10y agoThere's too much undefined behaviour for even modern C++ to be considered type safe: a dangling reference or invalidated iterator allows you to break it easily, accidentally. (Even "opt-out type safety" is a stretch, opt-in-with-extra-tooling-and-tests seems more appropriate.)