On Fri, May 13, 2011 at 12:29 AM, Gregg Williams <greg...@innerpaths.net> wrote:
> This is good advice, but I can't parse 1a after the phrase "or maybe",
> and I'm not sure about 1b. Can you reword them, making it clearer when
> you're using a Clojure keyword? I want to be sure I understand what
> you're saying--it sounds insightful! Thanks.

OK --

1. Think functional. Try to express as much as possible as "data
plumbing": here is an input, here is the desired result, how to get
there from here? Think in terms of calculating a new value in terms of
an existing one, rather than changing things in place. Familiarize
yourself with "map", "filter", "remove", "reduce", "iterate", and
"friends", and the data structures (maps, sets, vectors, and seqs) and
use those to represent as much as possible and to do as much as
possible. In particular, when a processing step has to be repeated:

1a. If it's for each element of a sequence, consider "map", "reduce",
and "for". If it has to walk several sequences in tandem, use "map",
or maybe "reduce" or "for" with (map vector s1 s2 ...) as the input.
If it's for each combination in some sequences, so for all in the
first sequence, and for each of those for all in the second, etc., use
"for".

1b. If it's accumulating a result, consider "reduce", even if the
input isn't (obviously) a sequence, or "iterate", before resorting to
"loop"/"recur".

2. When the time comes to abstract things, abstract as much as you can
using functions as arguments and, perhaps, as return values and using
maps before resorting to "defmulti"/"defrecord"/etc.

3. Look at other Clojure code, including what shows up here from time
to time, and ask here about making specific code more idiomatic. Many
people here will likely answer fairly quickly, and even when they
disagree, the disagreement and their stated reasons for disagreeing
may themselves be illuminating -- and then anything *everyone* agrees
is ugly or poor practice almost certainly is. :)

That better? I made a few other tweaks as well as quoting all the
names of core functions and macros I was referring to.

-- 
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

Reply via email to