icyflame / cli-cube-timer

Time your solves, without leaving the terminal
https://npmjs.org/package/cli-cube-timer
20 stars 5 forks source link

Use "_" as prefix for all global variables and do not pass them around as function arguments #45

Open icyflame opened 6 years ago

Saurabh3333 commented 6 years ago

do not pass them around as function arguments means we can't use global variables as arguments?

icyflame commented 6 years ago

@Saurabh3333 Yes.

Saurabh3333 commented 6 years ago

Sir, what is the problem with passing the global variables as function arguments?

icyflame commented 6 years ago

@Saurabh3333 it's not a good practice. Global variables are available everywhere in JavaScript, they needn't be passed around as function arguments. It also makes following the code harder for anyone who hasn't worked with JavaScript before. Questions like "If the variable is available everywhere, why is it being passed as a function argument? Is there some reason I am missing?"

It's messy, of course. I shouldn't have used global variables in the beginning, when I was designing this module. I ended up using them. So, I think the second best option, after completely refactoring index.js, is to embrace the fact that index.js has global variables!