code-reviews

2020-09-10T18:53:44.063Z

Anyone willing to do a code review. Its about 130 lines of code. Ive just recently started learning clojure so im probably doing a lot of things not the right way.

2020-09-10T18:55:48.063300Z

that’s what we do here 😄

2020-09-10T18:57:08.064Z

True, I didnt want to copy and paste the whole thing here

2020-09-10T18:57:40.064200Z

link to github?

practicalli-john 2020-09-17T13:56:32.074900Z

@santosx99xx There is a nice example of tic-tac-toe with Clojure in this video http://practicalli.github.io/clojure/games/tictactoe-cli/ There is also another approach using ClojureScript and SVG graphics https://practicalli.github.io/clojurescript/reagent-projects/tic-tac-toe/index.html Hope you find these of interest.

2020-09-17T14:56:14.075100Z

Ive actually got it to pass state around, im just ironing out some bugs. Ill still take a look at yours to see how you did though.

2020-09-10T18:58:52.064700Z

https://github.com/SantoHerrera/clojuretictac Thanks man, I really appreciate it.

2020-09-10T19:16:52.065300Z

What are some ways to avoid atoms? I'm not sure how.

phronmophobic 2020-09-10T19:18:23.065500Z

some thoughts in no particular order: • clojure doesn't automatically apply tail recursion. I would explicitly use loop/recur for the game loop • I would make exitGame? a pure function and not have it actually shut down the VM • rather than updating state in a function call, I would make the state transition as an explicit step in the game loop. also, I would make the next value of the game a pure function of the previous value + input. maybe something like

(loop [game (new-game)]
  (print-board game)
  (let [action (read-action)]
    (if (exitGame? action)
      (get-winner game)
      (recur (update-game game action)))))
• get input should return a valid input and do nothing else

2020-09-10T19:18:28.065700Z

lots o’ ways!

2020-09-10T19:19:19.066Z

loop/recur , reduce , iterate

2020-09-10T19:20:32.066300Z

I would opt for something like what @smith.adriane did in this case though.

2020-09-10T19:22:01.066800Z

Thanks guys, ill change what was mentioned.