In C++, = default and {} are not the same constructor (opens external site)
View full thread · View on Hacker News
To get push notifications on iPhone or iPad, add Hack and Chat to your Home Screen: tap Share → Add to Home Screen, then open the installed app and enable push in Settings.
View full thread · View on Hacker News
Replies (3)
Replies (2)
Use of references for any non nullable pointer.
RAII for heap allocated types, eventually new/delete, leave malloc()/free() family with sizeof type math for interop with existing C code.
Prefer standard library algorithms with proper bounds checking, instead of memsomething and strsomething function family.
Preprocessor magic, when templates and constexpr are type safe, and can even be single stepped on a modern IDE.
Just some examples out of my mind.
Replies (1)
Replies (2)
Replies (1)
The point being made is that the stumbling blocks exist to be tripped over by the unsuspecting, and are not because of C.
Continue this thread (1 replies) →
Replies (1)
[..] One recent real-world example by one of the authors is the following: Improving the following code:
by introducing a getter to have better encapsulation, suddenly caused the undefined behavior:This is also why I dislike the term "C/C++" when referring to them as if they were a single language. They are two distinct languages with substantially different idioms.
What I hate about C++ is that it offers a myriad of ways to accomplish the same thing, ranging from outright terrible to genuinely good. Learning C first can reinforce habits that you'll later have to unlearn.
Replies (1)
There is no better way to understand what's going on in std::vector or std::string than writing a growable array in C and having to keep three facts straight: how much storage you own, how many elements you’re using, and who releases it. Knowing how much work the abstraction does is a damn good reason to use it.
Replies (1)
First Pascal for those that never coded in their life, and then C++.
The other languages that had explicit learning material were Smalltalk, Caml Light Objective Caml, Prolog, Lisp, Algol, Miranda, Java, PL/SQL, 80x86 and MIPS Assembly.
It was expected that the few classes where C was still used, basically UNIX kernel programming, alongside algorithms and datastructures, the knowledge to code in C would be taken from those C++ classes done during the 2nd year.
So I hold this view for almost 30 something years now.