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