Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
The end of one case is the next case or default. Easy.
C's behaviour is because whoever came up with that idea was clearly thinking in assembly. Then again, all good C programmers think in assembly anyway so that it's no big deal. -
@Codex404 yeah, but there is a design choice. Either fall through by default, which C does unless break is there, or break by default unless continue is there. Fallthrough by default is exactly what would happen with labels in assembly.
-
Well, in Pascal the Case statement does not fall through and in Swift, the switch does not fall through. Actually, it kinda says something... "Safety Belts"
These are languages that are not as concerned with performance as they are concerned with safety for the junior programmer and keeping them from ripping their hair out over beginner bugs.
Stacking a bunch of cases that match a single condition... or putting some "special cases" on top of a base case to leverage the fall-through is the natural way to think when working threads or pre-emptive interrupt work.
As others have said, C thinkers think at the machine level... in assembly. Someone who writes in C stands a good chance of being very handy with a soldering iron. Someone who writes in Pascal or Swift probably could not tell you what a soldering iron looked like. -
@xcodesucks GCC 7 and later has an interesting warning. If the case falls through and is not empty, a comment in certain format is required.
When upgrading GCC, I got bitten by that one in conjunction with my usual -Werror because I obviously had a comment there, but that was from long before the GCC team decided on the recognised format.
And I do have a soldering iron for doing electronics, you got me on that one. :-) -
Ah, check out pattern matching in a ML-family functional programming language like SML, OCaml, F#, or Haskell
It's glorious.
Related Rants
-
BugsBuggy18I found a //TODO in our companies code that's there since early 2016. The company was founded in early 2016.
-
thatsnotnice10['🥚','🐔'].sort(); Now I know the truth ...according to JS.
-
YuganshT7912I had to install a program whose setup file size was 3GB and I already had that setup in my pendrive, but my p...
„Couldn‘t figure out how to detect the end of a case, forced every developer to end a case with a break; so it doesn‘t go through all cases“
- the guy who invented switch case
rant
wk126