diff options
Diffstat (limited to 'docs')
-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. |