3 ms·
He's got a good point: Why is C still the staple it is? But I believe that Rust is going to take it's place. Not sure whether it's a good thing, but this trick
by neoeldex 10y ago
He's got a good point: Why is C still the staple it is?
But I believe that Rust is going to take it's place.
Not sure whether it's a good thing, but this trick isn't possible in rust ;)
Rust would give an error when an enum isn't exhausted in a match clause. So the issue being described doesn't exist :D
- pdpi 10y agoIt'll be a while still before Rust makes its way to all the platforms with a C compiler (if it ever even happens). As to why it's still a popular language... The C99 spec document is shorter than the Ecma-262 (Javascript) spec by around 50 pages. The parts dedicated to the _languages_ themselves (as opposed to the builtins/standard libraries) weigh in at 130 pages for C, or around 300 pages for JavaScript. C, despite its warts, is a small, simple language.
- catnaroek 10y agoHow much longer would the C specification be if it were fully formalized? And even then, a formalization isn't enough: it has to be useful for actually proving theorems, e.g. “such and such pattern is portable across conforming implementations”, and the size of the proof better not be much larger than the size of the program itself. If the C standard is so useful, try programming using the C standard as your sole debugging tool.
- drivers99 10y ago> Rust would give an error when an enum isn't exhausted in a match clause. So the issue being described doesn't exist :D I was going to say something like that, but the equivalent code would have a "_" case in the match statement. I don't know rust yet, but would a rust programmer typically make a point to not use a "_" (default) statement so that you can catch these at compile time and expect you'll never have anything else?
- geofft 10y agoIt's not just typical, it's required. If you add a default match when you've already specified all the possible cases, the compiler gives you an error. Here's an example (https://is.gd/KjSc8B https://is.gd/KjSc8B): enum Foo { Bar(i32), Baz(i32), } fn matchfoo(f: Foo) -> i32 { match f { Foo::Bar(x) => x, Foo::Baz(x) => x, _ => 42 } } gives "unreachable pattern", a hard error, for the "_" case.
- ordu 10y agoYou can also avoid using `default' statement in C, and use gcc -Wall while compiling. You'll get warning for missing enum values in `case' statements. You even can add -Werror and get errors when some enum values left unused. But when you have a really big enum and need to handle only small subset of it's values it didn't work. When _this_ problem can be avoided in Rust, it can be avoided in C also. The only Rust bonus here is compiler default behaviour.
- johnbellone 10y agoUgh.