Rust would give an error when an enum isn't exhausted in a match clause. So the issue being described doesn't exist :D
Rust would give an error when an enum isn't exhausted in a match clause. So the issue being described doesn't exist :D
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.
If the C standard is so useful, try programming using the C standard as your sole debugging tool.
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?
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.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.