WTH ? I strongly believe this promotes stupidity amongst programmers. It's verry natural for a function to be able to access global variables, both for read and write operations. It's your job as a programmer to fully understand the function you're trying to change, which variables are local and which are global. Not to mention that you could have naming convensions like "all global variables start with g_". And on top of that, it's a good practice to comment your code, for both you and others. Simply placing a comment like "// here we set value X in global variable Y" makes things crystal clear.
If we would use each variable only once, we would need to work with far more variables and our code would be alot bigger and alot messier. Not to mention we would increase memory size.
A simple example i can think of, often found in my codes, is something like this (pseudocode here, i work mostly in PHP):
Basically, if i would need 5 different queries, returning large amounts of data, but i only need that data for a verry short amount of time, why on earth would i want to create separate variables to load my memory more than needed ?
Optimization can often lead to code that is harder to read, test and maintain. You are right saying that is the task of an programmer to understand the code. But I would not like to work in such code. Moreover in times of huge in-memory-databases, memory is not as expensive as programmers maintaining and extending the code.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
WTH ? I strongly believe this promotes stupidity amongst programmers. It's verry natural for a function to be able to access global variables, both for read and write operations. It's your job as a programmer to fully understand the function you're trying to change, which variables are local and which are global. Not to mention that you could have naming convensions like "all global variables start with g_". And on top of that, it's a good practice to comment your code, for both you and others. Simply placing a comment like "// here we set value X in global variable Y" makes things crystal clear.
If we would use each variable only once, we would need to work with far more variables and our code would be alot bigger and alot messier. Not to mention we would increase memory size.
A simple example i can think of, often found in my codes, is something like this (pseudocode here, i work mostly in PHP):
Basically, if i would need 5 different queries, returning large amounts of data, but i only need that data for a verry short amount of time, why on earth would i want to create separate variables to load my memory more than needed ?
Optimization can often lead to code that is harder to read, test and maintain. You are right saying that is the task of an programmer to understand the code. But I would not like to work in such code. Moreover in times of huge in-memory-databases, memory is not as expensive as programmers maintaining and extending the code.