C++ has struggled with this, so that paper authors sometimes plead with the committee not to make their proposal needlessly worse in the name of "consistency" with existing bad features. This famously failed for std::span, which thus managed to be not only a real world footgun in a language which already has plenty of footguns but also a PR footgun - because for "consistency" the committee removed the safety from the safety feature and I believe in C++ 26 they will repair this so it's just pointless rather than actively worse...
no it's not. you literally have no other choice. you cannot add scopes after the fact - it is a breaking change. you cannot have some parts of the language have scopes and others not - it's so much worse for the user. think about human languages and which ones get quoted as being the hardest to learn (those with many exceptions). you're just wrong.
Notice that the Python doesn't work this way, we didn't make a new variable but instead changed the existing one.
Also, the intent in the Python was a constant, in Rust we'd give this constant an uppercase name by convention, but regardless it's a constant and so of course matching against a constant does what you expect, it can't re-bind a constant, 404 is a constant and so is `const NOT_FOUND: u16 = 404;`
if each x's scope ends at the end of each case doesn't that mean there's only one x?
> we didn't make a new variable but instead changed the existing one.
so because python doesn't have scopes except for function scopes it shouldn't ever have any new features that intersect with scope?
It's "a DSL contrived to look like Python, and to be used inside of Python, but with very different semantics":
https://discuss.python.org/t/gauging-sentiment-on-pattern-ma...
Ruby's `case`/`in` has the same problem.
it doesn't? you simply don't understand what a match statement is.
https://doc.rust-lang.org/book/ch19-03-pattern-syntax.html
let num = Some(4);
match num {
Some(x) if x % 2 == 0 => println!("The number {x} is even"),
Some(x) => println!("The number {x} is odd"),
None => (),
}
notice that x is bound to 4. match status:
case 404:
return "Not found"
not_found = 404
match status:
case not_found:
return "Not found"
Everywhere else in the language, you can give a constant a name without changing the code's behaviour. But in this case, the two snippets are very different: the first checks for equality (`status == 404`) and the second performs an assignment (`not_found = status`).We live in deeply unserious times.