Re: New switch/case idea

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

When was colon removed ? Does that mean I have to back into my code and remove the colons ?

Welcome to alpha testing.

bernie said...

My suggestion was simple and much easier to code and all it takes is 1 extra colon and no other keywords.

Why does ':' obviously mean fall through and '::' obviously mean do not fall through? How is one supposed to remember the difference? In my opinion, it would also be easy to code the wrong thing by accident, even if one did remember which was which. And locating such a bug for the code reader would also be difficult given that ':' and '::' are so similar.

The current syntax makes it explicit and clear what the switch is doing.

bernie said...

I think that things are being made too complicated with all the extra words.

The style of Euphoria is based on English words and not punctuation symbols, so it was decided that ':' should be replaced by 'then' as it is similar in style to the if statement, of which switch is a variant of.

bernie said...
switch X do   
  case 1:: -- do code until next case is encountered then break 
     ? 1  
  case 2, 3, 4: -- fall through 
     ? 2  
  case 5: -- fall through 
     ? 5 
  case 30:: -- do code until next case is encountered then break 
     ? 30 
     ? 123 
  case 27:: -- do code until next case is encountered then break 
     ? 27 
  case 81: -- fall through 
     ? 81 
end switch  

The final syntax for this is not finalized, but one suggestion is ...

switch X do  -- by default does NOT fallthru 
  case 1 then 
     ? 1  
  case 2, 3, 4 then 
     ? 2  
     fallthru 
  case 5 then 
     ? 5 
     fallthru 
  case 30 then 
     ? 30 
     ? 123 
  case 27 then 
     ? 27 
  case 81 then 
     ? 81 
end switch  

I think that if you do some analysis you will find that the majority of switch usage is non fall through, so we have made that the default setting and this will mean less typing to do.

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

Search



Quick Links

User menu

Not signed in.

Misc Menu