1. New Switch Idea
- Posted by jeremy (admin) Mar 27, 2009
- 1151 views
From the discussions in switch statement the devs started discussions up again about switch. We have come to an idea to maybe provide the best of both worlds. Please comment as to what you think about this idea:
1. Provide a with/without option on the switch statement:
integer X = 1 switch X without fallthru do case 1: ? 1 case 2: ? 2 end switch -- output: 1
or the inverse:
integer X = 1 switch X with fallthru do case 1: ? 1 case 2: ? 2 break case 3: ? 3 break case else puts(1, "Something else\n") end switch -- output: -- 1 -- 2
2. Make the switch smart. Any empty case statements have fallthru automatically:
integer X = 1 switch X do case 1: case 2: puts(1, "1 or 2\n") case 3: puts(1, "3\n") case else puts(1, "Some other number\n") end switch -- output: 1 or 2
Now, if we all like this idea, we must make a decision. What should the default action be?
1. with fallthru. This would cause it to act like most switch statements in other languages and is the current action:
integer X = 1 switch X do case 1: ? 1 case 2: ? 2 break case 3: ? 3 break end switch -- Output: -- 1 -- 2
2. without fallthru. This would be like other languages select statement:
integer X = 1 switch X do case 1: ? 1 case 2: ? 2 case 3: ? 3 end switch -- Output: -- 1
3. Provide no deafult, make the user state with fallthru or without fallthru.
So, the thread is now open for discussion!
Jeremy
2. Re: New Switch Idea
- Posted by jeremy (admin) Mar 27, 2009
- 1149 views
My thoughts? I personally like the idea and with the "smart switch" ability, I would prefer that the default be without fallthru. That would seem to hit the largest use of switch. Here's an example of how an undecorated switch would work if we had smart switch and the default of without fallthru:
integer X = 2 switch X do case 1: case 2: case 3: case 4: case 5: puts(1, "5 or less\n") case 6: case 7: case 8: case 9: case 10: puts(1, "at least 6 no more than 10\n") case else puts(1, "less than zero or greater than 10\n") end switch -- output: -- 5 or less
Jeremy
3. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 27, 2009
- 1123 views
3. Provide no deafult, make the user state with fallthru or without fallthru.
I like version 3, with the fall through for empty cases.
Matt
4. Re: New Switch Idea
- Posted by jimcbrown (admin) Mar 27, 2009
- 1113 views
I am for having "without fallthru" or "without break" be the default. I don't see an issue with the user being able to specify what they want (if they are going to be using a switch that is mostly fallthrus such as the Duff's device, then all the more power to "with break" or "with fallthru") as long as there is some mention that fallthru is on.
My personal philosphy - fallthru should be explictly stated.
Also, I know we can just use goto in a select/switch without break statement to achieve the fallthru effect. But I would prefer a new keyword that explictly turns on the fallthru effect, e.g. "fallthru" or "not break". "not break" looks more natural than "goto "some_random_label"" and is less typing (no need for a "label "some_random_label"" after the next case statement), so thats a 2-hit KO! :)
Also, I dislike colons. "switch..do" is ok, but "switch...on" sounds more natural. Also, "case..then"
5. Re: New Switch Idea
- Posted by bernie Mar 27, 2009
- 1128 views
integer X = 1 switch X do case {8,9,8,7}: ? X case {1,2}: ? X case 32: ? X end switch
How about allowing an integer or a sequence between the case keyword and the colon ?
6. Re: New Switch Idea
- Posted by jeremy (admin) Mar 27, 2009
- 1167 views
How about allowing an integer or a sequence between the case keyword and the colon ?
Bernie,
Currently sequences are allowed, but finding of one item in a sequence does not work. We are looking to expand switch/case in 4.1 for some of these options. Here are two examples:
switch "apple" do case "pear": ? 1 case "banana": ? 2 case "apple": ? 3 case "orange": ? 4 end switch -- Output: 3 switch 1 do case {1,2,3}: ? 1 case {4,5,6}: ? 2 case else ? -1 end switch -- Output: -1
Jeremy
7. Re: New Switch Idea
- Posted by bernie Mar 27, 2009
- 1120 views
How about allowing an integer or a sequence between the case keyword and the colon ?
Bernie,
Currently sequences are allowed, but finding of one item in a sequence does not work. We are looking to expand switch/case in 4.1 for some of these options. Here are two examples:
switch "apple" do case "pear": ? 1 case "banana": ? 2 case "apple": ? 3 case "orange": ? 4 end switch -- Output: 3 switch 1 do case {1,2,3}: ? 1 case {4,5,6}: ? 2 case else ? -1 end switch -- Output: -1
Jeremy
Oh yea I see the problem. There is no way to distinguish a numeric from an alpha in a sequence.
The solution to that is to not use a sequence but allow us to do the following. After the case no curlicues which would be interpreted as integers
switch 1 do case 1,2,3: ? 1 case 4,5,6: ? 2 case else ? -1 end switch
8. Re: New Switch Idea
- Posted by Kat Mar 27, 2009
- 1145 views
How about allowing an integer or a sequence between the case keyword and the colon ?
Bernie,
Currently sequences are allowed, but finding of one item in a sequence does not work. We are looking to expand switch/case in 4.1 for some of these options. Here are two examples:
<snip>
Jeremy
I could swear that when i asked for ranges or match() in the case line, i was told it would be too slow, and was therefore rejected. Same for eval(). Yesterday even.
Truely, useless
9. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 27, 2009
- 1118 views
I could swear that when i asked for ranges or match() in the case line, i was told it would be too slow, and was therefore rejected. Same for eval(). Yesterday even.
Yes, things like checking for less than, match(), or anything that isn't a discrete value to compare against is much more difficult. Something like 1,2,3 could be simply syntactic sugar for several case statements, and, at least from an implementation point of view, very different from the much less constrained things you had brought up.
Matt
10. Re: New Switch Idea
- Posted by jimcbrown (admin) Mar 27, 2009
- 1133 views
I could swear that when i asked for ranges or match() in the case line, i was told it would be too slow, and was therefore rejected. Same for eval(). Yesterday even.
Truely, useless
I think it was just said that it'd have to wait for 4.1 since it'd need a redesign of switch. After the redesign, we'd have two types of switches (a fast one and a slower one that does eval() and such) but to the 4.1 user its all the same switch.
11. Re: New Switch Idea
- Posted by DerekParnell (admin) Mar 27, 2009
- 1114 views
Please comment as to what you think about this idea:
I think that the syntax needs to be ...
switch <expr> [(with | without fallthru)] [label "name"] [do] case <valuelist> [:] <statements> case <valuelist> [:] <statements> case <valuelist> [:] <statements> . . . case else <statements> end switch
Where
- <expr> is an expression that evaluates to any Euphoria object
- If there is no 'fallthru' clause then 'without fallthru' is assumed
- <valuelist> is a comma-separated list of one or more discrete values that <expr> can equal to.
- <statements> is a block of one or more euphoria statements. A zero length statement block is not allowed.
- If 'without fallthru' is in operation, once <statements> block is executed, control passes to the 'end switch' line. Any 'break' statements are ignored.
- If 'with fallthru' is in operation, once a <statements> block is executed and is does not end in a 'break' statement, control passes to the next (if any) lexical <statements> block, otherwise control is passed to the 'end switch'.
- 'goto' can be used to manually change control flow within a switch.
Examples:
integer X = 1 switch X without fallthru case 1 ? 1 case 2 ? 2 end switch -- output: -- 1
integer X = 1 switch X with fallthru case 1 ? 1 case 2 ? 2 end switch -- output: -- 1 -- 2
integer X = 1 switch X with fallthru case 1 ? 1 case 2 ? 2 break case 3 ? 3 end switch -- output: -- 1 -- 2
integer X = 1 switch X case 1 ? 1 case 2 ? 2 end switch -- output: -- 1
object X = "three" switch X case 1,2,"three",4.112233, 5 ? 1 case 6,7,8,9,10 ? 2 end switch -- output: -- 1
12. Re: New Switch Idea
- Posted by jeremy (admin) Mar 27, 2009
- 1133 views
- Last edited Mar 28, 2009
I think that the syntax needs to be ...
switch <expr> [(with | without fallthru)] [label "name"] [do] case <valuelist> [:] <statements> case <valuelist> [:] <statements> case <valuelist> [:] <statements> . . . case else <statements> end switch
If I remember correctly, we had optional then's and do's added to Euphoria and it was quickly reverted. Maybe do is not the correct word, but Jim suggested "on" which sounds nice. He also suggested case <value> then which keeps with Euphoria syntax.
Where
- <expr> is an expression that evaluates to any Euphoria object
- If there is no 'fallthru' clause then 'without fallthru' is assumed
We agree here.
- <valuelist> is a comma-separated list of one or more discrete values that <expr> can equal to.
I thought that we had decided to add things like this in 4.1? If we do that now, I believe we are changing switch quite a bit and are going to push back 4.0 further. Adding them later on does not change the syntax for switch, it will only make some things easier.
- <statements> is a block of one or more euphoria statements. A zero length statement block is not allowed.
I personally, really liked the idea given by Matt, as copied from C#, of a smart switch that allowed:
switch X do case 1: case 2: case 3: -- do something end switch
Now, with your full proposal of allowing case 1,2,3: I guess the smart switch does make less sense to be excited about because you solve the same problem with allowing a list of items, then the block of code. I am assuming that case 1,2,3 would be written the same as the IL code of case 1: case 2: case 3: ?
- If 'without fallthru' is in operation, once <statements> block is executed, control passes to the 'end switch' line. Any 'break' statements are ignored.
Why ignore a break? What if there were some condition in place that the user wanted to break from?
- If 'with fallthru' is in operation, once a <statements> block is executed and is does not end in a 'break' statement, control passes to the next (if any) lexical <statements> block, otherwise control is passed to the 'end switch'.
I agree also.
- 'goto' can be used to manually change control flow within a switch.
We don't want to make the wrong decision with switch, but I think we should be sensitive to the fact that we are now at 1 year of 4.0 being developed. If there is anything we can enhance in 4.1 without cause syntax incompatabilities, I think it should be strongly considered. With the list type syntax, I know that there were all sorts of ideas. Before moving to a situation like that, it may warrant quite a bit of planning. If we accepted the current syntax of just 1 item per case, that would not conflict with 4.1 allowing multiple values per case. I am a bit concerned that if we rush to allow multiple values per case statement that come 4.1 when we sit down and think long and hard about it that we may create a syntax incompatability, or wish we wouldn't have rushed to make it in 4.0.
Jeremy
13. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 27, 2009
- 1135 views
- Last edited Mar 28, 2009
- <valuelist> is a comma-separated list of one or more discrete values that <expr> can equal to.
I thought that we had decided to add things like this in 4.1? If we do that now, I believe we are changing switch quite a bit and are going to push back 4.0 further. Adding them later on does not change the syntax for switch, it will only make some things easier.
- <statements> is a block of one or more euphoria statements. A zero length statement block is not allowed.
I personally, really liked the idea given by Matt, as copied from C#, of a smart switch that allowed:
switch X do case 1: case 2: case 3: -- do something end switch
Now, with your full proposal of allowing case 1,2,3: I guess the smart switch does make less sense to be excited about because you solve the same problem with allowing a list of items, then the block of code. I am assuming that case 1,2,3 would be written the same as the IL code of case 1: case 2: case 3: ?
Making the cases accept a comma delimited list is probably easier to do than to allow configurable fall through. And yeah, it should look the same from an IL point of view.
- If 'without fallthru' is in operation, once <statements> block is executed, control passes to the 'end switch' line. Any 'break' statements are ignored.
Why ignore a break? What if there were some condition in place that the user wanted to break from?
Yes, I don't understand this either. Unless Derek means when break is the last statement before the next case, at which point, I'd probably implement it to skip emitting the 'auto-break'. Six of one, half dozen of the other.
Matt
14. Re: New Switch Idea
- Posted by DerekParnell (admin) Mar 27, 2009
- 1129 views
- Last edited Mar 28, 2009
If I remember correctly, we had optional then's and do's added to Euphoria and it was quickly reverted.
The 'switch' is in a different situation though. In the other cases, anything could possibly occur after the 'do' keyword so it is impossible to recognise where the 'if/while/loop/etc' clause ended and the statement block started. In the 'switch' situation, the only valid thing after the 'do' is the 'case' keyword, and thus the first 'case' occurance signals the end of the 'switch' clause - the 'do' is actually redundant.
Maybe do is not the correct word, but Jim suggested "on" which sounds nice.
Yes 'on' is better than 'do', but is it worth a new keyword that would also be redundant?
He also suggested case <value> then which keeps with Euphoria syntax.
I'm sorry, but I don't understand what you mean. Is this instead of the 'switch <expr>' or are just saying that the colon is optional?
I thought that we had decided to add things like this in 4.1? If we do that now, I believe we are changing switch quite a bit and are going to push back 4.0 further. Adding them later on does not change the syntax for switch, it will only make some things easier.
Sure leave value lists for 4.1. I'm fine with that. It's not too hard to do anyway.
- <statements> is a block of one or more euphoria statements. A zero length statement block is not allowed.
I personally, really liked the idea given by Matt, as copied from C#, of a smart switch that allowed:
switch X do case 1: case 2: case 3: -- do something end switch
Now, with your full proposal of allowing case 1,2,3: I guess the smart switch does make less sense to be excited about because you solve the same problem with allowing a list of items, then the block of code. I am assuming that case 1,2,3 would be written the same as the IL code of case 1: case 2: case 3: ?
At first reading I thought the empty case fallthru was a good idea too, but later I realized it would introduce an exceptional situation that may be more confusing to have than not have. It would mean that sometimes there is automatic fall though and sometimes there is not, with similar looking syntax. By not allowing zero-length statement blocks, it means that all 'case' clauses have the same default behaviour with in a switch statement.
And yes, the value list would generated IL that used the same jump-table logic as currently happens. It is just a syntax-sugar with much reduced typing.
- If 'without fallthru' is in operation, once <statements> block is executed, control passes to the 'end switch' line. Any 'break' statements are ignored.
Why ignore a break? What if there were some condition in place that the user wanted to break from?
Maybe it was poor wording on my part. What I meant was that in effect any explicit break statement at the end of the statement block would be ignored because all statement blocks would behave as if there was a 'break' already there.
We don't want to make the wrong decision with switch, ... I am a bit concerned that if we rush to allow multiple values per case statement that come 4.1 when we sit down and think long and hard about it that we may create a syntax incompatability, or wish we wouldn't have rushed to make it in 4.0.
Of course. But I only recall two value-list suggestions, one with braces and one with out. It was agreed that the braces would not be useful after all and could be omitted and still have a valid list.
15. Re: New Switch Idea
- Posted by jeremy (admin) Mar 27, 2009
- 1088 views
- Last edited Mar 28, 2009
Derek,
What I meant by "case <value> then" is:
switch X do case 1 then -- do something case 2 then -- do something else case 3,4,5 then -- do something else end switch
removing the : all together. The above seems much more euphorian to me.
Using "on" vs. "do" ... I think your right. It sounds good, but switch X do is not hard to comprehend either. Another keyword would me we can't have a flag on = TRUE, however, on would be a bad variable name anyway... on what? light_on, fan_on, would be better.
Case list. If a case list is not hard to implement and will not cause further delays, then there is no reason on putting it off until 4.1. While we are making these changes to switch, just change that too. My only concern is that we may decide to do something different with it in the future and will then have this baggage to live with. I cannot think of anything, but I only thought for a short time. Would we ever want a case statement to do other things that the list format would conflict with?
I do like the case list better:
switch X do case 1: case 2: case 3: -- 1, 2 or 3 case 1,2,3: -- 1, 2 or 3 end switch
Jeremy
16. Re: New Switch Idea
- Posted by Critic Mar 28, 2009
- 1099 views
My proposal:
select value do case 1, 2, 3, 5..78: doA() case 6, 99: doB() else doC() end select switch value do case 1, 2, 3, 5..78: doA() case 6, 99: doB() else doC() end switch
The only difference between "switch" and "select" is that "switch" falls through, "select" does not. To avoid a fallthrough inside a "switch" a "break" statement could be allowed. Personally, I would omit "switch" completely as it is not often needed and confusing, especially since EU also targets hobby programmers. But I included it in my proposal because others want the feature.
17. Re: New Switch Idea
- Posted by euphoric (admin) Mar 28, 2009
- 1106 views
integer X = 1 switch X with fallthru case 1 ? 1 case 2 ? 2 end switch -- output: -- 1 -- 2
Is that output correct? If so, can somebody explain again why if the case doesn't match it still runs the code? I think it was explained before but I've forgotten the logic.
I'd expect the output above to be
-- output: -- 1
18. Re: New Switch Idea
- Posted by jeremy (admin) Mar 28, 2009
- 1067 views
integer X = 1 switch X with fallthru case 1 ? 1 case 2 ? 2 end switch -- output: -- 1 -- 2
Is that output correct? If so, can somebody explain again why if the case doesn't match it still runs the code? I think it was explained before but I've forgotten the logic.
I'd expect the output above to be
-- output: -- 1
with fallthru means that the execution will fall right thru any case statements it may find, i.e. pay no attention to them, once (and only once) a case statement caused it to start executing code in the switch. His example is correct.
switch 1 with fallthru do case 1: ? 1 case 2: ? 2 case 3: ? 3 break case 4: ? 4 case 5: ? 5 end switch -- Output is: -- 1 -- 2 -- 3 -- -- If it would have been switch 4, the output would have been -- 4 -- 5
The action you are describing would be without fallthru, i.e. switch does not just fall right through the next case statement. The next case statement after a match was found is treated as a break case.
switch 1 without fallthru do case 1: ? 1 case 2: ? 2 case 3: ? 3 case 4: ? 4 end switch -- Output: -- 1
Jeremy
19. Re: New Switch Idea
- Posted by jeremy (admin) Mar 28, 2009
- 1094 views
My proposal:
select value do case 1, 2, 3, 5..78: doA() case 6, 99: doB() else doC() end select switch value do case 1, 2, 3, 5..78: doA() case 6, 99: doB() else doC() end switch
The only difference between "switch" and "select" is that "switch" falls through, "select" does not. To avoid a fallthrough inside a "switch" a "break" statement could be allowed. Personally, I would omit "switch" completely as it is not often needed and confusing, especially since EU also targets hobby programmers. But I included it in my proposal because others want the feature.
We decided on the dev list against this because of the very close similarities of switch/selects operations. Further, we think it's a good service to educate the programmer on fallthru and without fallthru as it will help them quite a bit when using other languages as well. However, thank you for your suggestion! This suggestion was explained well and not criticizing anyone or anything. This was what is helpful. Thanks!
Also, EU's target is no longer hobby programmers. EU is a general purpose programming language suitable for a wide variety of tasks. There are commercial applications written in Euphoria and commercial quality apps. Many of us also use Euphoria in our work place for mission critical tasks.
Jeremy
20. Re: New Switch Idea
- Posted by SDPringle Mar 28, 2009
- 1096 views
Why say with or without fallthru when you could say without or with break?
switch without break -- default C like switch current behavior switch with break -- BASIC select like behavior: automatically put breaks in before each case
Equivalent to the current idea except you don't introduce yet another keyword.
Shawn Pringle
21. Re: New Switch Idea
- Posted by jeremy (admin) Mar 28, 2009
- 1094 views
Why say with or without fallthru when you could say without or with break?
switch without break -- default C like switch current behavior switch with break -- BASIC select like behavior: automatically put breaks in before each case
Equivalent to the current idea except you don't introduce yet another keyword.
To me, with/without break is confusing. without break. Does that mean the switch statement does not automatically insert breaks for me? or does it mean that I can do the switch without breaks (i.e. me not inserting a break).
The term for the behavior we are toggling is fall thru. with fallthru and without fallthru is clear and there is no mistaking it.
Jeremy
22. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 28, 2009
- 1112 views
Why say with or without fallthru when you could say without or with break?
switch without break -- default C like switch current behavior switch with break -- BASIC select like behavior: automatically put breaks in before each case
Equivalent to the current idea except you don't introduce yet another keyword.
To me, with/without break is confusing. without break. Does that mean the switch statement does not automatically insert breaks for me? or does it mean that I can do the switch without breaks (i.e. me not inserting a break).
The term for the behavior we are toggling is fall thru. with fallthru and without fallthru is clear and there is no mistaking it.
Yes, I agree, but I think the with statement should be mandatory. Also, I'm not sure I follow the discussion regarding do. People have said that it's used for while in order to be a separator, but this isn't really true. IIRC, we put do in the switch construct to keep it consistent with other euphoria paradigms. We always have a do or then to start a code block.
I think that we should keep this consistent with switch. I'm not against using some other word, but I think we should have something there.
Matt
23. Re: New Switch Idea
- Posted by jeremy (admin) Mar 28, 2009
- 1134 views
I think that we should keep this consistent with switch. I'm not against using some other word, but I think we should have something there.
Matt, I agree.
switch X case 10: ? 10 end switch
looks naked amongst other Euphoria code. Un-natrual. Now, what do you think of dropping the : and using then? I like that idea also as it seems to fit our syntax better:
switch X do case 10 then ? 0 case 20, 30, 40, 50 then ? 1 end switch
vs
switch X do case 10: ? 0 case 20, 30, 40, 50: ? 1 end switch
Jeremy
24. Re: New Switch Idea
- Posted by euphoric (admin) Mar 28, 2009
- 1090 views
with fallthru means that the execution will fall right thru any case statements it may find, i.e. pay no attention to them, once (and only once) a case statement caused it to start executing code in the switch. His example is correct.
Thanks Jeremy.
25. Re: New Switch Idea
- Posted by Critic Mar 28, 2009
- 1107 views
We decided on the dev list against this because of the very close similarities of switch/selects operations.
Well, that's the point: Similar operation - similar look. I dislike "switch without fallthru" because it is too verbose ("fallthru" is even spelt wrong). And making "select" a keyword really does no harm, IMHO.
Also, EU's target is no longer hobby programmers. EU is a general purpose programming language suitable for a wide variety of tasks. There are commercial applications written in Euphoria and commercial quality apps. Many of us also use Euphoria in our work place for mission critical tasks.
That's another discussion for which I will open another thread soon. It'll be a longer post.
26. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 28, 2009
- 1090 views
Now, what do you think of dropping the : and using then? I like that idea also as it seems to fit our syntax better:
switch X do case 10 then ? 0 case 20, 30, 40, 50 then ? 1 end switch
That does seem more euphorian.
Matt
27. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 28, 2009
- 1118 views
We decided on the dev list against this because of the very close similarities of switch/selects operations.
Well, that's the point: Similar operation - similar look. I dislike "switch without fallthru" because it is too verbose ("fallthru" is even spelt wrong). And making "select" a keyword really does no harm, IMHO.
The problem is that they are possibly too similar, especially to introduce into a language that's never had either. We have to consider the effect upon the user base. Euphoria has always been a fairly verbose language, and the with/without syntax goes along with that, including making the intended and expected behavior crystal clear.
Also, there's always a downside to adding keywords. And select is a common word, from GUI widgets and databases.
Matt
28. Re: New Switch Idea
- Posted by Critic Mar 30, 2009
- 1090 views
The problem is that they are possibly too similar, especially to introduce into a language that's never had either.
Implement "select" then. Some users have already complained they don't want/understand fallthrough.
We have to consider the effect upon the user base. Euphoria has always been a fairly verbose language, and the with/without syntax goes along with that, including making the intended and expected behavior crystal clear.
Yes, EU is quite verbose already - don't make it worse! Fallthrough is not "crystal clear", it is a wierd concept that no other control statement uses.
Also, there's always a downside to adding keywords. And select is a common word, from GUI widgets and databases.
Provide a command line tool to rename an EU identifier. This will be very useful anyway and is not hard to do.
29. Re: New Switch Idea
- Posted by DanM Mar 30, 2009
- 1062 views
We decided on the dev list against this because of the very close similarities of switch/selects operations.
Well, that's the point: Similar operation - similar look. I dislike "switch without fallthru" because it is too verbose ("fallthru" is even spelt wrong). And making "select" a keyword really does no harm, IMHO.
The problem is that they are possibly too similar, especially to introduce into a language that's never had either. We have to consider the effect upon the user base. Euphoria has always been a fairly verbose language, and the with/without syntax goes along with that, including making the intended and expected behavior crystal clear.
Also, there's always a downside to adding keywords. And select is a common word, from GUI widgets and databases.
Matt
Although this thread/discussion is how to implement "switch",
FWIW I like select, because it seems more clear to me what it is going to do. That is, it will select amongst the various cases, depending on the value of the variable or function or whatever. Therefore I'd prefer to see select included.
I do like the use of "then" after each case statement, as it seems to help the code reader/writer know what's happening.
And if a "fallthrough" concept is in fact useful, then I'd like to suggest a different word for that:
after
meaning: after a value is encountered in case statement, do it and all that follow after it
as in:
X = 3 after X do case 1 then ? 1 case 2 then ? 2 case 3 then ? 3 case 4 then ? 4 output: 3 4
And why not stop instead of break to STOP fallthrough ?
just my $.02 worth, I realize there may be good reasons not to do any of the above
Dan
30. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 30, 2009
- 1059 views
The problem is that they are possibly too similar, especially to introduce into a language that's never had either.
Implement "select" then. Some users have already complained they don't want/understand fallthrough.
Yes, which is why we're discussing changing the current implementation of switch.
We have to consider the effect upon the user base. Euphoria has always been a fairly verbose language, and the with/without syntax goes along with that, including making the intended and expected behavior crystal clear.
Yes, EU is quite verbose already - don't make it worse! Fallthrough is not "crystal clear", it is a wierd concept that no other control statement uses.
Yes, no other control statement uses it. So what? No other control statement besides for uses 'by'. I understand that you disagree with fall through completely. That's fine. But Euphoria will have a switch with fall through, even though probably not as the default.
It's crystal clear in that a reader could not be confused as to whether the switch was using fall through or not. Obviously, that isn't meant to explain what fall through is.
Also, there's always a downside to adding keywords. And select is a common word, from GUI widgets and databases.
Provide a command line tool to rename an EU identifier. This will be very useful anyway and is not hard to do.
Yes, that would be useful. But it still doesn't remove the downside to adding keywords.
Matt
31. Re: New Switch Idea
- Posted by Critic Mar 30, 2009
- 1043 views
Yes, that would be useful. But it still doesn't remove the downside to adding keywords.
And why not? (I wonder if you have ever had a valid point when discussing about programming.)
32. Re: New Switch Idea
- Posted by jimcbrown (admin) Mar 30, 2009
- 1034 views
Yes, that would be useful. But it still doesn't remove the downside to adding keywords.
And why not? (I wonder if you have ever had a valid point when discussing about programming.)
Someone would still have the headache of running the tool against old source code to fix it. Doing it all at once would be a big job, and while doing it as each source file is needed (to be reused in a new app) in a step by step process might be more reasonable, this is also more drawn out.
This is the whole point of getting all such changes in 4.0 - we only want to deal with this hassle once. After 4.0 the goal is to avoid changes that break source code.
33. Re: New Switch Idea
- Posted by mattlewis (admin) Mar 30, 2009
- 1055 views
Yes, that would be useful. But it still doesn't remove the downside to adding keywords.
And why not? (I wonder if you have ever had a valid point when discussing about programming.)
Because you've still added a keyword. Look, I'll type real slow-like, so maybe you can understand.
Y o u h a v e s t i l l a d d e d a k e y w o r d.
Matt
34. Re: New Switch Idea
- Posted by irv Mar 30, 2009
- 1063 views
"Critic" is beginning to sound very much like someone who got himself fired some years ago for trolling the Euphoria list.
Looking up language concepts in your schoolbooks is easy. Implementing them is not so easy. I doubt he's up to that.