Really? You may of course be right; but double-checking [1], I see: * it removed the "couple of magic numbers", the original post's most substantive technical criticism
* it has a much larger and better docstring I don't want to come across as zealot-y (who likes that?); it's just my opinion and could be wrong! Just seemed that the first example wouldn't pass tech review unscathed; but when I dug deeper into the context, I found the second and it seemed that would reasonably pass. To Devil's Advocate myself, there are critiques I personally see: * Maybe "cells" is better named "living-cells", or documented as such? * "cells" starts off being the subject... but each neighbor becomes the subject. There is a cleverness in this. Maybe a brief comment would be apropos. * mapcat and frequencies are fairly uncommon to use But to Devil's Advocate my Devil's Advocate, it's in a book which explains these things. So the impact of the cleverness or suboptimal naming is a bit diminished. Maybe the authors didn't want to belabor the point, due to the sharp edge between being explanatory and plodding. And I actually have used mapcat and even frequencies, in my tiny helper scripts before I started using Clojure for production. YMMV! All the best, Tj [1] https://github.com/clojurebook/ClojureProgramming/blob/7521bcfb52cdf7e598bca3c4e7860d795a67992c/ch03-game-of-life/src/com/clojurebook/collections/life.clj#L122 On Monday, April 15, 2013 8:40:58 AM UTC+2, edw...@kenworthy.info wrote: > > I'm sorry but that's not true. The version over the page hasn't been > re-factored 'into a nicer version' it's been re-factored into a more > generic version to support, for example, hexagonal grids. > > On Saturday, 13 April 2013 23:12:59 UTC+1, Tj Gabbour wrote: >> >> Hi, >> >> The text explains the "elegant" aspects of it; and then in the next page, >> they refactor it into a nicer version which was 40% docstring. [1] >> >> So this is like critiquing the readability of someone's first draft. :) >> >> >> All the best, >> Tj >> >> [1] >> https://github.com/clojurebook/ClojureProgramming/blob/7521bcfb52cdf7e598bca3c4e7860d795a67992c/ch03-game-of-life/src/com/clojurebook/collections/life.clj#L122 >> >> >> On Wednesday, April 10, 2013 7:27:58 PM UTC+2, edw...@kenworthy.infowrote: >>> >>> So, page 143 of Clojure Programming has an implementation of Conway's >>> Life: >>> >>> (defn step >>> "Yields the next state of the world" >>> [cells] >>> (set (for [[loc n] (frequencies (mapcat neighbours cells)) >>> >>> :when (or (= n 3) (and (= n 2) (cells loc)))] >>> >>> loc))) >>> >>> The book claims this to be "an elegant implementation'. >>> >>> Now it's been a long while since I wrote code to put food on the table - >>> but back then if I saw C or C++ code written like this I would describe it >>> as obfuscated - the sort of thing I would expect to see in the (now >>> defunct?) annual obfuscated C competition. It's concise and rather clever, >>> certainly, but hardly self-documenting: it's not very clear what it's doing >>> at all- with a couple of magic numbers thrown in for good measure. Rather >>> arcane in fact. >>> >>> Is it just me? Is this considered to be good Clojure code and I'm just >>> hopelessly out of touch and need to get with the programme? >>> >>> >>> >>> >>> -- -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.