6 ms·
No no no no. This is not a very good reference or tutorial or even an introduction. It even teaches some bad practices and omits crucial detail. The biggest pr
by exDM69 15y ago
No no no no. This is not a very good reference or tutorial or even an introduction. It even teaches some bad practices and omits crucial detail.
The biggest problem I saw was that it introduces classes and objects but does not tell you anything about the "rule of 3", destructors, copy constructors and assignment operators. These are crucial to understanding C++'s pass-by-value semantics and writing sensible C++. C++11 adds to this mess by adding rvalue references, move constructors and whatnot. Writing good and safe C++ requires you to use stack based resource management wisely and use ctors/dtors for initialization and cleanup (this is also why you almost never write try/catch in C++ - and there's no finally statement).
Another example: the article shows you how to do a Java-like constructor like this:
point::point(int x, int y) { this->x = x; this->y = y; }
When in C++ you want to use initializer lists like this:
point::point(int x, int y) : x(x), y(y) {}
At best this tutorial teaches you to write "C/C++" (the worlds most popular programming language that does not exist) or "C with classes". This style of programming has all the disadvantages of writing C but none of the advantages of C++.
C++ is one of the most complicated languages out there, on par with Haskell and Scala. It's C legacy makes it also somewhat dangerous and the pass-by-value semantics make it very different from any other language out there. You cannot expect to learn even a little bit of C++ from little vague blog posts like this.
If you want to learn C++, buy a book! The web is full of crappy resources like this one.
- jbermudes 15y agoIt's interesting that you mention a "C with classes" as the worst of both worlds. There's a large group of people that are perfectly happy with C, and there's a large group of people that like the OOP that C++ offers, but there's a lot of areas of C++ that many people actively avoid or dread, leading to the old joke that everyone programs in their own subset of C++. It seems that with that in mind, coupled with the recent surge of people working on systems languages (Go, Rust, D) that people are looking for a something else. It'd be neat if we could resurrect Stroustrup's orginal prototype of C++ that was literally "C with classes". I wonder whatever happened to that...
- cageface 15y agoThe most interesting part of C++ isn't the OO stuff, IMO, it's the generics. Modern C++ libraries aren't particularly OO but rely a lot on templates. I'd much rather see somebody take a crack at a new systems language that put generic programming front & center in a cleaner context.
- quantumhobbit 15y agoI always felt like templates were a kludge. Clearly the libraries make great use of them, but I've never been able to implement them in a way that doesn't screw up the build process. Probably because I never learned them the right way. That would be the tutorial I'd like to read: "Learn C++ templates as though they aren't voodoo."
- angelortega 15y agoI agree absolutely: templates are only just a little less crappy than preprocessor magic. I personally never use them.
- exDM69 15y agoYou're very wrong. C++ templates are very capable of expressing very powerful idioms. C++11 adds this to this power with variadic templates. std::function, std::tuple, etc are the future. Please do not be offended, but if that is your attitude towards a major language feature of C++, you probably should not be writing tutorials about it.
- AshleysBrain 15y agoI disagree, templates in C++ are great! Just make sure you declare all the code (both declarations and definitions) in a header file, and it should work fine.
- quantumhobbit 15y agoHaving to put both declarations and definitions in the same header file is what feels kludgey to me. It is a break with the normal way of doing things.
- andrewcooke 15y agoi asked for book recommendations (for c programmers) here - http://news.ycombinator.com/item?id=3098298 http://news.ycombinator.com/item?id=3098298 unfortunately, there didn't seem to be a really good one.
- nkassis 15y agoGo find a copy of Thinking in C++ by bruce eckel. He has a free version of it online (also volume two about the standard library). The book is getting old but I still find it valuable and he builds up from C and teaches a whole lot more of the gotchas than this article does.
- uriel 15y agoIt is worth noting that Bruce Eckel pretty much gave up on C++ as a hopeless mess long ago. After some time in Java-land and Python-land this days he is hanging out in Go-land.
- shin_lao 15y agoBe pragmatic. You have to start somewhere and this is a good introduction, even if it's inaccurate.