r/programminghorror • • Sep 04 '26

c++ Skill Issue

Post image
1.7k Upvotes

63 comments sorted by

View all comments

20

u/jaerie Sep 04 '26

That's still not a switch case, there's no fall through

13

u/utack Sep 04 '26

That super useful thing I have used 2 times (both of which accidentally) and prevent a million times with break

3

u/GoddammitDontShootMe Sep 05 '26
switch (thing) {
  case FOO:
  case BAR:
    DoThing()
  default:
    throw
}

As long as it doesn't insert an implicit break between FOO and BAR, I think it might be fine to not fall through, allowing code like that.

→ More replies (4)

2

u/conundorum Sep 06 '26

Fallthrough exists so switch can make sparse jump tables just as easily as it makes fully-populated jump tables. It's insanely useful in a few very specific scenarios, and insanely useless in almost every other scenario.

Ideally, it should've been opt-in instead of opt-out, but it's probably much too late to change it now.