I hardly ever use a module if I'm not wanting to import() from it. Using require at the top of a script or module is not the same as using require from inside some rarely used function. If I use require at the top of a script or module, then the lack of the module will still cause my script to fail "immediately" and before the script "runs", so I see no advantage to avoiding require in favor or always useing.

I prefer to require modules when it suffices because it makes it clear that the module is not importing anything and is not making compile-time changes that impact the compilation of the rest of the code.

I also rarely use a module without giving a specific list of arguments to pass to its import() function. Implicit imports are the enemy of clarity.

- tye        


In reply to Re: Use and Require - making an informed choice. (require++) by tye
in thread Use and Require - making an informed choice. by g0n

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.