When reading such concise code you must always remember that it is very compressed and says a lot in a few words. So it is really the information density that is disturbing the newcomer, not the legibility.
If the same code was expanded to 50 lines of Java code, then yes, each individual line of code would be easier to comprehend, but that would only give you a false sense of productivity because you'd be spending more total time to comprehend all the lines, and then even more time to grasp the function as a whole. The human short-term memory is very limited and Java-like syntax stresses it a great deal more than concise FP-like syntax. -marko On Thursday, April 11, 2013 2:12:37 AM UTC+2, Sean Corfield wrote: > > I think I would have found it pretty hard to comprehend when I first > started doing Clojure three years ago (eek - time flies!) but it made > sense reading it today and it is pretty elegant. It certainly helps to > know the rules of Conway's "Life"... I'm not sure I'd inflict this on > my team members yet, as they are newer to Clojure, but I don't think > it's particularly unreadable or complicated either. It's certainly the > sort of thing you have to get used to with Clojure (and Lisp in > general)... > > Sean > > On Wed, Apr 10, 2013 at 11:34 AM, Alex Baranosky > <alexander...@gmail.com <javascript:>> wrote: > > IMO, t the end of the day, if the code isn't immediately readable (for > other > > people on your team, which means what I'm saying is context dependent), > then > > it needs to be made clearer. That is *always* going to be a value > > judgement. But I've heard the same comment about that particular Game > of > > Life implementation enough times to suspect it is not immediately > readable > > to a lot of people. > > > > > > On Wed, Apr 10, 2013 at 11:29 AM, Mark <mjt...@gmail.com <javascript:>> > wrote: > >> > >> I agree that this seems a bit terse and magical. However, there are a > >> couple of mitigating factors to consider. > >> > >> 1. frequencies is a Clojure core function. It's simple enough to > >> understand on its own, but if you haven't encountered it, you'd need to > look > >> it up to be sure what it's returning. Someone who's seen a lot of > Clojure > >> code has probably already encountered it. > >> 2. mapcat is a classical LISP function. The name is retroactively > obvious, > >> but if you haven't seen it, it does a lot of stuff at once. > >> 3. The rest of this function is basically a sequence comprehension, > which > >> is idiomatic in Clojure. > >> 4. The example you have chosen isn't the final version. You have > selected > >> a partial solution and are presenting it as a straw man. Those bare > >> constants go away on the next page. > >> > >> If I were writing this code, I might break down the long line a bit - > the > >> mapcat and frequencies calls could be placed into a let binding and > given > >> meaningful names, which would aid somewhat. Apart from that, you're > >> contending with the fact that Clojure (and LISPs) is (are) wide, > shallow > >> languages. You have lots and lots of little functions that make it up. > >> Without knowing what these do, the whole language can seem > impenetrable. > >> > >> > >> On Wednesday, April 10, 2013 1:27:58 PM UTC-4, edw...@kenworthy.info > >> wrote: > >>> > >>> 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 clo...@googlegroups.com<javascript:> > >> Note that posts from new members are moderated - please be patient with > >> your first post. > >> To unsubscribe from this group, send email to > >> clojure+u...@googlegroups.com <javascript:> > >> 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+u...@googlegroups.com <javascript:>. > >> For more options, visit https://groups.google.com/groups/opt_out. > >> > >> > > > > > > -- > > -- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clo...@googlegroups.com<javascript:> > > Note that posts from new members are moderated - please be patient with > your > > first post. > > To unsubscribe from this group, send email to > > clojure+u...@googlegroups.com <javascript:> > > 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+u...@googlegroups.com <javascript:>. > > For more options, visit https://groups.google.com/groups/opt_out. > > > > > > > > -- > Sean A Corfield -- (904) 302-SEAN > An Architect's View -- http://corfield.org/ > World Singles, LLC. -- http://worldsingles.com/ > > "Perfection is the enemy of the good." > -- Gustave Flaubert, French realist novelist (1821-1880) > -- -- 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.