kaffeine icon indicating copy to clipboard operation
kaffeine copied to clipboard

Switch statements cause compile errors

Open benekastah opened this issue 14 years ago • 7 comments

And when this is fixed, it would also be nice if break statements aren't required. They're silly. I would like something like:

switch foo {
  case :bar:
    aha()
  case :batz:
    doSomething()
    fallthrough
  default
    bar()
}

Just an idea.

benekastah avatar Jun 21 '11 04:06 benekastah

ideally I'd like to keep compatibility with Javascript. Perhaps there's another way ?

On Tue, Jun 21, 2011 at 5:36 AM, benekastah < [email protected]>wrote:

And when this is fixed, it would also be nice if break statements aren't required. They're silly. I would like something like:

switch foo {
 case :bar:
   aha()
 case :batz:
   doSomething()
   fallthrough
 default
   bar()
}

Just an idea.

Reply to this email directly or view it on GitHub: https://github.com/weepy/kaffeine/issues/36

weepy avatar Jun 21 '11 07:06 weepy

There's always the ruby way. That's the best variation of the switch I've used.

// this is only ruby-ish
case thing {
  when 'rock', 'roll'
    rockNRoll()
  else
    goHome()
    beSad()
}

Then if you really need to use the fallthrough capability, you can just write your switch in pure js.

benekastah avatar Jun 21 '11 07:06 benekastah

how about

switch thing
 when 'rock', 'roll':
   rockNRoll()
 else:
   beSad()

? do we want/need the colons ?

On Tue, Jun 21, 2011 at 8:31 AM, benekastah < [email protected]>wrote:

There's always the ruby way. That's the best variation of the switch I've used.

case thing
 when 'rock', 'roll'
   rockNRoll()
 else
   beSad()

Reply to this email directly or view it on GitHub: https://github.com/weepy/kaffeine/issues/36#issuecomment-1408559

weepy avatar Jun 21 '11 07:06 weepy

Yeah, I actually kind of like the colons. It's a little more javascripty, and they help me a bit visually.

benekastah avatar Jun 21 '11 07:06 benekastah

yeah agreed.

maybe we don't need the else as it doesn't add anything beyond 'default' ?

On Tue, Jun 21, 2011 at 8:41 AM, benekastah < [email protected]>wrote:

Yeah, I actually kind of like the colons. It's a little more javascripty, and they help me a bit visually.

Reply to this email directly or view it on GitHub: https://github.com/weepy/kaffeine/issues/36#issuecomment-1408599

weepy avatar Jun 21 '11 07:06 weepy

True. default would be better in this context.

benekastah avatar Jun 21 '11 07:06 benekastah

ok so :

switch thing {
 when 'rock', 'roll':
   rockNRoll()
 when 'jazz':
    jazz()
 default:
   beSad()
}

which is converted to :

switch(thing) {
 case 'rock':
   rockNRoll(); break; case 'roll': rockNRoll(); break;
 case 'jazz':
   jazz(); break;
 default:
   beSad()
}

On Tue, Jun 21, 2011 at 8:46 AM, benekastah < [email protected]>wrote:

True. default would be better in this context.

Reply to this email directly or view it on GitHub: https://github.com/weepy/kaffeine/issues/36#issuecomment-1408619

weepy avatar Jun 21 '11 09:06 weepy