Friday, 20 June 2008

Do you know why globals are bad?

Some people just spout that globals are bad. They don't know why they say it. They say it the same way they say that gotos are bad.

my reasons for not enjoying globals:
* Globals are inherently dangerous because they imply temporal coupling.
* Globals are accessable everywhere and therefore restrict encapsulation

Temporal coupling is bad because you have to keep remembering in what order to set variables or call functions otherwise things go wrong.
Encapsulation is good because it reduces the number of access paths and therefore possible damage routes.

Just these two things make a massive difference.

No comments: