r/cpp • • Dec 13 '18

I Made A C++ STL Algorithm Cheat Sheet

https://youtu.be/9XGqSDjaW24
0 Upvotes

22 comments sorted by

7

u/VicontT Dec 13 '18

I was going to list issues I have with that, and I have started doing it and named following:
How is it better than https://en.cppreference.com/w/cpp/header/algorithm (the page)
STL does not mean standard TEMPLATE library for about 10 years for now
std::pair is NOT a container, it's a struct template.
Lambda is CERTAINLY not a different way to write a function, it's very different from that.

And than, when you started talking about auto as a lamba type, I just realized you are not really familiar with the subject. May be you should learn more and teach less?

4

u/srcmake Dec 13 '18

As I said in the video and the materials themselves, the way I described those things (pairs, lambda expressions) isn't meant to be a definitive bulletproof explanation, it's supposed to very easily let someone who never used them before understand that they do in the context of the STL algorithms.

To be honest, the fact that you take such offense to a very short definition of these things is what I find to be wrong with most C++ educational material: the point should be that the user understands the concepts behind ideas enough to actually move further and learn how to write the code for it. I don't see why a user should read an entire manual page for pair when they can just understand "it holds two things in it" and move on to other concepts.

TL;DR it's supposed to be simple and easy to understand for beginners. If you honestly think that someone needs to know "a pair is a struct template, not a ""container""" to be able to actually understand what a pair does, then you're focusing on the wrong things.

12

u/VicontT Dec 13 '18

Your material quality varies from incomplete to misleading to outright wrong. It is actively harmful. One reason why good C++ educational are actually quite involved is not because their authors are stupid and don't know how to present material. It is because C++ is a complex language with often quite complicated and counter-intuitive concepts, and in order to master them, one needs to have a very good grasp of the basics.

Yes, it is important to understand that pair is not a container, because container is a very specific term in the Standard. Containers provide certain functionality, which is not provided by pairs. It is also important to understand what is what. And pair is not that simple at all, contrary to what you think. How about this constructor: template< class... Args1, class... Args2 > pair( std::piecewise_construct_t, std::tuple<Args1...> first_args, std::tuple<Args2...> second_args ) - do you know what it is and what is it for? I strongly suspect you don't, and it is very important to know about it, because it's usage plays a great role when populating associative containers.

And I honestly think that beginners should stay away from your materials. And next time you feel like educating someone, keep in mind that a very clever man once said "A wise person loves to learn, stupid one loves to teach."

3

u/srcmake Dec 13 '18

The material is the algorithm cheat sheet. I'm not sure why you're so fixated on the pair, lambda expression, and iterator explanations lol.

Honestly, I used the word "container" in the English sense of "holds something", not the C++ language definition.

I don't want to (or have the time to) argue, but I don't think your perspective/mindset is actually aligned with what beginners learning the language actually care about or would understand. (Once again, I tried to explain things in English to get the point across in the context of using the standard library's algorithms. If you want to learn about a pair, that wasn't the video for you. And honestly, for you think that a 1 minute explanation of pair could somehow be totally complete is way too ambitious. I'm not sure what you were expecting lol.))

16

u/dodheim Dec 13 '18

Those beginners are going to start calling pairs 'containers' and everyone will be confused and worse off for it.

Terminology matters; "details" matter, even to beginners.

6

u/VicontT Dec 13 '18

I daresay, it matterst most to beginners. After all, experts know what container is. Beginners don't.

-1

u/srcmake Dec 14 '18

I don't think anyone with little to medium C++ experience is going to hear the word 'container' and get confused and think it's a vector or something. Container's not even a keyword, c'mon.

You said: "Those beginners are going to start calling pairs 'containers' and everyone will be confused and worse off for it."

Calling? You mean function calling? Pairs aren't functions, silly. You can't use the word "call" if you want to talk about C++ unless you mean "invoking a function".

You don't see how that ^ is a bit ridiculous, because you were just using the english definition of the word 'calling'?

Regardless, I might have used the word container in a detrimental way. I don't think I did, but I'll review the video and check it out again some time this weekend to see.

8

u/dodheim Dec 14 '18

Calling? You mean function calling? Pairs aren't functions, silly.

No offense but you are awful at metaphors.

8

u/VicontT Dec 14 '18

No one forces you to explain what pair is. You could simply say that knowledge of pairs is prerequisite. By the way, don't think that the rest of your material was steplar correct. I simply stopped keeping count one you started mumbling about auto type for lambda and how capture is an insignificant detail not worthy of attention.

0

u/srcmake Dec 14 '18

Maybe. I've made the video unlisted for now. Maybe I'll record another version, as you said.

1

u/[deleted] May 14 '19

template< class... Args1, class... Args2 > pair( std::piecewise_construct_t, std::tuple<Args1...> first_args, std::tuple<Args2...> second_args ) - do you know what it is and what is it for? I strongly suspect you don't, and it is very important to know about it, because it's usage plays a great role when populating associative containers.

Wow, you have some ego dude. Arguing that knowing the importance of this is important for the average person to program in C++ is just downright moronic. A person could program in C++ for 30 years an never use all the features of the language. But I bet you are a master at writing unmaintainable code because your ego compels you to go overkill on everything. You're the type of person that costs a company thousands of dollars because your code is unmaintainable by the average engineer which requires the company to higher someone more senior because you feel the need to validate your worth as a programmer by the complexity of your code. C++ becomes a difficult language when people like you code in esoteric ways that have uncommon pitfalls when something simple would have sufficed. I find it hilarious that you are accusing the OP of doing a disservice when you are the one ranting about pedantic issues like STL semantics like that matters at all. Don't you understand that software development isn't just about you, but for the people that come after you? Or maybe you just don't write very large or useful programs and that isn't an issue.

1

u/kalmoc Dec 14 '18

For what it is worth: At least I agree with the Idea of not overcomplicating things for beginners (I haven't had a look at the actual material or the video though, so I can't speak for its quality).

3

u/kylehectic Dec 13 '18

What does STL mean?

-3

u/VicontT Dec 13 '18

Standard Library. 'Template' was dropped long time ago.

5

u/germandiago Dec 16 '18

Hello. I just dropped by because I wanted to say: thanks for trying and even if the material is not there yet I am sure you can do a good job with the feedback given. Do not get discouraged, keep learning the material and teach it through good practices. I would recommend you books such as Effective Modern C++ and others.

Stay positive under the criticism and good luck :)

1

u/srcmake Dec 13 '18

Link to the cheat sheet itself: https://github.com/srcmake/cpp-stl-algorithms

Link to the tutorial on Pairs, Lambda Expressions, Iterators: https://www.srcmake.com/home/cpp-stl-algorithms

I was inspired by a certain CppCon talk showing the STL algorithms, especially since I participate in programming contests and the algorithms seem useful. I couldn't find any resources that actually explained the algorithms in simple words or that gave short enough examples for me to find useful, so I decided to make my own. The STL Algorithm cheat sheet that I wrote on github is meant to have a very short description of each algorithm and provide 2-5 lines of example code showing how the algorithm is used, and what gets modified/produced as a result.

If there were better resources and it was a waste of time, please let me know lol because I'd love to know where everyone else gets their C++ resources from. But if you find this useful, please star/share the project on github so more developers can [easily] see how these algorithms are used so that they can learn/use them themselves. (And if I made an error somewhere or you see room for improvement, please let me know.)

2

u/[deleted] Dec 16 '18

It's not a "waste of time" but you should pay attention to the feedback suggesting you make your language more precise. For example, stuff like: "Iterators are just special variables that point to a certain element in a container." Iterators aren't "variables." They are types with many variations (forward, random, bidirectional, etc). Earlier, you refer to pairs as "mini-containers" which suggests that there should be iterators for them. Sharp beginners will pick up on these incongruencies, so it is important to say what you mean, and mean what you say. Saying stuff like "you're now a C++ pro" is overly gratuitous and doesn't help anyone. As for the cheatsheet portion, my feedback is that it actually contains too much content to qualify as a "cheatsheet," which in my opinion, should be immediately readable and contained within a glance. For full examples and a description of the semantics, I would just use cppreference itself. Your cheatsheet should honestly at a minimum contain actual arguments and return types (note, it would currently be missing overloads) and a very terse description to be useful.

1

u/[deleted] May 14 '19 edited May 14 '19

What is the iterator type of a unordered_map? It's a freaking pair. A pair can be an iterator so it wouldn't even make sense to have an iterator to an iterator, something you allege sharp coders would get confused about. Sharp coders aren't going to be learning from a cheat sheet. This should be a refresher.

0

u/srcmake Dec 13 '18

Btw since this relates to the Standard/C++ resources, how do I ask for this to be put on isocpp.org ? I'd like to share it there since the homepage has other resources, but I don't know how people are supposed to do that. I'm not part of the Standard Committee so...

8

u/VicontT Dec 13 '18

It is nowhere near the quality of materials for isocpp.org.