discussion with C++ developers

Registerconnect to the broadcast and write questions and comments in the chat – the hosts will voice some of them.

Who answers questions

Ilya Kazakov

Developer in the data storage systems team at YADRO

Konstantin Vladimirov

Head of Compilers and Development Tools at Syntacore

Alexander Enaldiev

Technical lead in content filtering in Kaspersky

Stanislav Yurchenko

Developer at VK AdTech

Evgeniy Fyoklin

Code analyzer core developer at PVS-Studio

Continue the phrase: “Code review is when…”

Ilya Kazakov: When your comments on the Internet are actually read.

Konstantin Vladimirov: When a group of developers looks at their colleague's commit and gives them useful and constructive feedback.

Alexander Enaldiev: When the scars from battles heal, and the code objectively becomes better.

Stanislav Yurchenko: When the code, as opposed to the mood, becomes better.

Evgeny Fyoklin: When you convince someone to look at the code you wrote.

What is better: throwing an exception or returning an error code? Is it possible to abandon exceptions completely?

Ilya Kazakov: C++17 introduced std::variant and std::optional and std::variant. C++23 introduced std::expected and monads for std::expected and std::optional. I don’t see any obstacles to convenient work with error codes. I love marking functions and methods with noexcept and am very afraid of abort and std::terminate. I use exceptions only in constructors, and sometimes I disable constructors altogether and write factory methods – thanks to __cpp_guaranteed_copy_elision. Exceptions are evil, fight me.

Konstantin Vladimirov: It's better to use exceptions. They optimize the main path and remove garbage from the code.

Alexander Enaldiev: Exceptions looks like a cargo cult. I've met people who know that they shouldn't cheat, but they don't know what their goal is. Everything should come from the goal: has it gotten better or “the same eggs, only in profile”?

Stanislav Yurchenko: I would formulate the question differently: sometimes an exception is better, sometimes an error code. This is not a pick and choose question, it all depends on the context. If you need centralized handling of a large set of errors, exceptions are a good option. If the algorithm involves sequential branching depending on the errors received, returning the code may be the best solution.

Evgeny Fyoklin: For me it is better to throw an exception to handle errors. It allows you to create hierarchies of exceptions.

What tools do you prefer to use for working with third-party dependencies?

Ilya Kazakov: I think they pay too little attention Conan. It is developing very actively and gathers a fairly large community around itself. I myself am the author of several recipes at conan-center-index and it holds a special place in my heart.

Konstantin Vladimirov: I like Conan but I don't mind vcpkg. In principle, anything, as long as it’s not submodules.

Alexander Enaldiev: It seems that Conan (was) quite good, but for me personally the issue is not relevant in workflows – we have a monorepository.

Stanislav Yurchenko: I can’t say that I have become zen in this matter. I just used Conan.

Evgeny Fyoklin: CMake, ChocolateyСonan, vspkg.

The standard library is often discussed in reports at meetups and conferences. Do you think it’s possible to write in C++ and not use the standard library?

Ilya Kazakov: A reasonable reason to abandon the standard library may be the need to develop for embedded systems, where project size and careful handling of memory are absolute. In other cases, I see no reason to deprive myself of an extensive toolkit with good optimization.

Konstantin Vladimirov: Expectation: they hint to you about the advantages of drivers or bare metal C++. Reality: people write in Qt and don’t pay attention to STL and Boost.

Alexander Enaldiev: I'm pretty sure that those who abandon the standard library end up writing exactly the same code as in the standard library. Unfortunately or fortunately, I have not encountered in practice a situation where using the standard library would have been impossible. Don't like dynamic dependency? There is nothing stopping you from linking statically. Problem with the library version on the target platform? Link statically. Don't like linking statically? Link statically 🙂

Stanislav Yurchenko: Can. But to do this, you will have to rewrite part of the standard library, sometimes significant. It was an experience. I will say this: developing again what is already in the standard library is, first of all, boring.

There is a phrase “Every good C++ library should have a C interface.” Why is that?

Ilya Kazakov: Expectation: we meant that it would be nice to count on a heterogeneous environment, all sorts of C, C++, rasts, sharps and other cythons. Reality: because the Si-shnoye lobby does not sleep.

Konstantin Vladimirov: What is a library interface in the C++ world? These are header files. Every time you include a header file, you include all of its dependencies, and as a result, the library's dependencies flow into your dependencies. In addition, it is possible that the header file uses a standard higher than the standard of your project. In this case, using the library will not work at all. But if you provide a header written in C, then the headache will be much less. True, unfortunately, and functionality.

Alexander Enaldiev: Due to the fact that C has a stable ABI and no manipulation (at least type manipulation). In C++, type manipulation occurs in an implementation-dependent style.

How often do you use final?

Ilya Kazakov: Until recently, I didn’t remember him at all, but Konstantin Vladimirov convinced me that it was in vain. Now I stop myself from writing it everywhere (even where it is not needed)

Konstantin Vladimirov: Quite often both on classes and on specific methods.

Alexander Enaldiev: Once every two years for sure.

Stanislav Yurchenko: I am guided by the rule “don’t sculpt anywhere.” I rarely see it, I use it even less often.

Evgeny Fyoklin: The team lead prohibits us from using virtual functions.

Join the discussion in the comments! How would you answer the questions? And also register to a C++ meetup to participate in an online discussion with experts.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *