On Sep 13, 2:43 am, jng27 <jgran...@gmail.com> wrote: > http://jng.imagine27.com/articles/2009-09-12-122605_pong_in_clojure.html
Neat. I have some suggestions though. 1) I think you use too many refs. the sx, sy, etc. could all be replaced with a simple (defstruct position :x :y) (def whatever (ref (struct position nil nil)) It's less granular, but much easier Also, do the *w and *h refs don't seem to change after the game starts, so refs are overkill for them. You could at least make them atoms, though if possible using just regular defs and (binding [...]) or maybe even alter-var-root! would be cleaner (no need to explicitly deref vars). 2) write specialised functions for updating the positions, and use alter instead of ref-set. eg. instead of (ref-set bx (+ @bx @sx)) (ref-set by (+ @by @sy)) you could have something like (alter (partial merge-with +) b-pos @s-pos) 3) Split up the actionPerformed for the pong-frame. it's way too big. The best way to split it would be to try to move as much of the actual logic into pure functions and just altering your refs using those functions. Separating the dosync logic (dealing with refs) from the actual game logic (calculating the new values from the old ones) makes the code much more understandable. 4) Prefer (.foo bar) and (Foo/bar) to (. foo bar) (this is my personal recommendation) -- Jarkko --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---