-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix Switch #3701
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
There was much discussion of switch in Issue #2047. Removed Type-Defect label. |
This comment was originally written by [email protected] You're quite right, this is a duplicate and should probably be marked as such. It seems like this subject has been discussed at length. Shame a bolder change wasn't embraced :( |
|
Implicit fallthrough is like driving a Ferrari with a broken side mirror. Sure, you can maybe use it, but it's a lot of work and it looks so damn ugly dangling down the side of the car. There is a need for Implicit fallthrough is generally acknowledged to be a syntactic failure with new languages either adding a Case statements are generally easier to read as one-liners than if..else blocks. This is even more true when all the Finally, this breaking syntactic change is incredibly easy on the consumer. Release an automated tool that looks for .dart files, searches case by case. If that case has a Why let such a good language have such a second-rate feature looking ugly and making your code harder to read? Why not fix our Ferrari? |
For the record: Dart does not have implicit fallthrough. The request here was purely for a different syntax to do the same thing we already do, except for not making the final |
This issue was originally filed by [email protected]
This not a bug but a (highly opinionated :P) suggestion.
Dart is a new language, and with a new language based on C you have the unique opportunity to fix legacy C problems. Top of that list should be the switch statement - Dart can do better!
Lose the "label: goto" heritage of the switch statement, eliminate case fall-through and introduce proper blocks. Here is one example of a "fixed" switch statement:
switch(someVar) {
case (1, 2, 5) {
// this will catch up to three variations of someVar
} case (3) {
// no need for break, fall-though is gone
} case (4) {
// this is a block with its own scope
} default {
// default, else or case else...
}
}
With the exception of block scope (which isn't available in JS yet anyway), the above is convertible to JavaScript.
The text was updated successfully, but these errors were encountered: