Tuesday, May 31, 2011

Never use global variables (or at least try very hard not to)

I'm coding in C++, I decided to use global variables to save memory since I'm expecting millions of events, I figured I could save about 16 bytes per event (4 pointers). But I'm now realizing that was a stupid idea. So not to self, never use global variables, unless constants.

Most importantly, it makes your code extremely hard to unit test. So DON'T DO IT.

No comments:

Post a Comment