Changeset View
Changeset View
Standalone View
Standalone View
doc/developer-notes.md
Show First 20 Lines • Show All 679 Lines • ▼ Show 20 Lines | - Use explicitly signed or unsigned `char`s, or even better `uint8_t` and | ||||
lead to interoperability problems or dangerous conditions such as | lead to interoperability problems or dangerous conditions such as | ||||
out-of-bounds array accesses | out-of-bounds array accesses | ||||
- Prefer explicit constructions over implicit ones that rely on 'magical' C++ behavior | - Prefer explicit constructions over implicit ones that rely on 'magical' C++ behavior | ||||
- *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those | - *Rationale*: Easier to understand what is happening, thus easier to spot mistakes, even for those | ||||
that are not language lawyers | that are not language lawyers | ||||
- Use `Span` as function argument when it can operate on any range-like container. | |||||
- *Rationale*: Compared to `Foo(const vector<int>&)` this avoids the need for a (potentially expensive) | |||||
conversion to vector if the caller happens to have the input stored in another type of container. | |||||
However, be aware of the pitfalls documented in [span.h](../src/span.h). | |||||
```cpp | |||||
void Foo(Span<const int> data); | |||||
std::vector<int> vec{1,2,3}; | |||||
Foo(vec); | |||||
``` | |||||
Strings and formatting | Strings and formatting | ||||
------------------------ | ------------------------ | ||||
- Use `std::string`, avoid C string manipulation functions | - Use `std::string`, avoid C string manipulation functions | ||||
- *Rationale*: C++ string handling is marginally safer, less scope for | - *Rationale*: C++ string handling is marginally safer, less scope for | ||||
buffer overflows and surprises with `\0` characters. Also some C string manipulations | buffer overflows and surprises with `\0` characters. Also some C string manipulations | ||||
tend to act differently depending on platform, or even the user locale | tend to act differently depending on platform, or even the user locale | ||||
▲ Show 20 Lines • Show All 495 Lines • Show Last 20 Lines |