My other comment was in response to the first half of your comment, before an edit added more about structure of code. I'd say I partly agree, but I think another consideration is that in C there is a limit to how much you can reasonably fit in an expression. What in, say, Haskell might look like...
let f = case something of
Foo -> 10
Bar -> 22
cannot reasonably take the same form in C, despite there not being a "real" update going on.
This means in C you wind up writing things like,
int f;
switch(something) {
case Foo:
f = 10;
break;
case Bar:
f = 22;
break;
default:
/* ... handle error ... */
}
And the flow is basically the same, but with an additional degree of freedom to make a mistake, and there some static checking can have your back.
Incidentally, on GCC and Clang I recommend building with -Wswitch-enum, which will help point you at the above when you add something to the enum that contains Foo and Bar.
This means in C you wind up writing things like,
And the flow is basically the same, but with an additional degree of freedom to make a mistake, and there some static checking can have your back.Incidentally, on GCC and Clang I recommend building with -Wswitch-enum, which will help point you at the above when you add something to the enum that contains Foo and Bar.