DEV Community 👩‍💻👨‍💻

Discussion on: The Power of Variable Names

Collapse
 
adillaumam profile image
Ahmad Adillaumam Author • Edited on

Wow, thanks for the advice and additional knowledge. I need to learn more. After I reread it, I realized I was careless with lots of typos and wrong implementation. Thank you for being reminded. I have very little experience so I am very grateful to be able to listen to experienced people. Thank you so much for taking the time 🙏

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 Author

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