Quote:Original post by Antheus
Ever tried unit testing a database application where you need to test DROP statement? In common design where database access is singleton or global hard-coded, accidentally running such test without changing the configuration will wipe the production system. So how do you test it automatically?
Much easier if systems are not coupled.
QFT.
not exactly a DROP statement, but in general. once it's a hot database, with money-data in, and all, and you have to test stuff around, have fun if you can't just switch the database easily. i first had, in all my apps, a singleton connection (just so damn easy in .net). i learned the quite hard way (no dataloss in the end in the database) that this isn't how it should go :)
singletons are just bad. everyone who doesn't understand this still has to learn a lot in clean, save, proper programming.
i do use globals sometimes. i do use global functions sometimes. but never singletons.
edit:
i have found quite some places where globals can be handy (in small scale apps, that is). i never found one point, where a singleton has any gain over a global. if i thought it may be that way, taking the global away and making it a locally pass-around object was always simpler to implement, less to think about, and then, 100% working and debuggable and testable.