3 ms·
I think this is a little bit disingenuous. The Clojure syntax used for the operation was the cleanest possible, whereas the syntax used in the other languages w
by johnloeber 11y ago
I think this is a little bit disingenuous. The Clojure syntax used for the operation was the cleanest possible, whereas the syntax used in the other languages was not. Here's the Python example:
> [sum(t) for t in zip(a, b)]
It's clear that this alternate version is easier to understand:
> [x+y for (x,y) in zip(a,b)]
Beyond that, of course functional languages like Clojure lend themselves to creating "small, nice things." That's why functional languages like Racket/Scheme are often used to teach introductory CS courses: they're not too hard to read, and lend themselves nicely to explaining basic concepts, while not burdening the user with enormously complicated syntax. However, this can change depending on the context. I think it would be fair of the author to bring up scaling difficulties of Clojure: conventions for "small, nice things" occasionally produce really ugly abstractions at scale.
- deleted 11y ago[deleted]
- bpicolo 11y agomap(sum, zip(a, b)) scales as well as Clojure here, though not identically concise
- johnloeber 11y agoOh, that's really elegant. Nicely done.
- Scarbutt 11y agoI'm not a regular python user but the article did mention that map is somehow not pythonic.
- masklinn 11y agoYup apparently an earlier version of the article used `map` and someone complained that it's not pythonic. `map` using a lambda may be undesirable compared to a listcomp, but if you already have a function doing exactly what you want it's perfectly fine. Though in this case a better (existing) function is `operator.add`.
- bpicolo 11y agooperator.add doesn't scale to n lists. Would be weird in this case as well. You'd need: map(lambda x: operator.add(*x), zip(x, y)) map might not be `pythonic` but I typically pull out map/reduce/filter for the trivial cases. filter(bool, list_) is just as understandable as [i for i in list_ if i]
- tomjakubowski 11y agoAlso disingenuous is the suggestion that you need to explain function invocation in Python, but not in Clojure. Maybe that falls under the umbrella of explaining s-expressions, but I don't think there's a notion of "function invocation" in s-exprs (only in language which use s-exprs as their syntax). Strange, too, that infix notation (familiar to anyone who's taken arithmetic) needs explanation in Scala and Ruby, but prefix notation gets a pass in Clojure.
- laughinghan 11y agoTo be fair, prefix notation got a pass in all languages.