On Mon, Dec 29, 2008 at 3:10 PM, Chouser <chou...@gmail.com> wrote: > > On Mon, Dec 29, 2008 at 3:40 PM, Mark Volkmann > <r.mark.volkm...@gmail.com> wrote: >> >> On Mon, Dec 29, 2008 at 2:24 PM, Brian Doyle <brianpdo...@gmail.com> wrote: >>> Looking at this code the uppercase variables stands out. >>> This isn't idiomatic is it? >>> >>> (def GRID_SIZE 10) >>> (def HEIGHT 600) >>> (def MARGIN 50) >> >> I don't know. > > I believe the idiom for global values like this is to place asterisks > around the name. Underscores (and CamelCase) should only be used when > required for Java interop: > > (def *grid-size* 10) > (def *height* 600) > (def *margin* 50) > (def *x-index* 0) > (def *y-index* 1)
I think that's supposed to be + instead of *, at least Common Lisp seems to use +. > On a more general point, I'd personally recommend being wary of > over-investing in comments. This is not a radical recommendation, but > I'll bring up again anyway that thought that it's better to write code > in such a way that it explains itself than to add comments to code > that doesn't. Only when the former is insufficient should more > comments be added. I agree completely! In some programming languages, for example Smalltalk, I feel like I can almost always write the code in a way that doesn't require comments. However, I don't feel able to do that as often in Clojure. I think it's because you can do so much with so little code in Clojure. For example, here's some code that I don't know how to rewrite in a way that I find self-explanatory: (every? #(<= (- (apple %) +grid-size+) (head %) (+ (apple %) +grid-size+)) [+x-index+ +y-index+])) And here's another one: (assoc snake :body (cons (vec (map #(+ (dir %) ((first body) %)) [+x-index+ +y-index+])) (if grow body (butlast body))))) Perhaps using your suggestion to go back and use a map with :x and :y keys instead of a two-element vector to represent x/y coordinates would help a little, but I'm still not sure the code would be immediately obvious. Maybe it's just a matter of time before I'm good enough at reading Clojure code that I won't feel the need to add comments to these. Even if that happens though, I'll still be concerned about the ability of other developers that haven't yet reached that level of proficiency to understand my code. -- R. Mark Volkmann Object Computing, Inc. --~--~---------~--~----~------------~-------~--~----~ 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 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 -~----------~----~----~----~------~----~------~--~---