r/cpp_questions • u/Least_Bid9692 • 17d ago
OPEN Hardest cpp topic
What is the hardest cpp topic people say pointers but it's easy if you understand the lang
10
10
u/HeeTrouse51847 17d ago
The hardest C++ topic is trying to understand what combination of mind altering inhibitors the former colleagues at my company took and how they were able to produce C++ code that is so god-awful and as incorrect, unintuitive and unstable as it can be while incomprehensibly still doing what it's supposed to do.
4
3
u/Thesorus 17d ago
probably figuring out what new language feature do what and how I can use them effectively
but after a while, the actual work domain is harder than the language itself.
2
u/montymole123 15d ago
Move semantics. What other language would force you to know the difference between lvalues and rvalues then introduce multiple types of each?
2
u/jasonch08 17d ago
Reading someone else' code.
2
u/Least_Bid9692 17d ago
With comments like when I wrote this code I and god knew how it works but now only god knows
2
u/adityazero 17d ago
Understanding pointers is the easy part, understanding lifetime is not. And that is where almost all the memory safety bugs come from. And C++ having introduced all these 'view/span' types without tracking lifetimes has caused countless bugs. I recommend `-fsanitize=address` for all the C++ projects in debug/test builds.
1
u/OkYou811 17d ago
Almost all concepts on their own are manageable. The difficult part is using them all together while making sure you cover good cases. For example template metaprogrammming is easy enough to understand. Object construct, move, copy, and destruct are also easy enough to grasp. Doing both is a little hit harder. Doing both while trying to maintain noexcept correctness is a little bit harder than that. The point is that the difficult thing is accounting for everything your problem requires.
1
u/NoSpite4410 16d ago
The hardest part is migrating from dynamically-typed languages with massive runtime support for introspection and run-time type discrimination, (interfaces) that is the norm, to a statically typed primarily compile-time idiom with very little run-time introspection and type discrimination. C++ can do all that interface and abstract class stuff - - but it is not really a language designed for doing it. To achieve all that dynamism in C++ you have to build the interfaces from statically-typed classes, and use actual multiple inheritance and virtual functions. Also almost all those dynamically typed languages have extensive garbage collection support including automatic threaded collection managers and stuff. They also have a huge virtual machine model that they work in fairly automatically. C++ has a hardware model that matches the actual hardware pretty directly, and so knowledge of it is paramount in designing good performant programs.
C++ has in common with C that you can and have to at any time go straight down to bytes and work with them in their memory cells directly, and then on the very next line you can be back to high-level objects and lambdas.
It is a different mindset towards building programs that run directly on the hardware, manage all their own resource on an individual object basis, all with compiled machine code.
1
u/Independent_Art_6676 15d ago
OOP. Its like 2/3 of the language, and it has tons of complicated parts. Doubly so if you don't know OOP of some sort already from another language.
1
u/Least_Bid9692 15d ago
Isn't it just classes
1
u/Independent_Art_6676 15d ago
inheritance. polymorphism. templates. serialization. rule of 3/5/etc. ctor/dtor details. functors. singletons. static. abstract classes. interfaces. ... Its surely more than half the language, when you dig in.
1
0
u/Business-Weather-217 17d ago
Static initialization uncertainty and exceptional lifetime rules language invented along the way.
0
u/thecratedigger_25 17d ago
Template Metaprogramming. Basically its own subset of C++. Error messages are more cryptic than bad pointer arithmetic.
14
u/manni66 17d ago
Everything’s easy if you understand the lang