Hacker News new | past | comments | ask | show | jobs | submit login

Starting with C is the worst way to learn C++. You start out with bad habits you then have to unlearn.

Unlearning bad C habits is hard because the language accommodates them for as long as you continue to cling to them. You need to consciously decide you will use the new, better way. Once you have done each once, there will be no temptation to backslide.




Fully disagree. Understanding pointer semantics is a pre-requisite for understanding RAII.


I know C++ since 1993, I am quite curious how pointer semantics have anything to do with RAII.


Because smart pointers are still pointers under the hood. You're forgetting the time before you know what pointers were - people coming from higher level languages don't immediately grok the concept. By teaching them automatic memory management patterns like we use in C++ without teaching them why you need such things, they'll never fully understand the code they're writing.

It's like the "I know React but not JavaScript" crowd all over again.


If you think RAII is about smart pointers, you really don't understand it.

RAII is about resource management, regardless of where those resources live on.

Heap allocated, OS handles, indexes on a fixed sized buffer, network sockets, ...


Yes, I'm aware, thanks. Lifetimes, ownership, etc. are all overlaps of RAII and associated concepts.

Again, what did being pedantic prove here? You clearly understood what I meant.


Yeah, doesn't make sense. Pointers are less useful in C++, because we have better things now.


Of course we do. You still need to know how pointers work to use RAII effectively, though.


Not at all, because RAII is about constructors/destructors, and not at all about pointers.

Heap allocated data is one special case of OS resources that can be managed by constructor/destructor pairs.


What did being pedantic prove here?


The thread started with you insisting a C-level conception of pointers is essential to coding C++, which turns out to be false.

Learning C first is a very bad way to learn C++. One can pick up pointers later, and asm blocks after that.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: