Andrea Koutifaris
2 min readApr 6, 2021

--

Your calcWinner takes almost double the time than the other one.

For 100.000 iterations in my computer:

- calcWinnder (yours) 95 chrome, 261 FF

- calculateWinner: (react version) 53 ms Chrome, 152 FF.

In a normal Tic Tac Toe the winner calculation time is not so important, but if you add an AI and extends the game to a NxM board, than the winner calculation time becomes very important. That said I used this performance to falsify some of your assertions.

I commented out the side effect // else nextPlayer();, because I shouldn't count that in the performances test.

Your version: https://codepen.io/koutifaris/pen/YzNxeKR

React version:

https://codepen.io/koutifaris/pen/bGgrLdd?editors=0010

I profoundly dislike how you write your code. It took me more than 10 minutes to understand your version, compared to the react one which took me a few minutes. Also everything is mixed up with side effects. I guess your definition of open/close principle is: open to find/replace, closed to criticism.

But that is just my personal opinion. So I will focus on a few points about Tic Tac Toe.

"1) I don’t have “lines” stored inside it where it adds execution and memory overhead that even “const” doesn’t fix."

Yes, you use global memory instead, retaining it even when not necessary. Not that it is a mistake, but neither the react version is. BUT your version is considerably slower, so that "overhead" is your in your head...

"2) By comparing to player I'm able to implement simpler checks with faster loop abortion."

Your version is just slower. Those "simpler checks" words are just meaningless.

"3) By using for/of instead of the old-school loop, I can do my destructuring in the loop. Also doesn’t help that they use const there which if they were REAL constants would break the execution loop."

Either you do not understand const keyword in JS (which of course is not the same of that of C++) or you cannot avoid to throw random words in your sentences.

--

--

Andrea Koutifaris
Andrea Koutifaris

Responses (1)