DEV Community

Discussion on: The Power of Variable Names

Collapse
 
joolsmcfly profile image
Julien Dephix

Glad I can be of any help.

Good variable names is one thing but it's just one step.
If I take your example:

function getFlaggedCells() {
    let flaggedCells = [];
    for (let cell in gameBoard) {
        if (cell[STATUS_VALUE] == FLAGGED)
            flaggedCells.add(cell);
    }
    return flaggedCells;
}
Enter fullscreen mode Exit fullscreen mode

It's more readable but

  1. it's not a pure function since gameBoard is defined outside of the function.
  2. it can be refactored in a more functional way
function getFlaggedCells(gameBoard) {
    return gameBoard.filter(cell => cell[STATUS_VALUE] === FLAGGED)
}
Enter fullscreen mode Exit fullscreen mode

I find it more readable.

Thread Thread
 
adillaumam profile image
Ahmad Adillaumam

Again, I really learned a lot from you, but here I can only say thank you very much to you and thank you for creating this discussion.

Thread Thread
 
joolsmcfly profile image
Julien Dephix

ha no problems. Keep on writing, it opens up discussions. 👌