Skip to content

Commit

Permalink
Update XLS style guide for naming absl::StatusOr<> values.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 705639565
  • Loading branch information
mikex-oss authored and copybara-github committed Dec 12, 2024
1 parent 8b0e726 commit 3759de8
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs_src/xls_style.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,17 @@ in the XLS project, with the relevant Google style guides
statement blocks.

* Prefer using `XLS_ASSIGN_OR_RETURN` / `XLS_RETURN_IF_ERROR` when
appropriate, but when binding a `StatusOr` wrapped value prefer to name it
`thing_or` so that it can be referenced without the wrapper as `thing`; e.g.
appropriate. When binding a `StatusOr` wrapped value, prefer to name the
variable after its underlying value (just as we do with pointers). Avoid
names like `maybe_foo` or `foo_or`, which can lead to multiple variables
that represent the same value.

```
absl::StatusOr<Thing> thing_or = f();
if (!thing_or.ok()) {
// ... handling of the status via thing_or.status() and returning ...
absl::StatusOr<Thing> thing = f();
if (thing.ok()) {
MakeUseOf(*thing);
thing->DoSomething();
}
const Thing& thing = thing_or.value();
```
* Prefer `CHECK` to `DCHECK`, except that `DCHECK` can be used to verify
Expand Down

0 comments on commit 3759de8

Please sign in to comment.