4 ms·
Isn't that the opposite of the intended implementation? I don't write Rust, but I think your implementation will always return either `None` or the "fallback" v
by khold_stare 2y ago
Isn't that the opposite of the intended implementation? I don't write Rust, but I think your implementation will always return either `None` or the "fallback" value with the `"-default"` key. In the article, the crucial part is that if the first `map.get_mut()` succeeds, that is what is returned.
- brabel 2y agoA great example of how "if it compiles, it runs correctly" is bullshit.
- unshavedyak 2y agoYou're reaching pretty hard there. Your assertion is a massive strawman, the implication seeming to be that "every problem in your logic won't exist if it compiles" - no one thinks you can't write bad logic in any language. Rather it's about a robust type system that gives you tooling to cover many cases at compile time. Even if we ignore logic, Rust has plenty of runtime tooling and runtime issues can still happen as a result. A complaint i often have about Bevy (despite loving it!) is that it has a lot of runtime based plugins/etc which i'd prefer to be compile time. Axum for example has a really good UX while still being heavily compile time (in my experience at least). "If it compiles it works" is still true despite my complaints. Because i don't believe the statement even remotely implies you can't write bad logic or bad runtime code in Rust.
- oivey 2y agoThis particular example explicitly dodges compile time checking for some ad-hoc (but likely safe) runtime behavior. It’s not a strawman at all. It’s a classic example of how sometimes the compiler can’t help you, and even worse, how programmers can defeat their ability to help you.
- unshavedyak 2y agoRight but their statement (as i parsed it) was that the the "if it compiles it works" phrase is bullshit. Since there's some cases where it obviously won't be true. At best it's ignorant of what that phrase means, in my view.
- oivey 2y agoI think they were highlighting that that phrase is bullshit. It’s trivial to escape many compile time checks.
- unshavedyak 2y agoYea, but that's my argument - that they're being dense (i imagine on purpose?). The phrase doesn't mean that nothing can fail at runtime. Of course it doesn't. Rather that we have many tools to write a program that can be written with many compile time checks. For example many representations of state can be describe in compile time checks via enums, type transitions, etc.
- brabel 2y ago> The phrase doesn't mean that nothing can fail at runtime. That's exactly what that phrase means, you're twisting the actual words in the phrase to be able to arrive at something more acceptable in your own mind. All you're saying is "oh you shouldn't take it literally". I can guarantee most people take that literally and it's bullshit.
- unshavedyak 2y agoSo you think everyone using that phrase thinks it's not possible to fail at all at runtime, in any manner? Unsafe, Panic and Error would like a word.
- lelanthran 2y ago> Since there's some cases where it obviously won't be true. That's not how I've seen it used every that I have seen it used. > At best it's ignorant of what that phrase means, in my view. I think your opinion on what the phrase means is a minority opinion.
- saghm 2y agoHonestly, I think the majority of the times I've said that sentence has been after running code that has an obvious mistake (like the code I posted above)!
- saghm 2y agoWhoops, you're definitely right. This is why I shouldn't try to be productive in the morning.