News for hackers. Stuff that matters.
Re:What Is the Switch-Case Equivalent in Python? by dragonwriter on Sunday April 04, 2021 @05:07AM (#26687964)
> If it succeeds, then the branch is taken and the variables (if any) are assigned, which in python means that they are assigned to the whole current function. This is a big side effect.

Assignment is not generally a side effect, and even if it were, matched branches in a switch statement potentially having side effects or externally visible variable (re)assignments is normal in languages with switch. (Ironically, match-based assignments visible outside the pattern match expression aren’t typical in languages with pattern matching, so actually the behavior you describe is more typical of switch statements than pattern matching, which is typically a block-scoped expression with local bindings.)

There are no comments on this comment yet.