3 ms·
This is the bad part of Python's match, I don't understand why they want to do it this way - in neither Scala, Rust, F#, C# you'd would (AFAIK) hit such issue.
by exyi 6y ago
This is the bad part of Python's match, I don't understand why they want to do it this way - in neither Scala, Rust, F#, C# you'd would (AFAIK) hit such issue. For example C# example of both behaviors: https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQMwAJboMLoN7LpHoDGA9gHYDOALugJYV0Vk0BiZArhcOgLzoALAAZBAbkLE0mOMPQBZABSM65YAFMAlPknFiVAO70aJABbpFarTqR67xEgEMq69C3ZceIXffs1TAE5kBm7qIQCiAB4k6gAONPSUigBEAHKs6BzcwMmaEra+AL4+eiXEAPTl6ABuVOjqkbEANvQkxmVEHeiGxmYWVtoEBb4Ozq7VjgFurFleXb7+QSEUYehRMfGJFCnpdLO8/o50ALZHZup1jk1NufkjxcPoD4VAA== https://sharplab.io/#v2:CYLg1APgAgTAjAWAFBQMwAJboMLoN7LpHoDG...
- duckerude 6y agoI don't know about those other languages, but Rust needs static type information to solve it (which Python doesn't have). Take this code: static NOT_FOUND: i32 = 404; match 403 { NOT_FOUND => println!("Not found"), _ => println!("Other"), } It doesn't compile: error[E0530]: match bindings cannot shadow statics It does compile if you change static to const (and then it does what you want). But if you misspell NOT_FOUND so it doesn't shadow a static then it misbehaves in the same way as the Python version, with only a few warnings to show for it. Python has the limitation that there's no fundamental difference between ordinary variables and constants. I don't know of an alternative proposal for Python that isn't burdensome or also dangerously surprising.
- pansa2 6y agoThat C# example is so much nicer than Python’s approach of casually breaking fundamental programming principles [0]. I wonder why Python’s designers didn’t use something similar? [0] https://twitter.com/brandon_rhodes/status/1360226108399099909 https://twitter.com/brandon_rhodes/status/136022610839909990...