On further thought, I think it probably makes more sense to go with. I like using because if we ever get optional semicolons (which may never happen) then they'll be eliminated too. Yes, we could use a different keyword for switch statements versus expressions, but I don't think that would add much value. If we eliminate case, we'll definitely need some sort of separator to tell when one body ends and the next pattern begins. C# uses, and Java uses for their switch expressions. We use for =>-bodied member declarations (but not lambdas). ![]() I felt that it looked weird without some kind of terminator or separator. I wouldn't think that expression switch needs a terminator either, since it too contains at most one expression, so I was surprised by the s in expression switches. Personally I still think it's better to use switch for all of them, but not because of any language history argument, just because I think switch statements, switch expressions, and switch elements are similar enough that using the same keyword is justified.) ![]() (If that's true then my argument doesn't really apply. ![]() a yet-to-be-designed "switch element" feature? I may be misreading comment but I think he's asking a different question: should we use a different keyword for switch statements vs. To be fair, when I made that argument, we were talking about the idea of retaining switch for classic switch statements and using some new keyword for the new, more powerful pattern-matching form of statement. As much as possible, the features we present to users should make sense even if they had been in Dart 1.0. I think made the argument that the design of the language shouldn't reflect its history. Pattern matching can do everything a switch can do and more, so if we added a new form, then switch would just be a deadweight historical feature. My impression then and now is that reusing switch is better. We did discuss extensively whether it made sense to pick a new keyword for the pattern matching construct. Is there a world where we distinguish these two cases (pardon the pun) more explicitly? I wonder if we are making our life harder for ourselves by trying to reuse the switch keyword for both. We don't have that problem with switch expressions, so we could eliminate case: We really need the case keyword to tell when we've reached the next case. With switch statements, it's actually hard to know when the current body has ended because it's a potentially empty unbounded list of statements. The one thing switch expressions have going for them is that we know the body is always a single expression terminated by. Can we extract any positive value from having a different syntax? You can't have different guards share a body. So if we're going to make switch expressions different, can we actually make them better? Right now, the switch expression syntax-aside from subjectively looking nicer to some-isn't actually materially better. I agree with and others that case: 123 looks like a pointless expression statement that discards a value. Sunday, Using Enum in Switch is very easy. Saturday, Enum in Java are compile time constant. Friday, Enum can also be used in case statement. ![]() Thursday, Java Enum values() method return all enum in an array. Wednesday, I confirm Java Enum can be used in Switch case. The different exhaustiveness behavior suggests to me that we may want switch expressions to be syntactically distinguished from switch elements.Īlso, one of the strongest arguments in favor of => for me is that I simply think it looks more like an expression form using that. Tuesday, apply Enum in Switch just link primitive int. I believe we could eliminate the required terminators here because the subsequent case is enough to tell us when the next case has begun. Switch elements have no been fully designed yet. I see some reasons for throw in a switch statement.ġst: not instead of a break but as the body of the default case.Bool xor( bool a, bool b) => switch ((a, b)) on the nested switch element.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |