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
Note: if you enjoyed this abstract hand-waving about boundaries, you might appreciate[this post](https://www.tedinski.com/2018/02/06/system-boundaries.html).
In the "Not as good" version, the precondition that `1`is a valid char boundary is checked in `is_string_literal`and used in `foo`.
234
+
In the "Bad" version, the precondition that `1`and `s.len() - 1` are valid string literal boundaries is checked in `is_string_literal`but used in `main`.
235
235
In the "Good" version, the precondition check and usage are checked in the same block, and then encoded in the types.
236
236
237
237
**Rationale:** non-local code properties degrade under change.
@@ -271,6 +271,8 @@ fn f() {
271
271
}
272
272
```
273
273
274
+
See also [this post](https://matklad.github.io/2023/11/15/push-ifs-up-and-fors-down.html)
275
+
274
276
## Assertions
275
277
276
278
Assert liberally.
@@ -608,15 +610,15 @@ Avoid making a lot of code type parametric, *especially* on the boundaries betwe
608
610
609
611
```rust
610
612
// GOOD
611
-
fnfrobnicate(f:implFnMut()) {
613
+
fnfrobnicate(mutf:implFnMut()) {
612
614
frobnicate_impl(&mutf)
613
615
}
614
616
fnfrobnicate_impl(f:&mutdynFnMut()) {
615
617
// lots of code
616
618
}
617
619
618
620
// BAD
619
-
fnfrobnicate(f:implFnMut()) {
621
+
fnfrobnicate(mutf:implFnMut()) {
620
622
// lots of code
621
623
}
622
624
```
@@ -975,7 +977,7 @@ Don't use the `ref` keyword.
975
977
**Rationale:** consistency & simplicity.
976
978
`ref` was required before [match ergonomics](https://github.com/rust-lang/rfcs/blob/master/text/2005-match-ergonomics.md).
977
979
Today, it is redundant.
978
-
Between `ref` and mach ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword).
980
+
Between `ref` and match ergonomics, the latter is more ergonomic in most cases, and is simpler (does not require a keyword).
0 commit comments