3 ms·
The Python version is straightforward to read and understand to a programmer of any language. The Ruby version is an idiosyncratic symbol soup. If I were taske
by Mawr 2y ago
The Python version is straightforward to read and understand to a programmer of any language. The Ruby version is an idiosyncratic symbol soup.
If I were tasked to modify the Python version to say, handle the case where `item` is an int, it would be immediately obvious to me that all I need to do is modify the `match` statement with `case int() as i:`, I don't even need to know Python to figure that out. On the other hand, modifying the Ruby version seems to require intimate knowledge of its syntax.
- pansa2 2y agoI think for someone with a basic knowledge of both languages, the Ruby version is more understandable than the Python. It's a combination of basic Ruby features, whereas Python's `match` statement is much more obscure - it isn't really Python at all, it's "a DSL contrived to look like Python [...] but with very different semantics" [0]. I don't particularly love the Ruby code either, though - I think the ideal implementation would be something like: fn stringify(item) => item.is_a(Interpolation) then item.value.convert(item.conversion).format(item.format_spec) else item.to_string() fn f(template) => template.map(stringify).join() [0] https://discuss.python.org/t/gauging-sentiment-on-pattern-matching/5770/21 https://discuss.python.org/t/gauging-sentiment-on-pattern-ma...