Not so long ago, on the basis of our office, we conducted a free lecture course "Modern and Effective C ++" and recorded them on video. The course was designed for recently arrived in our team of programmers, interns and all comers. In this article we would like to highlight the purpose of this course, the process of preparing for it, to summarize. We hope that for some of you our course of lectures will be interesting and you will appreciate our work. We wish you a pleasant viewing of reports!
How did the idea come
Our company PVS-Studio is developing a static code analyzer that identifies errors and potential vulnerabilities in the source code of programs written in C, C ++, C # and Java. And it’s not a secret to anyone that we are interested in attracting young specialists. It often happens that we have students who would like to gain professional experience in the field of programming and who still lack knowledge in this area. In addition, our newly arrived specialists also need help with professional growth. In view of the foregoing, it was decided to prepare a course of lectures on programming and conduct it. This idea pursued at least three goals: to show young professionals and interns how to write code more accurately, more efficiently and more safely; popularize C ++ outside the office and demonstrate that the language is promising from the point of view of learning and further work with it; to popularize our company as an interesting employer. Having determined our goals and inspired by the idea, we set about making our dreams a reality.
Training
With further discussion of our idea, so many questions and so few answers began to appear (surprisingly, yes?). On the agenda were: time and place, who will prepare the course, who will conduct it, what topics should be covered, whether we will record the course on video, how we will do it, how to promote it, and where it is better to do it and there is still a huge the number of questions that we discussed for another two weeks and repeated like a dash with the words: “And how ...?”, “And who ...?”, “And where ...?”.
And so, when everyone’s thoughts and ideas “synchronized”, it was decided that the course would be designed for 12 lectures 2 times a week from July 9 to August 15. Andrei Karpov and Philip Handelyants were selected as lecturers.
On our YouTube channel, we have put all the videos in a separate playlist for easy viewing. We also have a VKontakte group , which contains all the information on the lectures. Thus, it was possible to go to the page of a separate lecture, see what it was about, register for it, and later also watch a lecture recording if something wanted to be repeated or if a person could not attend in person.
Let's dwell on the topics of lectures and their content.
C ++ 11 standard innovations
C ++ 11 ... how much meaning there is in these five characters ... The first lecture turned out to be the longest and, perhaps, informative, because in almost two hours Philip and the guys discussed a lot of questions. So they started by looking at the C ++ language and the relevance of its use. Then they went directly to the changes in the C ++ 11 standard themselves. During this part, the extension of the core of the language was considered, namely:
pseudo-random number generators instead of rand () ;
link wrappers ( std :: reference_wrapper );
generalized wrapper for functions ( std :: function );
traits ( type_traits ).
Of course, it is worth understanding that such a huge amount of information cannot be covered in detail in two hours, so some points were told in more detail, while some had a more familiarization function.
C ++ 14 standard innovations
The second lecture was devoted to reviewing the innovations of the C ++ 14 standard. There were not many changes, so the listeners “suffered” not for 2 hours, but only 40 minutes :-). As in the first lecture, attention was paid to two main points: changing the C ++ kernel and changing the standard library.
Here's what they talked about:
output of the return type for functions without explicitly specifying the final declaration of the return type ( trailing return type );
decltype (auto) ;
easing restrictions for constexpr ;
variable variables;
aggregate initialization;
binary literals
number separators;
generalized lambdas;
lambda capture list of functions with initialization;
Having highlighted the innovations of the C ++ 11 and C ++ 14 standards, we focused on the topic of type inference in C ++. Why was it about this topic? Before C ++ 11, few people thought thoroughly about what it is and how it works, with the exception of “template magic” writers and compiler developers.
Times pass, and now the C ++ programmer needs to take into account the innovations accepted by the standards: auto , forwarding links, decltype , lambd capture list, type inference by return value, etc.
Innovations have begun to be actively used by developers in fresh code, and it is very important to understand what this means and what the compiler will do in this situation.
C ++ 17 standard innovations
Speaking about modern C ++, it was impossible not to mention the last existing C ++ standard. The narration was presented according to the already established scheme: the changes in the kernel, and then in the standard library, were considered. Thus, we considered:
output of types of template classes from constructors;
throw () is considered as noexcept and marked as depricated ;
noexcept has become part of the type system and is now taken into account when choosing function overloads;
copy elision ;
convolution ( fold expression );
if / switch with initializer;
if constexpr , structured bindings ;
nested namespaces;
new attributes [[ fallthrough ]], [[ maybe_unused ]] and [[ nodiscard ]];
hexadecimal real literals;
static_assert accepts the message as an optional parameter instead of a required one;
typename is now allowed in template template options;
Another new rule for auto type output with brace-initializer-list ;
inline variables;
auto can be used in template parameters;
preprocessor directive __has_include ;
register has become a reserved word and is not yet used;
std :: string_view ;
std :: optional ;
std :: any ;
std :: variant ;
std :: byte ;
std :: uncaught_exceptions instead of std :: uncaught_exception ;
boost :: filesystem with changes flooded as std :: filesystem ;
try_emplace and insert_or_assign for associative arrays;
free functions std :: size , std :: empty and std :: data ;
template variables for type_traits ( std :: * _ v <T ...> ).
STL: concept, containers, iterators
The fifth lecture was entirely devoted to the standard template library. We discussed the history of STL, what it consists of and how to start using it. We talked in more detail about standard containers ( vector , list , forward_list , deque , ...), adapter containers ( stack , queue , priority_queue , heap ) and iterator types ( input , output , forward , bidirectional , random , contiguous ).
STL: Algorithms, Wrappers, Functional Objects
In this lecture, they continued to work on the STL. Philip talked about the fact that you don’t need to engage in bicycle building and it’s time to start using standard STL algorithms. Various categories of algorithms, useful functional wrappers ( plus , minus , ...) were considered.
Static analysis as an integral part of development when writing C ++ programs
Philip decided to relax a bit :-), and the seventh lecture was held by our technical director - Andrey Karpov. He spoke about static analysis in general, and why it is necessary to use it in work. Andrei explained the direct relationship between using a static analyzer and improving the quality of code when working on a large project. It would be foolish to talk about static analysis without examples from our working reality, therefore, naturally, examples of detected errors by PVS-Studio were also included in the lecture. We talked about the right and wrong ways to use code analysis tools.
PVS-Studio coding standard and general techniques for developing effective C ++ diagnostics
Philip is still resting, and Andrei and his students glanced a little at the PVS-Studio internal kitchen, having examined two topics.
Firstly, we talked a little about the coding standard adopted by our team, and why we decided to design the code this way, and not otherwise.
Secondly, we discussed some methods of microoptimization of the code that we use when developing the analyzer. We discussed about the famous phrase "premature optimization is the root of all evil". The topic was touched upon in passing, but Andrei soon plans to devote a separate report to it “ Premature optimization is evil! Long live premature optimization! ” At the C ++ Russia conference. So we invite everyone to this wonderful conference and Andrey's report.
The lecture was primarily aimed at the interns of our company and those who eventually want to become them. Regarding the content, such moments of the PVS-Studio coding standard were discussed here:
general provisions;
Rows
variable naming;
type naming;
function naming;
code alignment;
table layout of a difficult condition;
separating spaces;
premature optimization;
optimization of class sizes and structures;
variables with short lifetimes and more.
Metaprogramming in C ++: templates, constexpr calculations, etc.
Philip had a rest, gained strength and told for “template magic”. Everyone knows that metaprogramming with each release of a new standard is becoming more and more difficult and incomprehensible, in the codebases the amount of "template magic" is constantly growing. The lecture set the task to keep up to date, telling about the main aspects of metaprogramming:
template functions;
Template classes
full and partial specialization of templates;
variable templates;
convolution.
Listeners after 30 minutes:
But that was not all! Philip decided to finish them off with a final talk about computation and type manipulation at the compilation stage, about the CRTP (Curiously recurring template pattern) pattern, SFINAE and detectors.
Assembly of C / C ++ projects and its optimization
Survivors after the previous lecture were told how to drink less coffee and fight less with swords while their project is being compiled.
The following aspects were raised:
translation phases in C / C ++;
addictions;
external templates;
precompiled headers;
parallel and distributed compilation;
compiler cache;
replacement of translation components: preprocessor, compiler, linker;
Single compilation unit (SCU);
modules.
Indefinite behavior, or how to shoot yourself in the foot
“Some people think they know how C and C ++ behave when they play with overflows or null pointers. No, they don’t know. And no one knows. Here indefinite behavior begins, and the word "indefinite" means that we cannot make any assumptions or guesses. It is simply impossible to write programs in which indefinite behavior occurs, and that’s the point. Consider the topic of indefinite behavior and some code examples leading to it, ”something like this was the beginning of lecture 11, in which Andrei again took over from Philip and highlighted key points of this topic, including terminology:
indefinite and unspecified behavior;
going abroad the array;
lack of virtual destructor;
delete operator
null pointers;
shifts;
integer overflow (64-bit errors);
integer overflow (checksum).
C ++ 20 and the foreseeable future
We could not finish our lecture cycle with a story about the imminent release of the latest C ++ 20 standard. The main emphasis was placed on concepts ( Concepts ), a library of ranges ( Ranges ), coroutines ( Coroutines ), modules ( Modules ), contracts ( Contracts ), a three-way comparison operator operator <=> ( Spaceship operator ), macros for testing functionality ( Feature test macros ), attributes ( Attributes ), std :: format , std :: jthread and much more ...
And so, when all organizational issues were settled, the moment came to realize the idea.
Implementation
Of course, we would call this stage “Expectation-Reality”, because, as it usually happens, everything that is thought at the planning stages changes one million more times at the stage of implementation. Naturally, we were aware of this fact and were ready ( no ) that something would go wrong. The main problem for us was the neighbors below, who were actively repairing the premises they rented, and in our office there came a drill-punch time (without comment), which could not but affect the recording of lectures. In this regard, almost half of the lectures from the course were rewritten again or some parts of the video were filmed. And if in the case of Andrei, there was nothing to rewrite, since his lectures lasted about an hour and we had enough time for the company not to carry out installation work from below, then we had to suffer from Philip's lectures, because 1.5-2 hours did not take for one lecture every programmer will survive and not every worker is able to wait so much without working. Perhaps this situation was the most unforeseen, otherwise there were no serious problems.
Now let's talk about the beginning of the course. About 20 participants signed up for our first lecture, but in fact 11 students attended. Of course, we understood that judging by the first event is stupid, and decided to watch what happens next. The number of students for the entire course was constantly changing: it was increasing or decreasing. However, we liked the fact that a certain “backbone” of the group was formed, which was present at each lecture. From the pros, you can also highlight the activity of participants. As in any new team, initially everyone was embarrassed and silently listened to the lecture, but somewhere around 3-4 lectures this constraint passed and the classes proceeded in a more active form - questions, discussions, just live communication after the lecture - and there were cases, when a person continued to communicate with the lecturer for another 40-50 minutes, because he is very interested in the topic and he really wants to develop in this direction. This could not but rejoice, since we understood that in part we contributed to this fact (+100 to karma).
The most persistent were awarded certificates.
Summary
A key indicator of the effectiveness of our venture is the achievement of goals. Has it become easier to work for young specialists and interns in our team in terms of socialization and improvement of professional skills? Definitely - yes, since the lectures were based on specific examples that our programmers encounter while working. In addition, this form of training contributed to the acceleration of the adaptation process in the team for new employees. Could we popularize the C ++ language outside the office? Frankly, we think that there is 50/50. On the one hand, there were very interested people who not only attended our lectures, but also revised them later, searched for additional information on a particular topic, and came fully armed for the next lecture. Yes there is preparation! There was a case when it was very heavy rain and a man came through wet so as not to miss the lesson. This I understand - zeal! On the other hand, initially there were more people wishing to attend our course “from outside” than at the end. I have at least three reasons for this:
The basis of CA were students, and, perhaps, having signed up for the course, they had a certain idea on the topic, but their expectations did not coincide with reality, since, despite the fact that the course covered general aspects of programming in C / C ++, a lot of narrowly focused and specialized issues.
The course took place at the height of summer (yes, we know that this year is not an argument, especially if you live in central Russia). Many simply left the city and were unable to attend the course, even if they were interested in it.
There were labor programmers who know everything without our course :)
In conclusion, I would like to say that we consider the idea of creating our own small programming course to be successful, because this experience helped our company optimize some internal work processes and clearly show our standards to future applicants.
If you have any questions, maybe even suggestions or ideas, then feel free to leave comments - we’ll talk :). And yes, thanks for reading this article.
Link to the selection of reports: "Modern and effective C ++" Vkontakte and YouTube . We will be grateful if you share them on social networks.