"polluting the global namespace" means "creating unnecessary global variables"
The "pollution" here is similar to
satellite polution; the more satellites and debris you put in orbit, the more probable a satellite clash is.
Global variables are similar; The more global variables you use, the more possible is that two of those share the same name - one will override the other, and you will have a problem.
In some cases they are easy to find. If you have two "rectangle" global variables, probably one of them will throw an error when it gets passed the wrong type of parameters.
But it's not always so evident. Global clashes can be very subtle and take months to find. I have had that issue myself.
I experienced this issue not long ago, in LÖVE 0.6.x, when I created a global function called "debug". On that time, LÖVE itself was using that same global variable for handling error output, so I had in fact disabled error logs. Since I did not have an error immediately, I didn't notice the change. Then I got some crashes, but I didn't notice that the error logs where not appearing because the errors where quite obvious. And then, one month later, I really needed error reports and I discovered that I didn't have any. I spent 2 months without error reports, until I opened an issue on the tracker and the devs helped me.
Putting your variables inside namespaces (mypackage.myvar instead of a global myvar) and using local variables are good practices that prevent this kind of issue.
If you are making a library for others to use, it's specially important to limit the global namespace pollution, since you don't know what others will be using as global variables. If you can, use 0 variables (you can just return a table on the require).
I must also point out that, for the shake of efficiency, local variables are slightly faster than global ones. So this:
Code: Select all
rectangle = love.graphics.rectangle
is a bit slower than this:
Code: Select all
local rectangle = love.graphics.rectangle
In addition of being faster, the local variable is also a bit less "polluting", since it's global inside the file/scope where it's defined, but invisible outside. Its downside is that it must be declared on each file.