aboutsummaryrefslogtreecommitdiff
path: root/docs/dev
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2021-04-05 11:02:47 +0100
committerAleksey Kladov <[email protected]>2021-04-05 11:02:47 +0100
commita01fd1af19314a73e5436a912f1cac2341ea11cd (patch)
tree19d03d2f7516f29f65f1e1de8ee1ab2254f2e98c /docs/dev
parent58924cfae1be231e01736407fa666f31898a699e (diff)
internal: explain "extract if condition" refactoring
Diffstat (limited to 'docs/dev')
-rw-r--r--docs/dev/style.md21
1 files changed, 20 insertions, 1 deletions
diff --git a/docs/dev/style.md b/docs/dev/style.md
index c594946be..48ce4b92a 100644
--- a/docs/dev/style.md
+++ b/docs/dev/style.md
@@ -842,7 +842,26 @@ Re-using originally single-purpose function often leads to bad coupling.
842 842
843## Helper Variables 843## Helper Variables
844 844
845Introduce helper variables freely, especially for multiline conditions. 845Introduce helper variables freely, especially for multiline conditions:
846
847```rust
848// GOOD
849let rustfmt_not_installed =
850 captured_stderr.contains("not installed") || captured_stderr.contains("not available");
851
852match output.status.code() {
853 Some(1) if !rustfmt_not_installed => Ok(None),
854 _ => Err(format_err!("rustfmt failed:\n{}", captured_stderr)),
855};
856
857// BAD
858match output.status.code() {
859 Some(1)
860 if !captured_stderr.contains("not installed")
861 && !captured_stderr.contains("not available") => Ok(None),
862 _ => Err(format_err!("rustfmt failed:\n{}", captured_stderr)),
863};
864```
846 865
847**Rationale:** like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context. 866**Rationale:** like blocks, single-use variables are a cognitively cheap abstraction, as they have access to all the context.
848Extra variables help during debugging, they make it easy to print/view important intermediate results. 867Extra variables help during debugging, they make it easy to print/view important intermediate results.