|go ahead... be a heretic|
Global or not globalby McA (Priest)
|on Jul 03, 2012 at 05:28 UTC||Need Help??|
I want to ask you for your opinion to the following general problem:
Function a uses b and b has to use c. That means you have to insert dbhandle in the function signature of b even if b doesn't need it by itself.
So, as more or less the whole application needs the database it happens that more or less all functions need a dbhandle. That means that the signature of more or less any function does have the dbhandle parameter.
Is this the right way to do this? Or would it be better to implement the functions the way that they can "grab" the dbhandle from somewhere (singleton = global variable)? When you add other things to the example above, e.g. a logging object, than the function signatures are growing with elements which you can find in more or less any function. (Logging is IMHO a much better example of an item you need everywhere, but logging is not a requirement to solve the initial business requirement. Log::Log4perl solves this elegantly by providing a singleton. So you can add logging whereever you want simply by calling get_logger).
Advices and ideas welcome.Best regards