Hacker News new | ask | show | jobs
by trufas 1622 days 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.

3 comments

Ok, 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.
> 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'

I've always assumed this was to maintain syntactic consistency with comprehensions like [x for x in arr if x > 2].
Python is a multi-paradigm language, of which OO is one paradigm it supports.
Ruby 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?
Not 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.
Ruby is a strongly OO language, which arguably also has better support for functional programming than Python.
Yes, that's the Zen of Ruby and why I love it.
Python, 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.

Which is ironic, given that "There should be one-- and preferably only one --obvious way to do it" is in PEP 20.
I agree. This has always driven me crazy. Python is supposed to be “there’s one way to do it” but I find it quite inconsistent!
The vast majority of Python code that I have had to interact with professionally seems to ignore the fact that PEP even exists.
How 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.
You're splitting hairs about what the op said. How about len() ?
[1,2,3].__len__()
Yes, Python is all OO under the hood just like Ruby but ugly as sin.