4 ms·
Lack of 'break' is a very useful bit of syntax I use somewhat frequently for categorization. AKA you have a handful of case values that fall into a smaller subs
by StillBored 6y ago
Lack of 'break' is a very useful bit of syntax I use somewhat frequently for categorization. AKA you have a handful of case values that fall into a smaller subset of catagories. Rather than an unreadable set of if/else's that all have multiple if
"a||b||c||d.." conditions, vs a big state machine, or match structure.
Then if one enforces a clearer formatting style than is common on most open source projects the lack of "break" statements stick out visually and it becomes much harder to miss a break statement when the intentionally missing ones have lines like
"// Intentional fall-through"
Or you use a "nobreak" macro and enforce the use of break/nobreak in the automated style/linter.
- touisteur 6y agoBut if you had a syntax that allowed inner/embedded functions, exhaustive matching, and the ability to combine a|b..e, you might never ever EVER need fallthrough. The case statement in Ada is the best control flow structure (I'm not very familiar with advanced FP-style pattern matching, but I can read and follow Ada's with almost closed eyes, and they're exhaustive by default you won't compile until you've handled all the cases), and Ada2012 added case- and if-expressions, and now it seems there's some ongoing work on making it a bit more powerful... This kind of construction makes the power of enumerated types, and restricted range types so much more evident.
- StillBored 6y agoWithout a doubt, even pascal's case statement is better syntactically. It also happens to be more terse.
- georgeecollins 6y agoSometimes I miss Pascal.