Standalone script or as a module?

I always have a dilemma with the choice of creating a module / package or keeping a standalone script.

I often write small scripts / programs in Perl or Python that do some work. I used to use the same subroutine in several programs, but they are just small subroutines, and this is my dilemma.

If I keep the script self-contained, anyone can run it without installing any packages. If it's a single file, you can use it from anywhere. However, if I create a module, my users will have to install it before using my script. I will need to consider the exception that dependent modules are not available, and later users may run into problems installing the required modules.

So, to avoid dependency problems. I prefer to have a little redundancy and not use any additional packages (only if I can do that. Obviously I won't override XML::Twig

in all my scripts, but I could do it for an INI parser or a Perl to JSON converter).

Also, I usually put all my scripts in the same directory as /usr/local/mycompany/bin

What would be the best strategy for accepting scripts / programs that do not exceed 200 lines and will be used by less than 20 people?

EDIT:

I am not asking for personal opinion. I am only looking for a very pragmatic and rational answer from those with good programming experience.

To give you a more specific example. I have a script that parses a config file in native format. This format is used by many people at my company. However, only my scripts use my parser. I think I only have three options:

  • Placement of a parser (about 50 lines) in each of 5 scripts.
  • Making a good module to be installed in your Perl / Python distribution.
  • Using a stand-alone library located in the same directory of other scripts.
+3


source to share


1 answer


False dilemma. You can do it right away.

You can create a module that you use in your scripts, and then when it comes time to deploy the scripts, include it along with them. Either include it as a local module file, or actually collapse the module and script into one file.



Thus, your materials do not require installing any modules separately.

0


source







All Articles