Skip to content

Fix Switch #3701

Closed
Closed
@DartBot

Description

@DartBot

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-languageDart language related items (some items might be better tracked at github.com/dart-lang/language).closed-duplicateClosed in favor of an existing reporttype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions