code-reviews 2020-09-10

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.

that’s what we do here 😄

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

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

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

loop/recur , reduce , iterate

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

Thanks guys, ill change what was mentioned.

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

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.

@lucio has joined the channel

@jsyrjala has joined the channel

@oscarlinusericsson has joined the channel