Skip to content

Commit 9a7e8ef

Browse files
committed
Add a STYLE file with rules we develop over time.
1 parent db8d4ce commit 9a7e8ef

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

STYLE.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
# Style
2+
3+
A collection of style rules that we collect as we design the library, with a
4+
focus on providing clear APIs that can't easily be used wrong, and avoid
5+
footguns, crashes, bugs, and UB.
6+
7+
1. All methods are `constexpr` unless they must call a non-`constexpr` function,
8+
or they expose floating point NaNs (since constexpr NaNs change their bit
9+
values).
10+
* Consider `panic()`/`check()` as constexpr for these purposes, they will
11+
correctly prevent compile if the condition fails.
12+
1. If you override on `const&`, then explicity provide or delete the `&&`
13+
override.
14+
* If the function should only act on lvalues, provide `const&`- and
15+
`&`-qualified overrides, and delete the `&&`-qualified override.
16+
* If the function should act on lvalues or rvalues, omit qualifying the
17+
method or provide all three.
18+
* If the function should act on rvalues, provide a `&&`-qualified override,
19+
and omit the rest.
20+
1. Use concepts or `requires` to prevent compilation errors inside a function.
21+
1. Use `sus` concepts where possible.
22+
* If you `requires` a concept, then use that concept to do the intended
23+
action instead of rolling it yourself. For example if `T` was required to be
24+
`MakeDefault` then construct `T` via `make_default()`.
25+
1. Use `()` around the `requires` expression always, since clang-format does bad
26+
things without it.
27+
1. Use `usize`, `u32`, `i32`, etc in all public APIs, except:
28+
* Use `size_t` for template parameters instead of `usize`. Since it may
29+
require forward declarations (sometimes from places that also must
30+
forward-declare the `usize` type), and template args are always statically
31+
determined, `usize` doesn't provide the same value in this context, and
32+
can get in the way.

0 commit comments

Comments
 (0)