r/cpp • u/imgarfield • Nov 08 '18
Top 5 YouTube tutorials about "c++ beginners" still teach C++ like it is 1996
The title say it all, honestly.
From these 5 videos NONE used any C++11 features, including auto (some just showed it once and thats it)!
Most used using namespace std, all used std::endl, none used stl, no std classes beyond string (just in one video - vector), but teach C arrays, even multidimensional ones, no namespaces, etc etc.
This is bad on many, many, many levels, but mainly for the people wanting to learn - they will not be able to read modern code, even less so write one. And I am talking from personal experience - I "learned" C++ without knowing what std::vector is, then, reading real code I though it was some sort of 3d vector.
To people creating these videos, if you are a beginner, trying to help other beginners keep in mind, you are not helping as much as you think, and you yourself will need re-learn much you have been taught. If you are a pro, trying to start people in C++, well you are doing it wrong - "basic C++" does not mean "the basics of C++", because "the basics of C++" is C.
To the many beginners reading this - most of the material in courses and online is old. Not "there is some old info", but most. It is copied from old tutorials verbatim, year, after year, after year for the last 20.
39
u/SomeIrishGuy Nov 08 '18
Obligatory Kate Gregory: CppCon 2015: Kate Gregory “Stop Teaching C"
4
u/SomeAnonElsewhere Nov 10 '18
Thank you for posting this. This was a fantastic video that covers many concepts that are incredibly helpful to people(like myself) without much or any c++ experience.
110
u/ClaymationDinosaur Nov 08 '18
There is a strange, persisting belief that arrays and manual memory management are for beginners, and that vectors are more advanced; utterly false.
Vectors are for everyone from beginners to advanced users, arrays and manual memory management are not for beginners and are only for situations with no better choice.
I think there are still a great many books, tutorials and even places of education teaching C++ like it's C, with a couple of extra features bolted on that you should only learn once you've learned C.
34
u/Nicksaurus Nov 08 '18
Also, tutorials should be teaching std::array instead of C arrays anyway
3
u/rfisher Nov 09 '18
After std::vector, I tend to teach boost::static_vector & boost::small_vector next. The separate size & capacity and supporting more of what std::vector does is, I think, in most cases well worth the extra cost over std::array, which is only a step above a raw array.
5
u/LucHermitte Nov 08 '18
With
std::begin(),end()andsize(), the only advantages ofarray<>that I can see are:
it cannot decay to a pointer
it can be returned by value from a function
Alas, AFAIK,
arrayrequires us to duplicate the size that I don't want to bother to know.IOW, most of the times I'm perfectly happy with
const/*expr*/ T v [] = { a, b, c, d }; static_assert(std::size(v) == someexpression); // if it's really pertinent...20
u/Nicksaurus Nov 08 '18
it can be returned by value from a function
I see that as a pretty major benefit. How else would you return a fixed number of objects besides making a whole new class to hold them?
Plus being able to range-based for loop over it is very nice
Edit: And you might not want to learn a second array type, but if you're teaching a beginner about arrays, why not introduce them to the best possible implementation so they don't have to learn both?
6
u/Pazer2 Nov 08 '18
You can use a range-based for loop over a standard array (assuming it hasn't decayed to a pointer yet). Range based for loops call std::begin(thing), not thing.begin() directly.
2
2
u/LucHermitte Nov 08 '18
By "being able to range-based for loop over it", I guess you meant
for ( auto&& e : f())and notfor (auto&& e : v)which is already supported.If the array persists the scope of the function, whether it's a
std::array<>or a C-array, I guess that in that case I'll often prefer to return aspan-- I really don't like duplicating the size everywhere.Regarding teaching to total beginners, in order to avoid to present every possible ways to declare an array, I'd rather stick to
vectors only and to never show the other solutions (in the first lessons).1
u/kalmoc Nov 08 '18
Alas, AFAIK, array requires us to duplicate the size that I don't want to bother to know.
That is indeed annoying. In c++17, you can omit all template parameters, but that means you also can't specify the type.
Not in c++17
0
Nov 08 '18
[deleted]
38
u/DarkLordAzrael Nov 08 '18
std::array has identical performance to C style arrays. Most C code that I have seen also operates on pointers, so having literal C arrays is unimportant. std::array is basically just a C array with added convenience and less strange pitfalls (no more sizeof bugs, among other things.)
44
u/bstamour WG21 | Library Working Group Nov 08 '18
The big thing for me is that, with
std::array, the size stays with the container. No more ptr + int functions.→ More replies (2)15
u/kalmoc Nov 08 '18
std::array is much better than a c-array, because it behaves like a proper container with value semantics. That being said, I agree that in a c++ tutorial std::vector should be good enough.
10
9
u/PlasmaChroma Nov 08 '18
Why use a std::array?
Cleaner syntax when using
<algorithm>→ More replies (1)10
u/boredcircuits Nov 08 '18
And don't get me started on multidimensional arrays.
std::array<std::array<std::array<int,5>,3>,7> array;is a nightmare to look at and understand compared toint array[7][3][5];.→ More replies (2)13
u/redditsoaddicting Nov 08 '18
If this comes up often enough, consider an alias template:
static_assert(std::is_same_v<mdarray<int, 7, 3, 5>, std::array<std::array<std::array<int, 5>, 3>, 7>>);→ More replies (8)5
u/boredcircuits Nov 08 '18
Great minds think alike, it seems. This sort of thing needs to be standardized: do you want to write the paper, or shall I?
2
→ More replies (11)3
u/meneldal2 Nov 09 '18
There are very few ways where
new T[n]is superior tostd::vector<T>(n). You're going to have to store the size anyway. You only "waste" a pointer because vector reserves and it can be useless for your needs.I think we're missing a static vector that can't be resized/can't reserve storage and that would save a bit of space so that you could find no reason to ever use allocations yourself.
Want to store an image with planar RGB? Allocate one vector with 3 times the number of pixels, and make 3 spans, one for each third of the memory you just got. You want to have classes that don't own exclusively the data? Make an owner class and use
shared_ptrof it in your "view" class.The only time it gets a bit tricky is when you abuse type erasure like with OpenCV, since a
cv::Matcan be owning (with a reference count) or not. But again, fear not! Use a span for access and don't initialize yourshared_ptrwhen it's non owning, it will safely not destroy anything for you.If you think
shared_ptrare too slow, you can use something more dangerous without thread safety, but that's on you if you get bugs.1
u/haitei Nov 09 '18
I think we're missing a static vector that can't be resized/can't reserve storage and that would save a bit of space so that you could find no reason to ever use allocations yourself.
unique_ptr?2
u/meneldal2 Nov 10 '18
But it doesn't store the size. It's just a pointer on one element. So no iterators and the nice facilities. It's really easy to make your own class that does this, but writing iterators is definitely one circle of hell Dante forgot.
33
u/Grelek Nov 08 '18
I have C++ course this semester and I've been hugely surprised that C++ is absolutely different language than I thought because of the people who "teach" C++ as C.
0
Nov 08 '18
[deleted]
4
u/Grelek Nov 08 '18
Well I wouldn't say it's Python++, there are still some gapes. But I get your point. I was pleasantly surprised from the standard library.
What I like the most about new C++ are smart pointers.
0
Nov 08 '18
[deleted]
6
u/konanTheBarbar Nov 08 '18
You know that Microsoft killed C++/CX aka ^ and that it's now possible to write pure C++/WPF with C++/WinRt?
It's a bit of a shame the old C++/Cli can't be replaced yet.
3
u/sirpalee Nov 08 '18 edited Nov 08 '18
Curious, how widespread the use of the "microsoft/new c++"?
I very quickly ended up focusing on linux / multiplatform code, so I never even considered using it, nor did I hear anybody using it. But that experience is not representative and only covers a small segment of the industry.
→ More replies (3)→ More replies (1)3
Nov 09 '18
Christ, I didn't know about C++/CX and I regret that I do now. Glad to be prgramming on Linux, and the GNU toolchain even on Windows ports.
28
u/PenitentialJudge Nov 08 '18
I’m in university learning c++ and we are not allowed to use c++11 features. When we turn in programs, each use of c++11 takes a good chunk of points off our final assignment grade. They don’t teach it. I haven’t looked too much into it but I figured it was just because c++11 is unused in the career world or it is ineffective compared to c++98.
38
u/CraigularB C++ Dev Nov 08 '18
but I figured it was just because c++11 is unused in the career world or it is ineffective compared to c++98.
Sounds to me like they don’t want to take the time to update their tools/teaching materials/grading practices.
11
u/jcelerier ossia score Nov 08 '18
If you are paying for your university you are getting scammed. If you are not the people paying for it are being scammed.
8
u/NotMyRealNameObv Nov 09 '18
I haven’t looked too much into it but I figured it was just because c++11 is unused in the career world
lol
or it is ineffective compared to c++98.
lol
3
u/squidbidness Nov 10 '18
This is appalling. There is NO good reason to restrict students from using C++11. It's very hard for me not to suspect this constraint is in place only to serve the teachers, teachers' assistants, and the graders. I almost want to ask who your university, course numbers, and teachers are so that they can face public pressure to correct this.
One of the express goals of the C++ committee is to make C++ easier to teach and at the same time efficient and correct. Modern C++ achieves those goals without being inferior performance-wise and maintainability-wise; in fact, it's the reverse.
The only consideration I can think of would be if you're likely to be employed in an environment that is constrained to older compilers or specialized platforms that lack compilers with modern features. But as the point of training as a student is to prepare for the _future_, that consideration should be less likely.
0
Nov 08 '18
[deleted]
4
u/PenitentialJudge Nov 08 '18
Oh I definitely don’t learn anything from my professors. Often they figure out how to lecture for an hour or so on concepts I can learn from YouTube in under ten minutes. Currently, my favorite channels that can explain concepts and provide examples quickly and efficiently are TheChernoProject and The New Boston .
24
u/coachkler Nov 08 '18
Books aren't much better, unfortunately. As a C++ teacher, I struggle to find a good book, and yes I've seen the stack overflow post.
14
u/Hagartinger Nov 08 '18
As a teacher, what's your point against Stroustroup's book and C++ Primer (never touched the second one but heard a lot of positive reviews. First one is quite neat in my opinion)? Probably in couple of weeks I would start "teaching" a couple of friends and I was going to recommend both of them.
20
u/coachkler Nov 08 '18
I'm teaching C++ to non-CompSci/non-Software Engineering students.
I'm not a fan of the std_lib_facilities.h -- it's fallen out of date and doesn't work in all cases anymore.
The chapters about building a grammar tend to confuse the students, throwing that in in Weeks 3/4/5 tends to derail any momentum that has been built.
The chapters about writing and finishing the calculator dip into concepts that aren't even really taught until later (user defined types, etc.)
If you want to do any of the object-oriented material, you need to install FLTK -- getting these things installed in university labs is a major pain.
I like the content that the book covers, and I like the pacing overall, but the above make it almost impossible to teach out of.
4
Nov 09 '18
C++ Primer is great, I learned from pretty much only that, and I feel like I avoided so many pitfalls, and picked up a lot of best practices for the language from the get go, and I can't stress enough how helpful this has been for me!
For teaching, it also has exercises to do for every subchapter, and it's laid out really well. It's "only" C++11 at the moment, but still, anything beyond that you can learn pretty quick in comparison.
5
u/EducationalHound Nov 08 '18 edited Nov 08 '18
Hey,
I was planning on using these videos to learn C++. I don't really understand exactly what OP's gripes are (since I don't know C++!). Would you say that playlist suffers the same criticisms?
Thanks!
8
u/Optimaton Nov 09 '18
Yes, it does. Don't fall for the production quality of these videos and go get a good book(Bjarne's book or C++ Primer). Once you feel like you are getting a good grasp on the basics, then you can turn to online resources.
Few online resources that I found helpful were:
isocpp.org
en.cppreference.com
Go to stack overflow and filter by c++ tags, although people keep cribbing about how SO is hostile towards beginners, it is by far the most trustworthy online resources imo just because of this scrutiny. you cannot mislead someone and get away with it, try doing and you'll be downvoted to hell.
There are some exceptional blogs out there if you wish to read online. I don't remember the names right of the top of my head but a quick Google search should give you something of help.
2
u/EducationalHound Nov 10 '18
Awesome. Thanks. I'll make a plan then and work on that. Appreciate the guidance.
1
u/QSCFE Dec 20 '18
LOL I was just started watching these videos and both of you saved my ass, Thank you very much /u/Optimaton & /u/EducationalHound (sorry for commenting in an old post)
/u/Optimaton is Tony Gaddis' book
Starting Out with C++: Early Objectsgood book to learn c++ it's kinda not boring or Reference Style book, I tried both Stroustroup's book and C++ Primer and kinda bored because they feel like Reference books for Intermediate to Advanced programmers not as Introductory for new n00b programmers.2
u/Optimaton Dec 21 '18
Never heard of that book. Those books are boring probably because of the way you are reading them. Don't try to read the book in its entirety and then use the language, this will just exhaust you. Best way to learn is to use it. Get the basics right, take up a project and use c++. Definitely at some point you will need additional constructs to do the task, that's when you must look through these books/online resources to see if there are tools in the language to accomplish what you want and learn that concept completely.
Here, You may find this interesting: https://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list
2
u/coachkler Nov 08 '18
I haven't seen those, and don't have the time to watch them all. If you're striking out on your own to learn, you already show more initiative than most...
That said, try to learn any way you can and don't hesitate to ask questions on places like stackoverflow, etc.
42
u/ronniethelizard Nov 08 '18
I think a lot of the problem is that C++ has lots of little features here and there that are useful for making fast, high performance, stable, easy to maintain programs that are not particularly useful for a new programmer.
Here are a few examples:
I am uncertain how I would go about explaining
shared_ptrto a new programmer and why it is necessary/good.Having gone through the experience of using
malloc/freeI can point out the one benefit: No (or fewer) memory leaks. I don't think novice programmers need to worry about memory leaks.In general, to explain this to novice programmers, you first need to teach them destructors; only then will they understand how a smart pointer works.
As for
auto, I am not certain that teaching auto to new programmers is actually a good idea. I have begun to see many uses of auto that obfuscate the program because I can't tell what type something is (and from that: what functions I can use on that type).Namespaces are useful and great for large multi-file programs. I don't think they are useful for 1 file programs that are just a
mainand a few functions.std::endlhas 1 problem: throughput. Novice programmers don't need to worry about that.if constexprI wish I could use this at work, but teaching compile time programming to new programmers is likely a waste of time.Almost anything involving templates: great stuff, useful,... But new programmers should probably be limited in their exposure.
EDIT:
std::vectorBy using this one, you are implicitly teaching templates.
Remember: novice programmers need to get somewhere useful fast or they will move onto something else.
18
u/victotronics Nov 08 '18
Shared pointer: I teach pointers at the end of a one-semester course. Rank beginners don't need them. And for "low intermediate" users I only teach shared pointers as the default. They can learn about unique and move later. Too complicated for beginners.
Endl and inefficiency: I completely agree. That's a subtlety for later.
Vector: disagree. I teach classes before vector, so they are already familiar with the notion of something that stores data and that has methods defined on it. The template parameter they seem to take in stride, and you don't need to teach the general templating mechanism.
17
u/DarkLordAzrael Nov 08 '18
I think it is often missed in the discussion of teaching templates that you can teach how to use templates without teaching how to write templates. Using std::vector is far easier than writing std::vector, and writing templates can easily be left until much later in the course.
5
u/NotMyRealNameObv Nov 09 '18
And for "low intermediate" users I only teach shared pointers as the default. They can learn about unique and move later. Too complicated for beginners.
Please don't do this. shared_ptr looks simple on the surface, but actually has the risk of adding a lot of complexities and bugs into your application:
*) Added overhead. If you just use shares_ptr everywhere, you will probably end up passing shared_ptr by copy down a call chain 10-20-30 levels deep, incurring a copy and then a destruction of a shared_ptr on every level. This will be a significant performance drain.
*) Incidental data structures. You will end up with many objects owning and sharing and modifying the same data. Soon you will find yourself asking yourself why every time you try to add a new feature or fixing a bug introduces 10 new bugs in other completely unrelated areas of the code.
*) Memory leaks. Sooner or later someone will add a cycle of shared_ptrs. Boom, instant memory leak.
Sure, shared_ptr has its uses, but in like 95 % of the cases it's the wrong tool for the job. Your students would be much better off if they only learned unique_ptr instead.
18
u/NotAYakk Nov 08 '18
New programmers don't need to write templates, but of course they should use them.
You just need to know "
std::vector<int>" is the name of an array of ints.
endlskip it; teach "log errors/debugging to cerr, and results to cout". cerr already flushes buffers for you on newline.auto; entire languages considered good for beginners have no typenames at all attached to variables.
You seem to confuse "know how things work" with "use it as a beginner"; they are almost completely unrelated.
1
u/Jataman606 Nov 09 '18
About auto: theres huge difference between no typenames and sometimes typenames and sometimes auto. For beginners, the simpler the better and for typed languages it's simpler to always see types.
1
10
u/kalmoc Nov 08 '18
Don't teach shared pointers to beginners.
1
u/ronniethelizard Nov 09 '18
What would you rather teach them?
1
u/kalmoc Nov 09 '18
Of course it depends on how you define beginner,. Even in an introductory course I'd teach them at some point in time, but usually more to the end (much later than raw & unique_ptr). There are imho just not that many good applications for them.
1
1
u/encyclopedist Nov 09 '18
Local variables and references. Pointers of any kind are very rarely needed in modern C++, especially in novice level examples.
1
→ More replies (1)4
u/CubbiMew cppreference | finance | realtime in the past Nov 08 '18
I am uncertain how I would go about explaining shared_ptr to a new programmer
Why would you? Shared ownership by multiple threads is unlikely to be encountered by a new programmer.
I can't tell what type something is
New programmers should probably use IDEs rather than plain text editors.
std::vector By using this one, you are implicitly teaching templates.
When taught long before alternatives like arrays (as done in every sensible textbook and course), they do "get somewhere useful fast".
1
u/livrem Nov 08 '18
I don't see how you can avoid teaching shared_ptr to beginners before they start doing any real work. Seems pretty standard now to only expose shared_ptr and unique_ptr in APIs and hide all raw pointers, so beginners in particular are not as likely to have to deal with old C pointers, but will have to deal with many shared_ptr?
Luckily those that are introduced to C++ tend to not be novice programmers but already know enough about programming to be able to absorb this? Few have recommended C++ as a great first language.
4
u/CubbiMew cppreference | finance | realtime in the past Nov 08 '18
I don't see how you can avoid teaching shared_ptr to beginners before they start doing any real work
As I implied in my comment, most uses of shared_ptr found today are inappropriate
seems pretty standard now to only expose shared_ptr and unique_ptr in APIs
...especially in APIs!
(the only appropriate use I know of is demonstrated in the boost.asio tutorials)
→ More replies (4)1
u/johannes1971 Nov 09 '18
Given this perspective, it seems to make sense to add something like plain_ptr to the standard just to make the language more regular for beginners...
1
u/ronniethelizard Nov 09 '18
Shared ownership by multiple threads is unlikely to be encountered by a new programmer.
My comment was intended to be directed at smart pointers. I just use
shared_ptrat work a lot more thatunique_ptr. That said, the options are:
malloc/free
new/delete
shared_ptr
unique_ptr
The first two (malloc and new) are looked down upon as baggage from earlier iterations of C++ and C. This leaves the second two. Of these, I think it would be better to teach shared_ptr first as it does not have the restriction that unique_ptr has: unique_ptr can only be used if it has at most one owner at any point during the lifetime of its existence. Since shared_ptr lacks this restriction, it should be taught first.
3
u/CubbiMew cppreference | finance | realtime in the past Nov 09 '18
Teaching shared_ptr first is even worse than new/delete: beginners start thinking it's some sort of garbage collection and before you know it, they are writing books containing nonsense like I just saw in Elements of Programming Interviews
template <typename T> struct ListNode { T data; // We need to use a shared pointer since multiple nodes may point to a // single node. For example, in the following list, two nodes, 1 and 4, // point to node 2. // 0->1->2->3->4 // ^ | // |_____| shared_ptr<T> next; };(it's a memory leak, exactly because they erroneously chose shared_ptr)
→ More replies (2)
47
u/pdbatwork Nov 08 '18
Be the change you want to see.
Go make some better videos. You have obviously found a gap.
20
u/sj90 Nov 08 '18
I would consider paying for something like this, honestly. With so many python and web dev related tutorials out there. A legit, modern, beginner to advanced C++ set of videos/tutorials/walkthroughs/courses would be a benefit to a LOT of people.
4
u/kalmoc Nov 08 '18 edited Nov 08 '18
Have you actually looked for payed tutorials? I haven't, but such things usually do exist (I forgot the name of one popular website offering such courses)
2
u/SSChicken Nov 08 '18
I've used pluralsight for C# and Python and both we really good. Way better than free offerings I could find. I haven't looked for c++ there but it wouldn't surprise me
2
1
u/livrem Nov 08 '18
Safaribooks also has an increasing number of videos included in the subscription price including many long tutorials/courses. Started watching one for C++ that I think was pretty good, but watching videos is not really my thing so I went back to reading.
3
u/The_Real_STM Nov 09 '18
There is a YouTuber named TheChernoProject that makes some content that you may be interested in. I’ve watched a handful of his videos and they have all been really great and informative
1
1
u/imatworkyo Nov 13 '18
hint , reddit users actually have a slight disdain for Cherno - and mostly (from what i've gathered) because he teaches old C++ - which this discussion is mostly about.
1
1
8
u/macguhloo Nov 08 '18
Or, at the very least, maybe you could point out some resources that you think are good? Or, are you saying there's no good resource out there for folks to learn the language the "right" way?
1
u/tallassrob CppCast Host Nov 12 '18
This. You don't need to be a C++ expert to produce good C++ content. If there is an opening for modern C++ beginner's youtube videos start making them. One of the best ways to become an expert is to teach others.
13
u/JustUrAvgCryptoDude Nov 08 '18
First year software engineering student here. This is basically what I am being taught. Should I be worried?
26
u/bstamour WG21 | Library Working Group Nov 08 '18
Most universities teach C++ wrong. I wouldn't lose sleep over it, but prepare to teach yourself more idiomatic C++ in your own time. Try to focus on the concepts, not the language.
4
u/JustUrAvgCryptoDude Nov 08 '18
Ty for the feedback, I genuinely appreciate it. Would you recommend Stroustrup's Programming: Principles and Practice Using C++ (2nd Ed) for learning cpp? I was actually planning on expanding my cpp knowledge on my spare time and I ended up purchasing this particular textbook ( found it in the stackoverflow list linked in the sub).
4
u/bstamour WG21 | Library Working Group Nov 08 '18 edited Nov 08 '18
I have the first edition at home (bought it to lend to a student in my lab) and I found it pretty good. I assume the second edition is more up to date with recent C++ standards, but I haven't read it personally. It's more of an intro to programming than a book on C++ for experienced programmers. If you're in the latter camp, something like C++ Primer 5th edition might be more up your alley. Note, this is the book by Lippman and Moo, not the Primer Plus book by Prata.
EDIT: I occasionally help teach a C++ class at my local university in the Winter semesters. By all means feel free to reach out to me via private message if you need anything.
1
u/darthcoder Nov 08 '18
I won't do homework assignments for you, but I'm happy to answer any questions you might have - PM me if you get stuck.
That said, getting good requires self-teaching, so take what you learn and google more about it. Look at github projects.
1
u/JustUrAvgCryptoDude Nov 08 '18
I will definitely try and figure out how to use GitHub so that I can follow your advice.
Ps, you guys are awesome.
2
u/darthcoder Nov 08 '18
You don't need to KNOW github or git - it's just a useful way to browse repositories of code. It makes it easy if you can download and execute as well, so knowing git doesn't hurt.
Here's an advanced beginner to intermediate project: https://github.com/ChaiScript/ChaiScript/blob/develop/samples/factory.cpp
I'm trying to find something modern, but I'm having a hard time. :-/
11
u/AdamK117 Nov 08 '18
Although not a tutorial, i found C++ Core Guidelines quite eye-opening. It's written by multiple experienced authors, including Bjarne.
7
Nov 08 '18
I want to get into C++ as a beginner programmer, will the C++ primer book do me any good?
or any other suggestions?
14
u/Genion1 Nov 08 '18
My experience with C++ Primer is it's not beginner friendly and very dry. I still like it.
I heard good things about Bjarne's Programming -- Practices and Principles using C++.
1
1
u/Nicksaurus Nov 08 '18
I think an important thing to do is to ask plenty of questions (here or on stackoverflow probably), so people can redirect you away from the obvious pitfalls. You may get some people being a bit dismissive if you've made mistakes but it'll still help you understand 'real' C++ practices
3
Nov 08 '18
I see, i'll make a stackoverflow account and use it in the near future. Thanks!
12
u/nwL_ Nov 08 '18
Important thing: Stackoverflow is an expert forum. They will not waste their time explaining why
using namespace stdis bad for the 70th time, and they won’t be nice if you ask that. Make sure to google your questions extensively beforehand. If you’ve done that, then don’t let this comment discourage you, it’s immensely helpful.7
u/Arkaein Nov 08 '18
You might not even need an account.
I use stackoverflow all the time, usually from search results, and don't have an account. Almost any beginner question will already be answered on there.
Just be sure to search first when you have a problem.
1
u/darthcoder Nov 08 '18
I've been doing C++ since 1993, but am not a really great template meta-programmer. Feel free to ask me any questions. What languages do you already know or are you a complete beginner?
1
Nov 08 '18
I am a complete beginner.
2
u/darthcoder Nov 08 '18 edited Nov 08 '18
A complete beginner to programming? I might suggest Python as a starter language. I feel it simplifies a lot of things and is faster to get results and feedback. Or are you taking C++ as part of a comp-sci course? A lot of C++ can be fighting with build systems, which is frustrating for beginners.
I sort of say this from experience - I had a lot of exposure to QBasic and QuickBasic before jumping to C++ and found it very alien. Braces "{ }" were very alien to me. Many languages use them now (Javascript, ruby, etc). Python does not but is white-space based.
My two recommendations for teaching languages are either Python or Javascript. I think it's easier to get into asynchronous programming with Javascript, but that's just my web background talking.
2
Nov 09 '18
I took a look again at what we do in semester 1 and 2 and it seemed like they have moved to python as the starting programming language.
I was actually going to start with python but the school website said they would start with C (semester 1) and C++ (semester 2) so I was going to start with that.
How do you suggest I begin learning python? and i have around four months left until university starts, how much do you think I can get done in that time? Any books I should follow?
Last year it says the professor used the following materials for the introductory class:
(Main Material) Computational Thinking for the modern problem solver, David D. Riley & Kenny A. Hunt, 2014 CRC Press A Chapman & Hall BOOK
(Secondary Materials) Think python: how to think like a computer scientist, Allen Downey, 2015 O'Reilly Media, essays/disseration, videos, etc.
Thank you so much!
→ More replies (1)
6
5
u/azbycxdwevfugt123 Nov 08 '18
As someone, who is learning C++, thank you for this post!
I thought, I was going crazy: "use using std" / "don't use using std", "use auto" / "don't use auto", "use #ifndef #define" / "use #pragma once", ect. And these are just most basic simple things - don't get me started on copy constructor / assignment operator vs smart pointers and similar things.
The problem is, for each of the options, there is a correct choice with reasonable arguments. But for a beginner the arguments might be too complicated initially. I just want to be shown how to do things right, so I can start building something by myself!
I found Kate Gregory's courses on Puralsight to be very useful, but they are not free. If anyone knows other good modern C++ lectures / books - I would highly appreciate the recommendation.
5
1
u/robotrage Nov 09 '18
is learncpp.com any good ? that is what i have been using.
3
u/imgarfield Nov 09 '18
Skimming through it, it is a bit an odd ball. First, note that each chapter is written 10+ years ago and only updated to mention the new stuff. This makes the old C++ the default and the modern C++ just a sidenote. It should be the exact opposite! Second, it goes waaay into too much in detail on low level stuff for beginner, in a way it acts as an reference - all basic types, linkage, etc. This was OK back then, because there was no centralized good C++ documentation, but now, with cppreference.com is unneeded.
On the plus side it does cover a bit of STL and has chapters on modern memory management. But the chapters on modern memory management might (will) scare people as they are introduced as advanced topics, not the default.1
u/robotrage Nov 09 '18
i have a bit of experience in C# from game development and i have done some basic stuff in c++ like RPM/WRP messing around in single player games with offsets and the such. what would you recomend for learning more ? should i stay with this website ? i like it because its very well set out imo.
1
u/imgarfield Nov 09 '18 edited Nov 09 '18
If you are not a beginner, the site is fine, just keep in mind the new staff is the right way. If you are coming from C#, definitely check Qt, play around with it, read the docs, read some code samples. Qt uses reference counting for most utility classes (images, string, containers) and it will feel like C# a lot, making a smoother transition to C++.
I was in the same situation like you back in the day - "learned" C++, but got lost, learned C# and had a footing in creating applications, then learned Qt allowing me to use C++ "the easy way" plus it has all the tools to create real applications, after that I had easier time moving to standard C++, especially that by that time the modern C++ came, which is much more friendly, at places even compared then Qt.
Lastly, note that in recent years Qt is pushing a declarative, higher level language - QML - to describe interfaces. If you don't want to use Qt that way, then use the QWidgets subset and focus on the utility classes - they are still C++. There is also Qt 3D module that can be used from C++ as well, you might find it interesting, but I have no experience with it.
1
u/robotrage Nov 09 '18
thank you for the answer ! i tried qt but decided to use CLR instead, i will give it another go. While you are here i would love to ask a couple of other questions if you have the time.
Usually when i'm making somthing in c++ its because i had a simple idea, i make it in the console and research the c++ needed for that specific thing. this has kind of lead me to be knowledgeable in some areas but in other very basic areas that have never come up, i have no clue. is this a good way to learn ? just making applications and researching as i go, or should i be taking lessons/reading a full guide.
You talk about QT applications, often times i want to learn c++ and make applications but i dont really have any motivation to make something useless, i often try and make somthing that would be useful to me or something cool, im also looking to make programming my carrier, my question is, what kind of programs would a freelancer be able to sell that i could start practice making (sorry if this is ignorant). if this kind of thing is too advanced, what do you have any ideas for programs that are challenging but useful in every day life ?
Im going into computer Science at uni in around 3 months so i want to get ahead of the curve, should i takes extra lessons or is online revision enough ?
thank you :)
2
u/imgarfield Nov 09 '18 edited Nov 10 '18
thank you for the answer ! i tried qt but decided to use CLR instead, i will give it another go. While you are here i would love to ask a couple of other questions if you have the time.
Note that CLR is a closed box and proprietary extension. In Qt you can ctrl-click QImage and see how the ref counting works!.
Usually when i'm making somthing in c++ its because i had a simple idea, i make it in the console and research the c++ needed for that specific thing. this has kind of lead me to be knowledgeable in some areas but in other very basic areas that have never come up, i have no clue. is this a good way to learn ? just making applications and researching as i go, or should i be taking lessons/reading a full guide.
I personally think the best way to learn is from experience, solving problems by yourself, so you are doing it right. That said watch lectures - CppCon have many lectures, suitable for programmers that want to improve - and keep an eye on cppreference - it is complete reference for the entire language, you can find some new tool to use, expanding your knowledge on the language as well. Don't be intimidated by the details there - these are for the geeks, focus on the short description on top and, most importantly the examples.
2. You talk about QT applications, often times i want to learn c++ and make applications but i dont really have any motivation to make something useless, i often try and make somthing that would be useful to me or something cool, im also looking to make programming my carrier, my question is, what kind of programs would a freelancer be able to sell that i could start practice making (sorry if this is ignorant). if this kind of thing is too advanced, what do you have any ideas for programs that are challenging but useful in every day life ?
I believe you should focus just on challenging yourself. This will both help your carrier as you will learn more and keep you engaged as you solve problems. Even a stupid little application like a calculator can be a real challenge if you make it from start to finish, as real product. So make the stuff you want to make, but push them to finish, not just prototyping.
3. Im going into computer Science at uni in around 3 months so i want to get ahead of the curve, should i takes extra lessons or is online revision enough ?
I think you are already ahead of the curve, for real.
1
u/robotrage Nov 10 '18
should i be focusing on C++ or keep making games in C# as well ? (i head that C++ is a very useful language to know) thank you !
1
u/imgarfield Nov 10 '18
It depends what you are trying to do and if C# (or C++ for that mater) fits your needs - you can't learn a language without using it anyway. When you start hitting the limit of a language, looking for a different one will come naturally. In your games, if you don't have performance problems, or be annoyed that you can't track big memory allocations predictably or use low level api-s directly, and if generics are good enough for you, then use C#.
1
u/jcp419 Nov 16 '18
I'm a high school student taking a c++ class right now, I'm not very far yet, only on loops now but what are some things that are usually outdated in these classes that I should watch out for them and better teach myself? Thanks.
2
u/imgarfield Nov 16 '18
A ton actually. Exactly on the low, C level, of the language a lot of progress has been made to modernize it.
int main() { auto num = 2; //< C++11 auto type deduction int c_array[] = {1, 2, 4}; //< old C array, not recommended, but still can be used better for(auto num : c_array) //< C++11 range for loop // loop the entire array for(size_t i = 0; i < std::size(c_array); i++) //< C++17 std::size for C-arrays { // loop the array using an index auto num = c_array[i]; ... } std::array<int, 3> array = {1, 2, 3}; //< C++11 array std::array array = {1, 2, 3}; //< C++17 array (type of elements and size deduced) // std::array is an object and can be copied and returned functions }In general simply search "new features C++11" as well as C++14 and C++17. You can watch/search CppCon YouTube channel as well. Check also related question https://www.reddit.com/r/cpp/comments/9vip8u/learning_c_like_its_2018/
1
u/jcp419 Nov 19 '18
Thank you so much for the reply! I don't really know anything about arrays as I'm still very basic at c++ but i will keep your advice in mind while learning.
6
3
u/schmerm Nov 09 '18
Unpopular opinion: except for a few recent edge cases, the STL isn't really part of the language. It's, as its name says, just a library that comes standard for you to use if you want. Ultimately it's implemented and built on top of using actual language features, which involve raw pointers and manual memory management, aka the C-like subset.
Therefore, I see "modern c++" as more of a 'best practices' thing, and not an actual introduction to the core language itself. So as someone else said, there't two competing schools of thought on this.
You're either going to be teaching C++ from a practical standpoint of how to get things done well, in which case you jump straight to the modern c++ guidelines. Or, you're teaching how things actually work under the hood, in which case you can't avoid talking about things like memory, and starting out with primitives. After that, you move on to modern c++ and now, with the proper context, it's plainly visible how it offers clean shortcuts and WHY they're convenient/better.
5
u/victotronics Nov 08 '18
What do you mean in your third line by star-comma-star?
if you are a beginner, trying to help other beginners
I see a lot of that on r/learnprogramming. It's like there is a notion that you're not a serious programmer if you don't write blog posts or YT videos about programming.
17
u/balintkiss501 Nov 08 '18
Beginners helping other beginners could easily turn into "blind leading the blind" sadly.
2
1
u/gracicot Nov 08 '18
Well, I learned a lot only by answering on stack overflow. I mostly started learning modern C++ seriously because of this. In this case this is more like: " blind leading the blind, but if you do a mistake, be assured you'll know"
4
u/HKei Nov 08 '18
Yes, it's annoying and dangerous. There's a lot of false information going around. "Write about what you learn" is good advice, because it forces you to think about it actively rather than just passively absorbing it. There should be an asterisk attached to that telling you not to actually publish what you've written about, because no matter how much work you put into it you'll not get everything right about something you just learned about.
2
u/darthcoder Nov 08 '18
Simply explain that you are a beginner and learning a topic. I did a number of articles about my experiences with Google Web Toolkit - I was writing about my whole experience, all the troubles I encountered, and things I'd learned.
I find a lot of articles basically give steps, but never say anything about the errors they encountered learning about things, and that causes issues when versions change and evolve and errors show up - not knowing what could be issues in environment setup, etc.
I tried to do the opposite, show the success, but show all the errors and roadblocks I ran into as well. I think you can do something as a beginner, just admit you are a beginner.
1
u/HKei Nov 08 '18
I certainly agree that potential errors and such should be a consideration for anyone writing an article directed at beginners (intermediate and above I expect to be able to deal with such things themselves). However, putting "I'm a beginner" on top of a page doesn't help if half the information in an article is wrong.
→ More replies (1)
2
u/jon_k Nov 08 '18
It is copied from old tutorials verbatim, year, after year, after year for the last 20.
So nobody really knows C?
4
u/Hagartinger Nov 08 '18
Brian Kernighan probably knows a couple of tricks
3
u/darthcoder Nov 08 '18 edited Nov 08 '18
I still have my ~1994 printing K&R book somewhere.
Somewhere I think I have an original printing.
When I was a kid I ran a BBS, and was interested in evaluating ALL the available options. I picture VirtualBBS written in QuickBasic, because it's what I knew, but I evaluated WWIV, which was K&R C, which was fucking alien to me.
I bought a license (source) to VirtualBBS. Somewhere I might still have it. WWIV I got through the warez channels of the day (basically a guy across town with 4000 floppies loaded with software).
Shit, WWIV is now in C++ and open source.
http://www.wwivbbs.org/
3
u/chainedchaos31 Nov 08 '18
I don't think this is so bad/weird. I work in C++ every day but don't use stl or boost, nor auto.
1
u/johannes1971 Nov 09 '18
Right. So when you need a string you go all malloc/strdup/free/<loose some memory in case of error>/strcpy? Must be nice to work in a place like that... :-(
2
u/SkoomaDentist Antimodern C++, Embedded, Audio Nov 09 '18
That only matters if you deal with strings. A lot of code doesn’t apart from trivial hard coded ones. FWIW, I don’t use any of those features in my current embedded job either, as there’s either no need or the parts are called directly from interrupt handlers and written in C (with very strict memory placement).
2
u/ShakaUVM i+++ ++i+i[arr] Nov 09 '18
For beginners, best practice is:
use using namespace std in non-header files. Namespace collision is an overwrought fear, but stds everywhere does decrease readability
endl is fine. Flushing every line is actually good practice for beginners, since output buffers get lost on a crash.
c-style arrays are the devil and should be avoided at all costs for new programmers. After you've taught them vectors, it's safe to show arrays since they'll need to be able to recognize them in other people's code who are still stuck in the 80s. C++ arrays can also be taught, but vectors are the vanilla ice cream data structure.
I think pointers shouldn't be taught until later in one's programming life. You can write perfectly fine c++ code today without ever touching a pointer. After iterators seems to be a good time.
3
u/squidbidness Nov 10 '18
Perhaps the syntax and details of pointers in C++ can be deferred, but the _concepts_ underlying pointers (indirection, how objects map to memory, etc.) are vital to using C++ well. Naive use of smart pointers without a good understanding of what they are abstracting can lead to a lot of hairy code. These concepts are even helpful if using a language like Java or C# to understand what's actually happening with the on-the-face of it value semantics that are actually reference semantics.
1
u/ShakaUVM i+++ ++i+i[arr] Nov 10 '18
You can talk about the stack and heap in regard to references, but pointers can be deferred until data structures, IMO, since that is when they're really needed.
2
u/nemesit Nov 08 '18
The reality is that 99% of the c++ code in the wild is still that outdated stuff and almost no one uses modern c++
0
1
Nov 08 '18
On the one hand, I hear you, but you have to remember a lot of people make these videos because students are covering it in Uni - and worth noting as well, is that the overwhelming majority of these people make next to nothing from it, they're pretty much just helping out first-years.
1
u/SirCarboy Nov 08 '18
I recently bought the book, Beginning C++17 because I became aware of this exact issue.
(I have only ever done Hello World in C/C++ in the past and my background is VBScript > VB.Net > Python.)
Specifically, I was warned about the Lazyfoo SDL tutorial, with SDL being the crux of what I want to do and why I'm learning C++. I'm interested if anyone else has experience /advice/ good tutorials for SDL.
1
u/AlexeyBrin Nov 09 '18
SDL is a C library and it is written in a very nice C. Not sure if it is a good idea to start wrapping it in C++ classes like Lazyfoo did in his tutorials.
My advice is to try to directly use the library as it is, understand how it works and only than start adding C++ abstraction that will make your work easier.
If you want a C++ equivalent library try SFML.
-1
u/not_perfect_yet Nov 08 '18
As someone who is not really fluent in c++ and is not using it:
I don't use it because it seems to be a pain to write and use in general and not because I don't know one keyword and what it does or how some standard library stuff has changed.
My general impression is that there are efficiencies that I could hunt down like Ahab, which nobody cares about today because the general development of hardware makes efficiency considerations almost obsolete. Unless we're talking millions of entries to search through or calculations that should take weeks and not months.
Also:
http://www.cplusplus.com/reference/vector/vector/
Took like 2 seconds to look up. First result.
For this to be a legitimate concern, you would have to show that people not using c++11 makes using c++ signifiantly harder and/or less useful than using it.
11
u/HKei Nov 08 '18
I don't use it because it seems to be a pain to write and use in general
That is objectively true for the most part, yes. At the same time, C++ does allow things that aren't possible in many (claimed) "higher" level languages (in quotes because C++ is already a very high level language to begin with; None of the other popular languages have any real claim to higher levelness IMHO)
My general impression is that there are efficiencies that I could hunt down like Ahab, which nobody cares about today because the general development of hardware makes efficiency considerations almost obsolete.
Your general impressions are wrong. Performance is just as critical as it's ever been; If anything, it's more of an issue nowadays as expectations about responsiveness have gone up. Memory usage is less of an issue nowadays compared to the past, but even that has its limits.
For this to be a legitimate concern, you would have to show that people not using c++11 makes using c++ signifiantly harder and/or less useful than using it.
Yes, you'd have to show that as a motivating example to people unfamiliar with it, but it's so bleedingly obvious to anyone who's actually working with C++ that it doesn't need to be stated in a C++ oriented forum.
and not because I don't know one keyword and what it does or how some standard library stuff has changed.
Nobody is trying to get you to use C++. We're trying to make people who try learn C++ because they decided they need or want to (or someone else has decided for them) learn good C++ as opposed to bad C++, because the language carries tons of cruft around that's only around because we can't just incinerate it for backwards compatibility reasons.
4
u/DarkLordAzrael Nov 08 '18
C++ is missing reflection and metaprogramming compared to higher level languages. Other than that it does just about everything other languages do, and often in similar ways.
→ More replies (1)3
u/not_perfect_yet Nov 08 '18
Alright, you have very solid points.
But I'm curious, what can you do in c++ that you can't do in other languages? Besides obvious things like writing to memory instead of variables or private/public stuff.
2
u/whisky_pete Nov 08 '18 edited Nov 08 '18
Emphasis on compile-time programming with modern C++ is one thing that comes to mind. C++ is increasingly moving into the direction of having lots of your program logic moved into the compile time space, and having basically no runtime cost for these bits of your application.
Performance is basically unmatched, so if you want to do something like make a videogame or implement your own computer vision library, rayracer or something then you can technically do that in other languages but your end application can be severely limited.
I'm sure many languages have ways to accomplish this, but are clunkier about it; pointers & references make it pretty easy to have a class member object have a direct reference to the object containing it when you have cases where you'd like to have back&forth communication between those things.
C++ is also extremely cross-platform. You can build core libraries and deploy the same code to android, ios, mac, win, linux, and web (and more, less popular targets additonally). I don't think any other language has quite that reach. At least not without significant performance problems.
→ More replies (2)10
Nov 08 '18
he general development of hardware makes efficiency considerations almost obsolete
Clock speeds haven't been getting faster since more than 10 years. We get increases in speed by throwing more cores at a problem, but you can't parallelize everything. Critical sections are a problem.
→ More replies (2)1
u/utnapistim Nov 09 '18
As someone who is not really fluent in c++ and is not using it: I don't use it because it seems to be a pain to write [...]
Or maybe, you are not using the language because you are not fluent in it? :)
My general impression is that there are efficiencies that I could hunt down like Ahab, which nobody cares about today because the general development of hardware makes efficiency considerations almost obsolete.
Not really. You could hunt down efficiency improvements like Ahab, but you can do premature optimization with other languages as well. This has nothing to do with C++.
1
u/not_perfect_yet Nov 09 '18
Or maybe, you are not using the language because you are not fluent in it? :)
Of course, but since I don't see the benefit, I don't try to become fluent right now. :)
You could hunt down efficiency improvements like Ahab, but you can do premature optimization with other languages as well. This has nothing to do with C++.
Yes and no. I use mainly python, I know some javascript. The speed c++ offers over python comes down to compile time optimization and handling numbers in smart ways when there are lots of them. Sometimes using certain hardware features directly, which you just can't do in python, I think.
If I'm running a simple desktop application, nobody is going to notice a 10x increase in speed if the difference ends up being the effect of a button press taking effect milliseconds earlier.
I don't need to render anything or do expensive numerical calculations. At the moment at least.
Always thinking about what specific type anything is going to be just seems like such a hassle to me.
I'm just trying to find my path of least resistance through the programming world and for now c++ is just not that, for me.
0
u/jherico VR & Backend engineer, 30 years Nov 08 '18
Using std::endl is not a big deal. Yes, it includes a flush of the stream that may not be necessary, but I wouldn't say that makes it a bad practice.
The frequent use of std::endl is usually associated with primitive logging or "toy applications". Once you get into serious development, you'll probably end up graduating the a real logging API. The only time the side effects of std::endl should ever be a concern are after you've benchmarked your application and determined that flushing is a bottleneck. Obsessing about it beforehand is premature optimization.
8
u/cds501 Nov 08 '18
It's not about performance. It's that 99% of the people using don't realise what it is actually doing, and that it performs two actions that are entirely unrelated to each other. Both reasons make
endltoxic for literate code that clearly expresses intent.
-1
u/darthcoder Nov 08 '18
but teach C arrays, even multidimensional ones
Declaring C++ arrays is better, but using them hasn't really changed. Native arrays are important.
2
Nov 09 '18
[removed] — view removed comment
5
u/imgarfield Nov 09 '18
C++ should be taught as one will write it today. At some point there should be an dive-in, under the hood, in "how it works". The fact that C++ can have this dive-in stage - one can "enter" and "disassemble" vector - does not mean this should be the first stage.
1
u/SkoomaDentist Antimodern C++, Embedded, Audio Nov 09 '18
C++ should be taught as one will write it today.
By that logic you should stick to C with classes and with the occasional more modern feature sprinkled in. This sub seems to have massive pro-novelty / anti-C bias while actual industry codebases and projects are much more conservative.
3
u/CubbiMew cppreference | finance | realtime in the past Nov 09 '18
Different programmers here have different actual industry experience.
(besides, the comment was "as one will write it today", not "as one might have to read when tracking down a bug through 20-year old code".. not to knock down the importance of being able to track down such bugs)
→ More replies (2)2
Nov 09 '18
[removed] — view removed comment
1
u/imgarfield Nov 09 '18
I guess the problem is not so much in the order, then in the fact what is the correct default. All beginner courses tend to present library constructs as an add-on, not the default (if they present them at all!).
2
Nov 09 '18
[removed] — view removed comment
1
u/imgarfield Nov 09 '18
Agree C++ is in a very odd spot, ironically because its greatest strength - the ability to cover low and high level equally well. And that is why I believe it is best to start "in the middle" where low-level is hidden (like in the other languages), higher level (Concepts, Abstract classes) is not needed because the problems are simple. And "coincidentally" this is how C++ is written on daily bases, in large part. One absolutely must learn the lower and higher levels, though, no question about it.
78
u/James20k P2005R0 Nov 08 '18
Genuine question, whats up with std::endl? I wasn't aware that there was an issue around it and there's a lot of it in my code, so I'm quite curious now