re: Language Proposal: The 'Any' Switch Case VIEW POST


What about simplifying this:

switch (number) {

  any: // Runs before any matched case

  case 1: // ...

  case 2: // ...

  any: // Runs only after case 1 or 2 match

  case 3: // ...

  case 4: // ...

  any: // Runs after any of the previously matches cases

  default: // ...


Ooo, I like this! I thought about putting it before and after, and I love the addition of the middle block. But I worried about the readability of this. Since it begs the question, at least at this stage, does the middle bottom any run after 1,2,3,4 or just cover 3,4?


I think it would just have to just be specified by the language. I'm not coming up with anything that wouldn't add a bunch of lexical complexity.

This does remind me though, when you have increasingly complex relationships between data and behavior, at some point it's best to abstract that into it's own class that can encapsulate that logic so that the language doesn't have to make increasingly strong opinions on how those relationships are expressed.

code of conduct - report abuse