| ▲ | epage 4 days ago |
| I think the switch statement design is a foot gun: defaults to fall-through when empty and break when there is a body. https://c3-lang.org/language-overview/examples/#enum-and-swi... |
|
| ▲ | gkbrk 4 days ago | parent | next [-] |
| This feels very natural though, in a "principle of least surprise" kinda way. This is what you'd expect a properly designed switch statement to do. |
| |
| ▲ | HarHarVeryFunny 4 days ago | parent | next [-] | | Least surprise to who? Are there any other mainstream languages that behave this way? I think consistency is the best correlate of least surprise, so having case statements that sometimes fall though, sometimes not, seems awful. | | | |
| ▲ | trinix912 4 days ago | parent | prev | next [-] | | Sadly many of us are so used to the C fall-through behavior that this would be quite a surprise. Personally, I'd rather see a different syntax switch (perhaps something like the Java pattern switch) or no switch at all than one that looks the same as in all C-style languages but works just slightly differently. | |
| ▲ | epage 4 days ago | parent | prev [-] | | It reads naturally but I can see people getting tripped up writing this. Worse for changing existing code. Refactor in a way that removes a body? Likely forget to add a breake |
|
|
| ▲ | riazrizvi 4 days ago | parent | prev | next [-] |
| If I aimed and shot a gun at my foot and a bullet didn’t go through it, I would trash the gun. |
| |
| ▲ | all2 4 days ago | parent | next [-] | | To be fair, I would probably toss the gun away if a bullet went through my foot. | |
| ▲ | fuzztester 4 days ago | parent | prev [-] | | Er, Forth guy as a, would foot trash I the and bullet gun the. Word! |
|
|
| ▲ | bluecalm 4 days ago | parent | prev [-] |
| I agree it's not the best choice.
I mean it's true that you almost always want fall-through when the body is empty and break where it isn't but maybe it would be better to at least require explicit break (or fall-through keyword) and just make it a compiler error if one is missing and the body is not empty. That would be the least surprising design imo. |