6 ms·
Good luck trying to understand C++ without C. The numerous C++ traps and pitfalls will just look mad to you. BTW, 'multi-paradigm' is an oxymoron. Not even Scal
by ExpiredLink 12y ago
Good luck trying to understand C++ without C. The numerous C++ traps and pitfalls will just look mad to you.
BTW, 'multi-paradigm' is an oxymoron. Not even Scala uses that concept any more.
- throwawayaway 12y agoScott Meyers says in Effective C++, view C++ as a confederation of languages: C, C++, the preprocessor and templates. When some people say that when you are learning C++ you should not be exposed to C, I really have to disagree.
- bewuethr 12y agoI think he says "OO C++" and "STL", not "C++" and "preprocessor".
- stinos 12y agoGood luck trying to understand C++ without C look at it this way: suppose some alternate universe where there is no such thing as C, it just doesn't exist, nobody ever heard of it. Why would you not be able to completely master C++ that universe? The traps and pitfalls which you consider C, would then just be known as C++ (just as in reality they are C++ now, maybe not just always named as such). I think that's one thing what's being advocated here. Anyway, what traps do you have in mind specifically?
- millstone 12y agoMuch of C++ can only be understood in the context of C. For example, why are string literals not std::string, and what the heck are null-terminated strings about? In your alternate universe, C++ would be a nonsense language full of absurd design decisions. Understanding C is perhaps necessary to understand why C++ works the way it does.
- ExpiredLink 12y ago> Much of C++ can only be understood in the context of C. This. Moreover, much of the complexity of the language is caused by being designed as a super-set of C. C++, literally, makes no sense without C.
- bkeroack 12y agoEven further, why are strings considered a linear sequence of 8-bit characters (defaulting to ASCII)? That's madness in 2014! If I give you a sequence of bytes and tell you it's a "string", that's no more meaningful than if I gave you a bunch of bytes and said "this is music" or "this is a picture". Without telling you the encoding you have to blindly guess how to interpret it. Go does a good job of rectifying this: strings are generally opaque binary objects--indexing into them gives you abstract "runes" (representing Unicode code points) which can then be encoded into various flavors of UTF characters.
- jbooth 12y agoI know it's a rhetorical question, but "Unicode didn't exist when C or C++ were invented" is a really good answer.
- jerf 12y ago"Go does a good job of rectifying this: strings are generally opaque binary objects--indexing into them gives you abstract "runes" (representing Unicode code points) which can then be encoded into various flavors of UTF characters." Overselling Go a bit there. Indexing into a string gives you that byte: http://play.golang.org/p/rxeexRzW7e http://play.golang.org/p/rxeexRzW7e There are ways of iterating along a string by "rune" but it's not the default. That said, given that strings in Go are assumed to be UTF-8, indexing into them by rune is expensive and if you actually want to iterate by Unicode char I'm not bothered by having to be a bit more explicit about it.
- bkeroack 12y agoStrictly speaking, indexing into a string gives you an integer type (as your example also shows): https://play.golang.org/p/i7_MKja_mQ https://play.golang.org/p/i7_MKja_mQ "Rune" is an alias for int32. So we are saying the same thing, essentially.
- mikeash 12y agoC++ wouldn't exist in that universe. But if we accept the hypothetical, I think that people in that universe would still identify and separately consider the C-ish subset of C++, much like template metaprogramming is considered its own subset of the language. So no, I don't think they would understand C++ without first understanding C, even if they didn't call it "C" or consider it to be a completely separate entity.
- aikah 12y ago> Good luck trying to understand C++ without C. You need a basic understanding of C.But C and C++ are different languages,period.
- Ragnarork 12y agoWhat 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.
- AnimalMuppet 12y ago> BTW, 'multi-paradigm' is an oxymoron. False. What's a paradigm? It's a way of viewing things. What ways are there of viewing programming? Well, there's functional, there's structured, there's object-oriented, there's generic, and maybe some more. Can C++ be used to write non-object-oriented, non-functional, purely structured-programming-style procedural code? Yes, it can. (Essentially, that's the subset that's in common between C and C++.) Can it be used to write object-oriented code? Certainly. Can it be used to write functional code? Again, yes (though not nearly as purely as the Haskell zealots would like - but C++ doesn't enforce the purity the way Haskell does precisely because C++ is multi-paradigm). Can C++ be used to write generic code? Yes. (I have heard that the STL was written in C++ because, at the time, it was the only widely used language that would do what Stepanov wanted to be able to do.) Four different paradigms. You can write C++ code using any of them, or you can mix and match. That's multi-paradigm. Or are you arguing that, if you have more than one paradigm, you don't have any? That might be true of a program, though I think that the argument is merely a matter of definition, and therefore not very interesting. But if the language makes it easy to write in several paradigms, it seems perfectly appropriate to call it multi-paradigm.