Now the CppCon 2017 conference is taking place, and video from there has already begun to appear on their youtube channel. And I thought, why not try to make notes of interesting lectures. Of course, I’m not very sure how long I have enough depends on how much you like it.
This is the first introductory video. It is not so interesting for me, but I could not miss it either, it's Straustrup. Further, the text of his face. Headings are taken from slides.
Disclaimer: All further text is a rather brief retelling that is the result of the work of my perception, and what I considered to be “water” and ignored could be important for you. Sometimes the performance was: "(important thought 1) (minute of water) (important thought 2)". These two thoughts smoothly flowed into each other, and I got quite sharp jumps. Where it is possible to smooth it, but I thought it inappropriate to completely brush the text, it would take a long time.
When I was asked to speak at the opening of the conference, I wondered what I could tell you about what is important to you and what you have not heard a million times. And I decided to tell you about learning the language C ++.
Let us ask whom we teach, what, why and how. Need to do it better. I do not criticize anyone in particular, but I feel that we should do it better. Not all of us are teachers, but nevertheless, there are always cases when we are engaged in training. For example, we tell colleagues about the latest features or give advice. We communicate on StackOverflow, Reddit, we conduct blogs, etc. But you need to give good advice. Tips that move the world forward.
There is one thing that worries me a lot - people often have very strange ideas about C ++. I'll come back to this problem a little later.
When you learn, think about what you want to achieve. And from this start. Do not start from "what we have already done" and "what is easier to start," and if you are a teacher, then from "what is easier to check."
No need to focus on language features. For example, you have seen examples that explain the problem of converting a signed short
to an unsigned int
[ tells about language teaching in general, and not about C ++ features ]. This is not interesting and can be seen in the debugger or read the manual. Teach so that such a problem does not appear.
Do not try to teach everything, you can not. Carefully select a subset of the language.
One of the emerging problems of learning C ++ is that the language is studied on its own, separate from the libraries. Vector on page 697, sort through 100 pages. It teaches that stl is a boring, complicated garbage. And at the same time: your Linked List or Hash table is cool, cooler than stl.
[ in the speech, the author uses the word clever with a negative nuance, something like a person who tries to seem to be clever ]
People who want and demand the "latest" often do not know the basics. Review the basics.
Keep it simple. Do not rush into the most difficult and sophisticated. Do not use the most advanced algorithm that you can find. I would not choose bubble sorting, but I would also not choose a "complete general algorithm for everything." Offer the simplest example that illustrates a technique or feature.
Focus on common cases. Be rational. Do not tell the students, "Do it only this way, this is right, it tempers the character. And you can get the top five if you answer that way." It is necessary to explain why it is necessary to follow the rules, give pupils good ideals, ideas, techniques.
Of course, when teaching, it is very tempting to stand in front of colleagues, a group of people and show with all your appearance: "Look, this is a complicated thing that you did not understand. It means that I am smart." This is not very good training.
If you study only the language itself, then once in reality you can simply “drown”.
Use different tools. Not only the compiler and tutorial, but also IDE, debuggers, version control systems, profilers, unit testing, static analyzers, online compilers. Tools need to be modern (sometimes I get questions on Turbo C ++ 4.0 :()
It is necessary to learn the principles and fix in practice. Use graphics, networks, the Internet, Raspberry Pi, robotics, etc. This is obvious to you, but not obvious to universities. Do not say that it is simple and fast. And remember that no one can do everything.
How often do we learn? We explain language plus a little standard library. Without any graphics, user interface, web, email, databases ... And many students think that C ++ is a boring useless language. But this is not so, because such things as browsers, DBMS, CAD and others are written in C ++. Before the start of the lecture, spend 5 minutes on practical application.
It is very important for us, the C ++ community, to simplify getting started, the ability to use right now.
How are users in different industries divided into groups? Let's give an example with a photo. The result depends on the equipment and the user. Personally, I'm new to photography. Most features of a professional camera will be useless to me. It weighs a lot, is expensive. For her, there are many accessories in which you can drown. But with it you can make excellent photos, if you spend a lot of time learning. Similarly, there are many people who cannot use various features of the language and library.
On the other hand, we have devices that can be used immediately. Such a device is cheap, simple, "cute." Forgives mistakes, does not require a lot of effort to master. It is a "thing in itself." Few extensions and additions, if any. No interchangeable parts.
Sometime while teaching, I needed the students to have a GUI library installed. It turned out that installing the same library on student Macs, Linux, Windows is quite painful.
Each photographic manufacturer offers a “system”, which assumes that you can gradually upgrade equipment and move to the next level as you learn.
It is not necessary to give a beginner a professional camera with all the bells and whistles. In this case, he will have difficulties and the result will probably be worse than if he used the "soap box". Therefore, any one solution would not be suitable for all.
Language must be represented by three distributions. For beginners, amateurs and professionals.
Base:
import bundle.entry_level; // import bundle.enthusiast_level; // import bundle.professional_level; //
Extensions (which are not included in the database):
import grahics.2d; import grahics.3d; import professional.graphics.3d; import physlib.linear_algebra; import boost.XML; import 3rd_party.image_filtering;
As a student for the second week after the start of training can install a library of graphical interface and work with databases? Different libraries and systems are collected in different ways. Different libraries may be poorly compatible. A dozen incompatible package managers are not the solution. Make simple tasks simple.
> download gui_xyz > install gui_xyz
Or in an equivalent way, for example in IDE:
import gui_xyz; //
My vision of modern C ++ (as usual):
Modern C ++ is not C, Java, C ++ 98 and is not the language you programmed 10 years ago. Inertia is the enemy of good code. The teachers, justifying the non-use of modern standards, say that "we do not do that", "this is not inserted into my curriculum," "maybe in 5 years." Students have more confidence in the Internet than in teachers. Some people think that they are smarter than teachers, and sometimes they are right. I have been stably every year on the course were students, absolutely convinced that they are smarter than me in programming. In these particular cases, I am reasonably confident that they are not right [ laughter in the hall ].
To implement this, the C ++ Core Guidelines project was launched 2 years ago. He gives specific answers to questions. He has many, many participants, including Microsoft and Red Hat.
Do not separate the examples from the explanation. 5 pages of bare theory is a waste. Give examples and explanations to them. Without explanation, people do not generalize. They just copy-paste and invent the interpretation themselves, sometimes very strange.
Always explain the reasons. For example:
//1 int max = v.size(); for(int i = 0; i < max; ++i) //2 for (auto x : v)
Why is 2 better than 1? Example 2 clearly shows intent, v can be changed without rewriting a loop, and less error prone. It should be noted that 1 provides more flexibility. But goto is even more universal, and therefore we avoid it.
[ I.4 means point from Core Guidelines ]
void blink_led1(int time_to_blink) // - void blink_led2(milliseconds time_to_blink) // void use() { blink_led2(1500); //: ? blink_led2(1500ms); blink_led2(1500s); //: }
[ Here milliseconds is some kind of simple type not from the Chrono library, so the last line results in an error. The text below describes a generalization of the type for a unit of measurement taken from Chrono. If interested, you can read my description of this library ]
template<class ep, class period> void blink_led(duration<rep, period> time_to_blink) { auto ms_to_blink = duration_cast<milliseconds>(time_to_blink); } void use() { blink_led(2s); blink_led(1500ms); }
Error_code err; //: //... Channel ch = Channel::open(s, &err); //out-: if(err) { ... } : auto [ch, err] = Channel::open(s) //structured binding if(err) ...
Should this code use the return of two parameters?
auto ch = Channel::open(s);
It is better? Yes, if the unsuccessful discovery was provided for in the program.
The word "smart" in the context of using C ++ - abusive. Find the bug:
istream& init_io() { if(argc > 1) return *new istream { argv[1], "r" }; else return cin; }
// auto x = m * v1 + vv // m v1 vv // void stable_sort(Sortable& c) // "c" , "<" // ( "==") { //... }
I recommend you go to github and read the Philosophy rules section containing the basic concepts.
My goal is very simple. We can write type and resource-safe code without leaks, memory damage, garbage collector, expressiveness limitations, performance degradation.
Two open projects are being developed now: an analyzer, for checking the rules of the Core Guidelines, and the GSL library - the guidelines support library ( implementation from Microsoft ).
No, I told not all about learning. Only barely scratched the surface.
[ Stroustrup has a super-ability to answer simple questions for 5 minutes, so I have greatly reduced his answers and the questions themselves too ]
Core Guidelines are too comprehensive. how to learn?
No need to read everything. Read the introduction, then the section with the philosophy. No need to search for the rule, the rule itself will find you.
Does the standard library need simple functions? For example random [ I suppose that I mean a function without the need to set the initial value and the possibility of setting the distribution law ]?
Yes, we are.
You talked about 3 C ++ distributions. Who should do this?
It is unlikely that the committee will deal with this, so I think it should be done by the community. It will be easier with the development of a single package manager and modules.
My daughter goes to college and we did a thermostat project together. So, in order to get the temperature and display on the screen, it took a whole semester of studying C ++. What do you think about that?
Yes, there is such a problem. With modules it will be better.
Is it necessary to teach programming as a general subject, as well as math
I am not competent in this matter.
mmatrosov : you said that you need to use libraries in training. Wouldn’t it be that a new generation of programmers will not know the basics?
Depends on the goal. I teach students how to implement a vector, they should know about pointers, but not everyone needs to implement a lock-free code.
Source: https://habr.com/ru/post/339036/
All Articles