Quote:Original post by Mathematix
Notice that I said "This appears to be the best option for what you want to do", which is not the same as it being good code practice.
If it's not good coding practice, it's not very likely to be the "best" option now is it? After all, good coding practice is all about solving problems in a best manner possible.
Quote:Quote:Original post by MaulingMonkey
1) Global pointers can be just as NULL as function argument pointers, so your proposal dosn't solve the problem you described.
Of couse, and I didn't imply otherwise. The point of making it global is that you will create an instance in one place and destroy the instance at anopther single place in the code.
You haven't pointed out why it wouldn't solve the problem!
You stated the problem, as mikeman points out, as being a hard to find bug (lies - use a debugger) deriving from the possibility of the pointer being NULL. As I just said, global pointers suffer this exact same possibility. As such, your "solution" does nothing to alieviate the indicated problem. Is that explicit enough?
Quote:Quote:Original post by MaulingMonkey
2) Global pointers can be modified from ANYWHERE, and as such, it can be harder to figure out what, for example, might be modifying the pointer in question to become NULL in the first place, so it adds to the problem you described.
What?! If you point to the global, as I was trying to get across, then make sure that you're not pointing to it again when leaving the function, why should that be a problem?
At this point, I'm lost as to what you're trying to describe. Post some code to illustrate what you mean? Did you mean "pointer-to-global" instead of "global pointer" perchance?
Quote:Quote:Original post by MaulingMonkey
3) That's not going to work if there's more than one SomeClass.
You're pointing out a problem that was not described, in that multiple instances of SomeClass are required.
What wasn't described is a situation where multiple instance of SomeClass are not required. Given that we're dealing with abstracts such as SomeClass, Foo, Bar, etc - it'd be insane not to think we need to address the general case - which, if the standard library is any judgement, consisting 99%+ of classes that are not limited to one instance - would seem to be "any number of instances" rather than "one, only one, and nothing more than one instance".
Quote:Quote:Original post by MaulingMonkey
4) Oh HELL no.
Globals aren't necessarily a bad thing, and are used in production code when justified. What makes them appear bad is poor implementations elsewhere in the code. :)
When justified. Justification that seems to be lacking, in this case. The entire proposal makes me go "What? Why? You want to add a bunch of assumptions to our code (specific global variables instead of any old variable the client wants to pass along as an argument), and the only apparent justification falls completely flat (that it somehow magically makes it unable to be NULL, less likely to be NULL, or anything else along those lines).
Hence the reaction. Adding globals without answering the "why".
Here's a good why: My program depends on this logger in multiple places throughout the code, and will not need multiple loggers in this architecture's forseeable future (it's a prototype or the program will need a full rehaul of architecture anyways if our original requirements have changed that drastically). As such, the simplicity of a global over dependancy injection (or alternative method) outweighs the risk of having to recode that assumption.