4 ms·
> const move = (value, i, j){...} > This function makes a move in the game, it takes 'x' or 'o' along with 2 integer coordinates. It will mutate all the state
by ppeetteerr 7y ago
> const move = (value, i, j){...}
> This function makes a move in the game, it takes 'x' or 'o' along with 2 integer coordinates. It will mutate all the state variables to reflect the new state of the game. After that, it calls renderNoughts(), this is a call to rerender the game - but we'll come back to that.
Dear programmers, not related to the actual article but, when you have to describe your function with a paragraph of text, please consider improving the naming of your function and its parameters.
- bigmanwalter 7y agoIt seems perfectly well named to me! I love when code bases have more lines of comments than actual code.
- ricardobeat 7y agoSometimes the comments are only required because the code is confusing. In this case the function both mutates the state, and renders the app. If using a framework like React/Vue etc it might make perfect sense to call this function `move`, but here it has a lot more responsibility and would need a more representative name like update/setState/renderApp/etc. But I think it's pointless to debate as it breaks the single-responsibility principle and you're unlikely to find something like this in a large scale app anyway.
- bigmanwalter 7y agoIt could also be because the code is terse. In that case it makes sense to explain what's going on.