These days, I've been learning C++ and have posted some articles about it. Since I started to learn C++ with raw pointers, I naturally hit some common questions: new/delete, manual memory manage, and so on.C++ Traps That Caught Me Off Guard — A Beginner's Log - Coder Legion
A few days ago, I discussed this topic with some C++ developers. As far as I'm concerned, I believe that raw pointers are fundamental and it's necessary for beginners to build a mental model of RAII and memory management before moving to smart pointers.
On the other hand, some developers think that raw pointers are not a suitable topic for beginners - we have the safer and more modern smart pointers to manage, so why not start with them directly?
Actually, it's up for debate whether beginners should learn these constructs. From my own experience learning C++ through raw pointers, I believe beginners can benefit from a moderate understanding of them.
As for performance, there's no absolute winner. Smart pointers are safer and work well for most scenarios, especially when code maintainability matters. Raw pointers still have their place in performance-critical or low-level contexts. The key is knowing both and choosing wisely.
Which one would you learn first if you are a beginner? And why?