Changeset View
Changeset View
Standalone View
Standalone View
doc/developer-notes.md
Show First 20 Lines • Show All 453 Lines • ▼ Show 20 Lines | - *Rationale*: Include files define the interface for the code in implementation files. Including one but | ||||
not linking the other is confusing. Please avoid that. Moving functions from | not linking the other is confusing. Please avoid that. Moving functions from | ||||
the `.h` to the `.cpp` should not result in build errors | the `.h` to the `.cpp` should not result in build errors | ||||
- Use the RAII (Resource Acquisition Is Initialization) paradigm where possible. For example by using | - Use the RAII (Resource Acquisition Is Initialization) paradigm where possible. For example by using | ||||
`unique_ptr` for allocations in a function. | `unique_ptr` for allocations in a function. | ||||
- *Rationale*: This avoids memory and resource leaks, and ensures exception safety | - *Rationale*: This avoids memory and resource leaks, and ensures exception safety | ||||
- Use `std::make_unique()` to construct objects owned by `unique_ptr`s | |||||
- *Rationale*: `std::make_unique` is concise and ensures exception safety in complex expressions. | |||||
C++ data structures | C++ data structures | ||||
-------------------- | -------------------- | ||||
- Never use the `std::map []` syntax when reading from a map, but instead use `.find()` | - Never use the `std::map []` syntax when reading from a map, but instead use `.find()` | ||||
- *Rationale*: `[]` does an insert (of the default element) if the item doesn't | - *Rationale*: `[]` does an insert (of the default element) if the item doesn't | ||||
exist in the map yet. This has resulted in memory leaks in the past, as well as | exist in the map yet. This has resulted in memory leaks in the past, as well as | ||||
race conditions (expecting read-read behavior). Using `[]` is fine for *writing* to a map | race conditions (expecting read-read behavior). Using `[]` is fine for *writing* to a map | ||||
▲ Show 20 Lines • Show All 457 Lines • Show Last 20 Lines |