You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
| Risk | Off-by-one errors, index space confusion |
1441
+
1442
+
Use consistent suffixes to distinguish numeric quantities (from [TigerBeetle's TigerStyle](https://github.com/tigerbeetle/tigerbeetle/blob/main/docs/TIGER_STYLE.md)):
1443
+
1444
+
| Suffix | Meaning | Domain | Invariant |
1445
+
|--------|---------|--------|-----------|
1446
+
|`_count`| Number of items | Items | — |
1447
+
|`_index`| Position of one item | Items |`index < count`|
1448
+
|`_size`| Number of bytes | Bytes |`size = @sizeOf(T) * count`|
1449
+
|`_offset`| Byte position | Bytes |`offset < size`|
1450
+
1451
+
Avoid `length`/`len` for new code — it's ambiguous (Rust `str::len` = byte size; Python `len(str)` = codepoint count). Note: Zig's stdlib uses `.len` on slices, which is fine — this convention applies to your own variable names.
1452
+
1453
+
**Wrong:**
1454
+
```zig
1455
+
fn process(data: []const u8, len: usize) void {
1456
+
var pos: usize = 0;
1457
+
var n: usize = 0;
1458
+
while (pos < len) {
1459
+
// Are pos and len in the same domain? Hard to tell.
0 commit comments