dao icon indicating copy to clipboard operation
dao copied to clipboard

switch syntax defect

Open Night-walker opened this issue 10 years ago • 3 comments

switch (var x = ...) or switch (invar x = ...) work, but not switch (x = ...). This omission looks inconsistent with for and while syntax.

Night-walker avatar Sep 01 '15 10:09 Night-walker

The inconsistency is superficial. for and while do not really support for/while( x = expr1 ), they support for/while( x = expr1; expr2 ). And, unlike in for and while, var and invar in switch actually declare a new variable in each case block according its case type.

The only way to make them consistent is to add a new syntax for declaring case-wise variable for type switch.

daokoder avatar Sep 01 '15 15:09 daokoder

Well, from the user's point of view, switch demands the use of var while for, while and, actually, if allow to omit it in a very similar case. Even if that's a simplified perception of things, it is likely the most apparent one, and it requires the user to remember this 'exceptional' case which is not very convenient.

Night-walker avatar Sep 01 '15 17:09 Night-walker

It's true it doesn't look consistent even though it's superficial from the implementation point of view.

dumblob avatar Sep 08 '15 13:09 dumblob