Re: New switch/case idea

new topic     » goto parent     » topic index » view thread      » older message » newer message
euphoric said...

Jeremy argued at one point that switch with fallthru as default was the norm for many other languages. I wonder then, if we're to introduce and welcome those programmers into the Euphoria community, we shouldn't have fallthru be the default, to keep things somewhat similar to them and lessen the learning curve a bit. Yes, I voted for "without fallthru" as default, but I'm having voter's remorse. I think the option "without fallthru" will satiate the dissenters who don't want fallthru as default.

Just throwing that out there for consideration. I don't care one way or the other. smile

Euphoric,

I am having a bit of arguer's remorse getlost There are two things that made me change my mind on the default... As I thought more about this, the default (as you have argued many times) is to use break, even for C programers. The way they are going to program a switch to start is probably:

switch X do 
    case 1 then 
        ? 1 
       break 
    case 2 then 
        ? 2 
        break 
end switch 

If not simply out of habit. That break is fine there. It does no harm. So, the fact that the majority of switches use break, we cover most people. The fact that the break does not cause a problem, is a benefit.

Now, the second thing that made me change my mind is we moved from : to then, and I think this is the more important change. The reason why is switch no longer looks exactly like the C switch, therefore, it's going to be someone unknown and the C programmer is going to use it cautiously knowing that it may not act how they suppose. case 3 then almost suggests when reading aloud that it's one block of code per case. So, our switch is different enough that C users are not going to simply jump in and use it without a little caution.

I guess there is a third... With the addition of with fallthru and now some form of continue, this makes the switch be able to do anything reasonable. You can default to fallthru, you can override the fallthru action with break, you can default to non-fallthru, you can override that with continue, etc...

Jeremy

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu