in reply to Re^3: Directory creation with current Date
in thread Directory creation with current Date

Why do you want to avoid POSIX?

I know it's in the standard distribution and I'm sure loading it will not be significant at all but ... if it's not *really* needed, well, it's just one less module to load :)

  • Comment on Re^4: Directory creation with current Date

Replies are listed 'Best First'.
Re^5: Directory creation with current Date
by demerphq (Chancellor) on Jan 19, 2005 at 21:20 UTC

    Well, not that you probably care but I certainly consider that a form of premature optimization. If you are sure that POSIX will cause you issues then I could understand it, absent such evidence its just bad practice. For one, the code you write is less likely to be correct than the code in POSIX, for two if you use a nontrivial selection of modules the likely that POSIX gets loaded anyway is pretty high. So you increase code bloat, probably reduce your run times (I admit I havent benchmarked), increase your chance for error, all for a gain that may not even occur at all. Doesnt sound like good practice to me.

    ---
    demerphq

      Hello,

      Well, I do care, since this is a question that arises a lot at work, that is: module load times. From previous discussions i gathered that modules take almost zero time to load, especially compared to system calls (that was the origin of the argument, it led to the use of Archive::Tar and others ) .

      if you use a nontrivial selection of modules the likely that POSIX gets loaded anyway is pretty high

      That's a good point, but the fact is that I mainly do system administration and installing more module "just for me" is forbidden. So i only use standard distribution modules, on my current project at least. (granted, these could also, maybe, load posix ! )

      probably reduce your run times (I admit I havent benchmarked),

      System load is the most important point for me, as in everything system.
      I believe POSIX has quite a lot of things in it, and i'm ready to had a few more lines in trade of the mere possibility that i gain something on that aspect.
      Maybe i could use POSIX qw(strftime) , but i do not know how this stands in load time difference compared to the whole use posix . Do you know ?

      Now if i really needed POSIX for something, i would use it. But only to format a date string ? Is it not using posix only for this that would make the code as a whole bloated ? .

      Anyway, I note the points you make on good practice since it's a very important subject where i certainly need more advice

      Cheers,

      ZlR.

        Well, loading POSIX which is an XS/C module is afaik pretty light. You could always put something like

        END { use Data::Dumper; print Dumper(\%INC); }

        in one of your modules and have a look at what is loaded. Id guess you'd be surprised. :-)

        Is it not using posix only for this that would make the code as a whole bloated ? .

        How does

        use POSIX qw(strftime); print strftime "%Y-%m-%d",localtime(time);

        Make your code bloated? Id bet the optrees and the rest created by your code to do the same thing are actually a lot bigger footprint than the precompiled from C POSIX library. Also, of the two which would you prefer to maintain?

        Now look, if you are writing scripts for a high usage web set, or something that has to have really fast load times then fine we can quibble about loading POSIX or something like it. But for the rest of the time I dont really see much room for even thinking about how long modules load, almost any task that is hard to do will take so much longer than the load time that its not worth caring.

        ---
        demerphq