logoalt Hacker News

gkbrklast Saturday at 6:24 PM3 repliesview on HN

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.


Replies

HarHarVeryFunnylast Saturday at 6:40 PM

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.

show 1 reply
trinix912last Saturday at 7:28 PM

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.

epagelast Saturday at 11:13 PM

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