Hacker News new | ask | show | jobs
by ubernostrum 4862 days ago
Not bad, but the big weakness is that the author seems to be very familiar with more expert-level aspects of Ruby, but not so much with Python. And turns that into "Python doesn't have these".

For example, he mentions Python doesn't have an equivalent of method_missing -- it's technically true that there's nothing you define on a Python class to specifically intercept a nonexistent method, but that's because Python's standard facility for this operates more generally at the level of attribute access. Suspect there's a bit too much expectation of Python to be message-passing like Ruby in not seeing that one.

Similarly, Python has plenty of metaprogramming features, they're just implemented differently -- and from a different conceptual standpoint -- than Ruby's. And so on and so forth.

1 comments

There are also a few non-idiomatic practices he seems to favor. For example, he seems to advocate use of `filter`, `map`, `reduce` in a few places, which, in Python, are better expressed with list comprehensions, combined with builtins like `sorted`, `all`, `any`, `sum`, etc. Adding the `operator` module opens up even more functional constructs without ever touching `map`, `reduce`, or `filter`.
Using list comprehensions as a replacement for filter and map I can see. I don't really see where you're getting at as far as substitutes for 'reduce' are concerned. For me, the 'operator' module is a justification for using 'reduce', not a replacement for it.
> I don't really see where you're getting at as far as substitutes for 'reduce' are concerned.

Reduce simply isn't used much in Python code, as a product of both culture and rather lacking lambdas. It's used so little (pretty much the only "usual use case" is covered by `sum`) it's been moved out of the builtins and to the functools module in Python 3 (whereas `map` and `filter` have remained)

Thank you, that was much more eloquently put than I could have provided. Indeed, `sum` was the one common use case I could think of, so I didn't bother including it as an example. I honestly can't say I miss `reduce` at all when writing python.
> Indeed, `sum` was the one common use case I could think of

There are 4 other not-completely-uncommon cases in the builtins, implemented in a significantly more efficient manner for the latter 2 (ignoring Python v C): min, max, any and all. And map and filter technically but repeatedly concatenating lists together (in python) isn't the most useful way to peg your CPU.