7 ms·
What exactly do you need to know about C, that is not part of C++, to understand C++? Genuine question.
by Ragnarork 12y ago
What exactly do you need to know about C, that is not part of C++, to understand C++?
Genuine question.
- throwawayaway 12y agowhy do pointers exist if you have references? why does printf exist? what is everything in the cstdlib?
- Derpdiherp 12y agoReferences in my opinion should actually be called "Address of" operators, then it's much easier for someone new to see why pointers and references exist together. Printf and the cstdlib - eh yeah I'll hand you that, if someone had no concept at all that a language called C existed prior to C++ this would be confusing without explaining it to them. But a newbie should not be looking at C++ code that uses the cstdlib or printf anyway, they should be looking at streams and true C++ code to begin with.
- throwawayaway 12y agoC++ falls to the no true scotsman fallacy yet again. If you type in hello world to the internet, you are going to be getting C and C++ versions and you are going to find out that both work. You can't hide the truth from beginners for any length of time. Imagine telling someone that they can't look stuff up on the internet in case they get exposed to "the wrong stuff"? check out google on streams: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html?showone=Streams#Streams http://google-styleguide.googlecode.com/svn/trunk/cppguide.h...
- Derpdiherp 12y agoBit of a strawman on googling for results - sure I'm not suggesting you can hide the fact it's a relative of C, but I know when I first started out every question I would ask the almighty google oracle would be appended with "C++" - "Why is my code crap C++" - so usually you'd get an actual C++ style solution. And so far as google and streams, well that's their opinion and fits into their particular style. There's plenty of dev houses that would tell you to avoid C style string manipulation due to the dangers of stack overflows etc. Anyway I'm not wanting to fall into a C vs C++ argument, I'm merely pointing out that it's very possible for someone to pick up C++ without having the slightest bit of knowledge of C to begin with. I sure didn't know any C to start with.
- throwawayaway 12y agoyou didn't understand C++ until you understood all the elements of C, you can start to learn C++ w/o C, but you can't continue. you even knew when you started that you had to append C++!
- pjmlp 12y ago> why do pointers exist if you have references? why does printf exist? what is everything in the cstdlib? Support for a legacy language full of security holes.
- throwawayaway 12y agoIn riposte: C++ willingly supports all previous security holes and adds a few more. why do we have structs and classes? all this stuff in the first week.
- pjmlp 12y agoTo allow Bjarne to sell C++ to C developers, specially those ex-Assembly programmers that were force-feed to C. You don't need to learn C, just read "The Design and Evolution of C++".
- throwawayaway 12y agoBut how can you explain their existence and all the C++ behaviour derived from that without using C - you can't.
- pjmlp 12y agoYes, you can. I am having this discussion since 1993. Back when a I was teaching assistance in the late 90's, we never talked about C in our C++ classes, besides the initial history introduction. The fact that the C++ language contains a (almost) C compatible subset doesn't require students to be aware of it. It is all ANSI C++.
- throwawayaway 12y agook: why do structs exist and why are their members public? why don't you just use classes with public? i have been taught extremely poorly and am many years your junior. K&R/stan lipmann's "inside the C++ object model" was a huge "oh ok, I've been basically lied to the entire time"
- maxlybbert 12y ago> why do pointers exist if you have references? Because references can't be NULL in C++, and you can't reseat a reference in C++. > why does printf exist? Personally, I think the more interesting question is "why isn't printf extensible?" And, with variable length template functions, it should now be extensible. If it were converted to a template. > what is everything in the cstdlib? I can't speak for all beginners, but I can say that when I was a beginner, the concept of language (and library) evolution was never hard for me to grasp. Even in a world where C never existed, I think I could have understood that some the library had old ways to do things, and new ways to do the same thing. In fact, I can't think of any language that's been around for more than, say, ten years without a little cruft and duplication in the standard library.
- throwawayaway 12y agoI don't disagree with you, but I am arguing against people who say you don't need to understand C. If it were the case that the new ways were actually superior in all cases, then that point would stand, but in many they are not. It's a confederation of languages and pretending it isn't hinders people and their understanding.
- maxlybbert 12y agoI will admit that the textbook I learned C++ from didn't cover C-style string manipulation (other than to say it was error prone). It took a very long time for me to be comfortable doing any kind of string operation without first converting to a std::string. Nowadays I realize that there are often different answers to different questions, and it doesn't bother me.
- omaranto 12y agoI think what ExpiredLink1 meant is what millstone says here [1], which I took to mean that although you don't need to know C before learning C++, psychologically it may help to know about C (i.e., that a language called C existed before C++ and that C++ is designed to be mostly backwards compatible with C), so that C++'s design choices don't seem as weird. [1] https://news.ycombinator.com/item?id=8722655 https://news.ycombinator.com/item?id=8722655