9 ms·
To be fair, you almost never should use the map builtin instead of the pythonic equivalent, list comprehensions. `print([x + 1 for x in [1, 2, 3])` I agree th
by trufas 5y ago
To be fair, you almost never should use the map builtin instead of the pythonic equivalent, list comprehensions.
`print([x + 1 for x in [1, 2, 3])`
I agree that the ruby approach is better in terms of consistency, but most developers will be aware of the conventions python uses.
- Mikeb85 5y agoOk, that's a nicer result (obviously I don't write Python lol) but still seems inconsistent to me (putting the function before the array) considering Python is an OO language and most people are going to be writing methods for classes where you call methods with dot. I just remember list comprehensions from Coffee-script and not going to lie, I hate them. It's like reading backwards.
- iterati 5y agoPython is a multi-paradigm language, of which OO is one paradigm it supports.
- Mikeb85 5y agoRuby has map, filter, reduce and a bunch of other functional methods. It's more about the consistency of wondering what's a function versus what's a method and then things like list comprehensions and for loops. Python also doesn't have a lot of the goodies of a real functional language, it encourages for loops and seems to be even more procedural than Ruby but less OO?
- jimbokun 5y agoRuby is a strongly OO language, which arguably also has better support for functional programming than Python.
- cutler 5y agoYes, that's the Zen of Ruby and why I love it.
- cutler 5y agoNot really. Python 3 is all OO under the hood including what appear to be procedural functions. It's just not as elegant as Ruby's OO.
- knodi123 5y ago> still seems inconsistent to me (putting the function before the array) I'm experienced in ruby, and learning python for a project. I don't think I'll ever not wince when using python's ternary; ruby: size = (waist > 30) ? 'large' : 'small' python: size = 'large' if (waist > 30) else 'small'
- cle 5y agoI've always assumed this was to maintain syntactic consistency with comprehensions like [x for x in arr if x > 2].
- runjake 5y agoYou're splitting hairs about what the op said. How about len() ?
- marquis_andras 5y ago[1,2,3].__len__()
- cutler 5y agoYes, Python is all OO under the hood just like Ruby but ugly as sin.
- weatherlite 5y ago
- junoper 5y agoPython, I think, has n number of ways of doing the same thing while Ruby's everything is object approach forces you down a single approach. So while reading ruby code, you usually don't have to shift your mental model from OOP to procedural/list comprehension etc. If Ruby gets a good machine learning library on par with something like Pytorch, I am sure many folks will shift to it and we might see new DSL emerge.
- regularfry 5y agoWhich is ironic, given that "There should be one-- and preferably only one --obvious way to do it" is in PEP 20.
- cutler 5y agoHow I wish that was a possibility. Unfortunately Python's dominance of ML and AI is a fait accompli. If anything is going to replace Python in this domain it won't be another scripting language with similar performance.