Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing closing tag #700

Merged
merged 2 commits into from
Jan 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions docs/STYLE.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,12 +123,12 @@ for (auto i = 0u; i < 10; ++i) {

Only use shortened version of the variable name if it's still obvious what the variable holds.

- Index = `_idx`
- Index = `idx`
- Input = `in`
- Output = `out`
- Request = `req`
- Response = `res`
- Initialization = `init
- Initialization = `init`
- ... etc.

If the context in which the variable is used is short, you can make variable names even shorter. For example `for (auto const& e : events) { /* ... */ }` or `auto const& b = get_buffer()`.
Expand Down Expand Up @@ -224,6 +224,10 @@ This means we do not want `new` or `delete` - except for placement new or placem

If there is no tool available in the C++ Standard Library please check first if we already have something in our [utl](https://github.com/motis-project/utl) library.

# Use `strong` types

Use `cista::strong` to define types, that cannot be converted implicitly. Using a `strong` type will ensure, that parameters cannot be mismatched, unlike `int` or `std::size_t`. This also makes function parameters clearer.

# `const`

Make everything (variables, loop variables, member functions, etc.) as `const` as possible. This indicates thread-safety (as long as only `const` methods are used) and helps to catch bugs when our mental model doesn't match the reality (the compiler will tell us).
Expand Down Expand Up @@ -307,9 +311,16 @@ Our go-to data structure is `std::vector`. (Hash-)maps and (hash-)sets are very

Never use `std::unordered_map`. We have better alternatives in all projects (e.g. unordered_dense).

## `vecvec` and `vector_map`

- Use `vector_map` for mappings with a `strong` key type and a continuous domain.
- Prefer using `vecvec<T>` instead of `vector<vector<T>>`, as data is stored and accessed more efficient. To store data, that may appear in any order, you may consider `paged_vecvec` instead.

# Tooling

- Always develop with Address Sanitizer (ASan) and Undefined Behaviour Sanitizer (UBSan) enabled if performance allows it (it's usually worth it to use small data sets to be able to develop with sanitizers enabled!): `CXXFLAGS=-fno-omit-frame-pointer -fsanitizer=address,undefined`.
- **Notice**: Some checks can cause false positive and should be disabled if necessary (compare `ci.yml`).
Example: `ASAN_OPTIONS=alloc_dealloc_mismatch=0`
- Check your code with `valgrind`.

# Spirit
Expand Down
Loading