|
|
|
|
|
by strictfp
3991 days ago
|
|
Coding Pro Tip: Instead of using the Singleton pattern, make one instance of your class at the start of your program and pass it around to its users. Singletons are really just as bad as global variables. Why? Because they are global variables. |
|
One could argue that you could just create it in the section of code you want to log - but that just creates noise and you end up repeating code.
logger = Log() # run code to open the file to the last position logger.log("test")
vs
Log.instance().log("test")
Now imagine this was a multi-threaded application - singleton arguments are much different.
> Singletons are really just as bad as global variables. Why? Because they are global variables.
Everyone has their own opinions - but you can't make sweeping generalizations. I'm not saying a global variable is appropriate in every situation - but every language, and project, is different. There are even different dialects of C++ [2].
[1] - http://stackoverflow.com/questions/228164/on-design-patterns...
[2] - http://www.reddit.com/r/programming/comments/197dn1/introduc...