The Single Most Important Bit of Software Engineering Advice

schwern on 2005-04-17T23:17:02

Make your globals and your locals look different.

I don't care if its $Global and $local or $GLOBAL or $GLOBAL{var} or $_local or whatever. Just make sure that when I'm reading an arbitrary hunk of your code I can tell what's global and what's not just be looking at the variable name. This is the single simplest way to avoid basic scope creep and its also the most often violated. I'm reworking some JavaScript code which as a handful of globals and they all have names like "current_image" or "state"... and so do the lexicals.

What's a global? Anything that exists across more than one subroutine. So yes, "file scoped lexicals" are global. What's local? Anything that exists in only one subroutine.