Fork me on GitHub
#code-reviews
<
2020-09-10
>
fullNameHere18:09:44

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.

potetm18:09:48

that’s what we do here 😄

fullNameHere18:09:08

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

potetm18:09:40

link to github?

fullNameHere19:09:52

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

phronmophobic19:09:23

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

potetm19:09:28

lots o’ ways!

potetm19:09:19

loop/recur , reduce , iterate

potetm19:09:32

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

fullNameHere19:09:01

Thanks guys, ill change what was mentioned.

practicalli-johnny13:09:32

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

fullNameHere14:09:14

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.