On Tue, Jun 29, 2010 at 2:37 PM, Matt Grimm <matt.t.gr...@gmail.com> wrote:
> For example, I have a logger class wrapped around Log4perl that
> supports screen, email, and syslog appenders, and each appender can be
> individually toggled on or off. Is it better to force the dependencies
> on the underlying syslog and email modules at the top of the logger
> class, or is it acceptable to bury those imports in the methods that
> actually do the initialization of each appender? It sort of comes down
> to whether I want the issue detected at compile time or run time I
> suppose, but is generally frowned upon to put imports down inside
> class methods?

I tend to think about it like this:

(a) Mandatory for operation?  Load it at compile time.  (And list it
as a prerequisite in Makefile.PL/Build.PL)

(b) Optional and almost always loaded in normal operation?  Load it at
compile time.  Even if there possible fallbacks, get it out of the way
at compile time.

(c) Optional and only needed some of the time?  Load it at runtime
if/when needed.

-- David

Reply via email to