From 053f721836d3e88dbefb0fbe478300224707797b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89amonn=20McManus?= Date: Fri, 19 Jul 2024 15:11:51 -0700 Subject: [PATCH] Add `TraditionalSwitchExpression.md`. PiperOrigin-RevId: 654138846 --- docs/bugpattern/TraditionalSwitchExpression.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 docs/bugpattern/TraditionalSwitchExpression.md diff --git a/docs/bugpattern/TraditionalSwitchExpression.md b/docs/bugpattern/TraditionalSwitchExpression.md new file mode 100644 index 00000000000..696272f3ba0 --- /dev/null +++ b/docs/bugpattern/TraditionalSwitchExpression.md @@ -0,0 +1,6 @@ +The newer arrow (`->`) syntax for switches is preferred to the older colon (`:`) +syntax. The main reason for continuing to use the colon syntax in switch +*statements* is that it allows fall-through from one statement group to the +next. But in a switch *expression*, fall-through would only be useful if the +code that falls through has side effects. Burying side effects inside a switch +expression makes code hard to understand.