|
|
|
|
|
by nilved
4360 days ago
|
|
Even with named functions, Python's use of global functions instead of methods for iterators force you to read the expression from the inside out. I think Lisp languages nailed this with their threading macros, which allow natural left-to-right reading, but Ruby's strategy is better than Python's, too, while maintaining very similar syntax. ;; clojure
(let [begins-with-a #(.startsWith % "a")
foo #(do-some-stuff-with %)]
(-> words (filter begins-with-a) (map foo))))
# ruby
words.filter { |e| e.start_with?(?a) }.map { |e| foo(e) }
It doesn't really make sense for things like `len` and `map` to be global functions in object-oriented languages. |
|