diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2021-04-05 11:04:28 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2021-04-05 11:04:28 +0100 |
commit | 9bf7ca59e9f16ef58adee2ae8fca01d0b6ac5a26 (patch) | |
tree | 19d03d2f7516f29f65f1e1de8ee1ab2254f2e98c /docs/dev | |
parent | 58924cfae1be231e01736407fa666f31898a699e (diff) | |
parent | a01fd1af19314a73e5436a912f1cac2341ea11cd (diff) |
Merge #8337
8337: internal: explain "extract if condition" refactoring r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'docs/dev')
-rw-r--r-- | docs/dev/style.md | 21 |
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 | ||
845 | Introduce helper variables freely, especially for multiline conditions. | 845 | Introduce helper variables freely, especially for multiline conditions: |
846 | |||
847 | ```rust | ||
848 | // GOOD | ||
849 | let rustfmt_not_installed = | ||
850 | captured_stderr.contains("not installed") || captured_stderr.contains("not available"); | ||
851 | |||
852 | match 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 | ||
858 | match 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. |
848 | Extra variables help during debugging, they make it easy to print/view important intermediate results. | 867 | Extra variables help during debugging, they make it easy to print/view important intermediate results. |