switch v2
---------
// switch v2 example:
switch (x) // Supports the new (e; x) too of course.
switch;
// end example.
Changes from classic switch:
My main issues with the current switch which I hope these changes address are:
* I hate trying to format switches. I'd like less nesting and brace ambiguity and formatting concerns here.
Win32 window message handling functions are a great example of what I want to make cleaner.
* I find switch verbose.
* break is not usually the default I want.
Questions:
1. Would this new syntax create any obvious parsing issues that would make it a no go.
I'm talking about the minimum in the example.
2. I'd like to support case (10,20,30): With an 'if any of these' meaning.
Is that syntax going to work or must a new syntax be invented here too.
If new, suggestion welcome.
3. I am mulling allow fallthrough as a keyword. But perhaps just insist on goto regular label?
Opinions on this please.
4. I'm also keen to narrow down what if anything can exist in a switch but outside of a case/default block.
I believe attributes and labels are necessary but probably no more.
Thanks
I'm keen to be rid of braces opening switches though as I think that's the root of my formatting and nesting dislike.I also think that switches tend to be quite long so looking at a closing brace on switch offers no surety what it is.Closing with switch; would fix that. It's unusual for C++ but I think we'd get use to it.I'd probably vote for the space for namespaces too. i.e.:namespace zen: // open//whatevernamespace zen; // closeAny takers?
...I just noticed the subtle difference, in that the opening declaration ends with a colon, and the closing with a semicolon. However, I think that might even support the point I was trying to make ;-)
...I just noticed the subtle difference, in that the opening declaration ends with a colon, and the closing with a semicolon. However, I think that might even support the point I was trying to make ;-)
Sorry I don't get where you are coming from here?Most code that I see looks like this:namespace zen {} // zenWhich I dislike because people update the first zend and forget the second zen in the comment.Same thing happens in include guards. #endif //whateverWhat I suggested was to get rid of that and make it this:namespace zen:// Long stuff here, above line opens, below line closes, compiler checks it matches.namespace zen;So we are already using comments to make code clear and the comments get out of step.My suggestion would seem to fix that?So what don't you like about that again please?
The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
On Saturday, January 7, 2017 at 3:15:25 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 7:53:33 AM UTC-5, gmis...@gmail.com wrote:The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
It has a syntax that is fundamentally different from anything else in C++. Your definition of "clean" is to not use braces. Well... tough. Curly braces is how C++ defines scopes. Pretty much everything that defines a scope uses them: functions, classes, if/for/while/do, etc.
Why should we change something that fundamental to how the language looks, just because one person doesn't like using braces for scopes? How does this objectively, or even semi-objectively, improve the language?
Consistency of the language is more important than one user's comfortI've offered my answer to this in another reply. But I as yet don't see any essential consistency lost here yet
but it's too soon to say. I think we have to see what ideas come forth and how they fit together as a whole before judging too harshly.
We should also factor in what we might gain here against what we might lose. We likely need a new switch to add all the other things we want beyond formatting issues too.
On Friday, January 6, 2017 at 9:34:07 AM UTC-5, gmis...@gmail.com wrote:On Saturday, January 7, 2017 at 3:15:25 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 7:53:33 AM UTC-5, gmis...@gmail.com wrote:The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
It has a syntax that is fundamentally different from anything else in C++. Your definition of "clean" is to not use braces. Well... tough. Curly braces is how C++ defines scopes. Pretty much everything that defines a scope uses them: functions, classes, if/for/while/do, etc.
Why should we change something that fundamental to how the language looks, just because one person doesn't like using braces for scopes? How does this objectively, or even semi-objectively, improve the language?
Consistency of the language is more important than one user's comfortI've offered my answer to this in another reply. But I as yet don't see any essential consistency lost here yet
Of course you don't; you have already said that you don't like curly braces. That doesn't chance the fact that this would be the first place in C++ that defines a scope without braces (or without being limited to a single statement).
You cannot deny that what you have proposed is a novel grammar to C++.
but it's too soon to say. I think we have to see what ideas come forth and how they fit together as a whole before judging too harshly.
I don't understand what you're talking about with regard to "what ideas come forth". If you're talking about what other features people might throw into this proposal, those "ideas" would work just as effectively in a `switch` statement that uses standard C++ grammar.
We should also factor in what we might gain here against what we might lose. We likely need a new switch to add all the other things we want beyond formatting issues too.
And when we get one, it will use curly braces.
On Saturday, January 7, 2017 at 4:10:44 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 9:34:07 AM UTC-5, gmis...@gmail.com wrote:On Saturday, January 7, 2017 at 3:15:25 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 7:53:33 AM UTC-5, gmis...@gmail.com wrote:The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
It has a syntax that is fundamentally different from anything else in C++. Your definition of "clean" is to not use braces. Well... tough. Curly braces is how C++ defines scopes. Pretty much everything that defines a scope uses them: functions, classes, if/for/while/do, etc.
Why should we change something that fundamental to how the language looks, just because one person doesn't like using braces for scopes? How does this objectively, or even semi-objectively, improve the language?
Consistency of the language is more important than one user's comfortI've offered my answer to this in another reply. But I as yet don't see any essential consistency lost here yet
Of course you don't; you have already said that you don't like curly braces. That doesn't chance the fact that this would be the first place in C++ that defines a scope without braces (or without being limited to a single statement).
You cannot deny that what you have proposed is a novel grammar to C++.I don't deny it's was novel. I am just saying "switch;" might not seem as out there if the other suggestions I've made with it were also enacted and I've presented a rationale why those suggestions might be motivating to some.
switch(blah) break
{
//Stuff
}
Do you prefer comments to remind people what namespace is ending?Have you seen people use comments to do that?
If you have seen comments, that might show other people might prefer an option to check them even if you don't.We don't know what people prefer until we ask, so I'm asking. I've seen comments used this way.but it's too soon to say. I think we have to see what ideas come forth and how they fit together as a whole before judging too harshly.
I don't understand what you're talking about with regard to "what ideas come forth". If you're talking about what other features people might throw into this proposal, those "ideas" would work just as effectively in a `switch` statement that uses standard C++ grammar.We should also factor in what we might gain here against what we might lose. We likely need a new switch to add all the other things we want beyond formatting issues too.
And when we get one, it will use curly braces.I hope you are right, but I didn't like the curly switches I experimented with so why don't you propose yours and then we can compare which formats the best? If yours is better I'll happily um switch to it. :)
I hope you are right, but I didn't like the curly switches I experimented with so why don't you propose yours and then we can compare which formats the best? If yours is better I'll happily um switch to it. :)
On Saturday, January 7, 2017 at 4:10:44 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 9:34:07 AM UTC-5, gmis...@gmail.com wrote:On Saturday, January 7, 2017 at 3:15:25 AM UTC+13, Nicol Bolas wrote:On Friday, January 6, 2017 at 7:53:33 AM UTC-5, gmis...@gmail.com wrote:The basic V2 switch I want has a cleaner syntax that is easier to format and use. To me that means it has automatic scopes, case that break at the end automatically and a structure that minimizes nesting and an excess braces. That seem important to me.
It has a syntax that is fundamentally different from anything else in C++. Your definition of "clean" is to not use braces. Well... tough. Curly braces is how C++ defines scopes. Pretty much everything that defines a scope uses them: functions, classes, if/for/while/do, etc.
Why should we change something that fundamental to how the language looks, just because one person doesn't like using braces for scopes? How does this objectively, or even semi-objectively, improve the language?
Consistency of the language is more important than one user's comfortI've offered my answer to this in another reply. But I as yet don't see any essential consistency lost here yet
Of course you don't; you have already said that you don't like curly braces. That doesn't chance the fact that this would be the first place in C++ that defines a scope without braces (or without being limited to a single statement).
You cannot deny that what you have proposed is a novel grammar to C++.I don't deny it's was novel. I am just saying "switch;" might not seem as out there if the other suggestions I've made with it were also enacted and I've presented a rationale why those suggestions might be motivating to some.Do you prefer comments to remind people what namespace is ending?
Have you seen people use comments to do that?If you have seen comments, that might show other people might prefer an option to check them even if you don't.We don't know what people prefer until we ask, so I'm asking. I've seen comments used this way.
A problem demonstrated here is that trying to do too much in one proposal (so far as we can call this that) is likely to fail, as the discussion becomes bogged down in focussing on one thing, often relatively cosmetic, which the proposer thought was something handy to do 'on the side' but which ends up eclipsing the main, functional changes (not that I like those much either)
Also:The onus is on you to prove that your idea is viable or useful, not on others to provide better alternatives.I hope you are right, but I didn't like the curly switches I experimented with so why don't you propose yours and then we can compare which formats the best? If yours is better I'll happily um switch to it. :)
On Fri, Jan 6, 2017 at 1:53 PM, <gmis...@gmail.com> wrote:> I agree with all you've said, but I want to start small as IMO whatever the real switch V2 is, it has to have a basic workable structure that does what switch V1 does in order to graft all that other stuff you want on to.I am not convinced you can have it done this way. Form should follow function, not the other way around.
> What's a basic switch that you'd support look like that does just V1 switch abilities?Again, the issues that you mentioned are not that important for me. I would not change switch just because of them.But since you asked, I want switch v2 as a selection operator, not a statement. So its syntax would an expression syntax.And, because the existing operator ? gets messy as soon as it gets chained, perhaps we can improve that one, too? For example, something along these lines, without explaining the details (chiefly because I am not very sure about these details):auto result = ?? query ?= match_1 => result_1 ?= match_2 => { return result_2; } ?: default_result;auto result = ?? conditional => result_1 ?: default_result;auto result = ?? query ?= match_1 => result_1 ?= match_2=> { return result_2; } ?? conditional => result_3 ?: default_result;Obviously, all these forms can be used as statements. Such use, as far as I can tell, would not have the nuisances you mentioned. Even though I am pretty sure some people will say this is APL rather than C++.
Cheers,V.
On Saturday, January 7, 2017 at 7:36:37 AM UTC+13, D. B. wrote:A problem demonstrated here is that trying to do too much in one proposal (so far as we can call this that) is likely to fail, as the discussion becomes bogged down in focussing on one thing, often relatively cosmetic, which the proposer thought was something handy to do 'on the side' but which ends up eclipsing the main, functional changes (not that I like those much either)I'm not trying to do too much. I posted purely on defining what a basic v2 switch might look like that does what the current switch does, whilst fixing it's formatting issues and most basic problems. That's not too much.In fact one of the first comments I had was that it was not too much, rather it was not enough. I directed that to another thread precisely so things didn't get too much.If think it would be good to have base switch structure that people can coalesce ideas around.
You call it cosmetics but syntax is important. In any case the syntax and basics is what I'm focused on here. If you are going beyond that here, you're solving more than I'm looking at and that might be where too much will come in.But what I'm trying to focus on is the basics.Also:The onus is on you to prove that your idea is viable or useful, not on others to provide better alternatives.I hope you are right, but I didn't like the curly switches I experimented with so why don't you propose yours and then we can compare which formats the best? If yours is better I'll happily um switch to it. :)Answering questions here IS me honouring that onus. I've already fiddled with ideas with braces in and I decided braces were the source of the formatting/verbosity problem. Since you disagree with that essence and given that braces are a pretty simple to explain, the onus is on you now to present how you feel braces work better.
But you aren't doing that. Instead you are stating without presentation that braces must stay or we'll have inconsistency. That hard to fight when you also seem to be contending that any discussion to the contrary on braces (like me suggesting that removing braces from other constructs like namespaces might lessen the notion that "switch;" is an oddity) is complicating the discussion "too much".
Anyway, keeping with my onus, I take from here: https://github.com/solodon4/Mach7this example:void print(const boost::variant<double,float,int>& v)
{
var<double> d; var<float> f; var<int> n;match(v)
{
case(C<double>(d))cout << "double " << d << endl; break;
case(C<float> (f))cout << "float " << f << endl; break;
case(C<int> (n))cout << "int " << n << endl; break;
}
endmatch
}This doesn't use braces in the case statements and I don't find it shocking.