Random Link ¯\_(ツ)_/¯ | ||
Jun 11, 2022 | » | Testing Your Code
8 min; updated Nov 19, 2022
Why Write Tests Helps catch bugs in the code, and in the programmer’s mental model of what the code does. The later a bug is caught in the development cycle, the more expensive it is to fix it. A good test today is a future debugging session saved. The test is the first client of your code. It uncovers sub-optimal design choices, tight couplings, missed cases, etc.... |
Jun 4, 2022 | » | Enumerations in C++
7 min; updated Jun 4, 2022
Unscoped (or Plain or C-Style) Enumerations Plain (or C-style) enums are entered in the same scope as the name of their enum, and implicitly convert to their integer value, e.g. enum Color { red, green, blue }; int col = green; Color c2 = 1; // error: invalid conversion from 'int' to 'Color' [-fpermissive] enum CardColor { red, black }; // Error: "red" conflicts with a previous declaration... |
May 31, 2022 | » | Resource Management in C++
4 min; updated May 31, 2022
Resource Handles RAII is also covered in Classes in C++ > Motivation for the Destructor Mechanism The constructor/destructor pattern enables objects defined in a scope to release the resources during exit from the scope, even when exceptions are thrown. All standard-library containers, e.g. std::vector, are implemented as resource handles. std::unique_ptr and std::shared_ptr These “smart pointers” are useful in managing objects that are allocated on the free store (as opposed to those allocated on the stack).... |
May 12, 2022 | » | Classes in C++
15 min; updated May 12, 2022
quotes Doug McIlroy: Those types are not “abstract”; they are as real as int and float. What is the context of this quote? A class is a user-defined type provided to represent a concept in the code of a program. Essentially, all language facilities beyond the fundamental types, operators, and statements exist to help define better class or to use them more conveniently.... |