Search code examples
dependenciescrystal-lang

How to include large numbers of dependencies


In crystal, is there a better way to include large numbers of dependencies for a script, as opposed to lots of require "whatever" statements at the top?

For example, I'm currently creating a web framework where I'm potentially anticipating a large number of dependencies and would prefer not to have a number of require statements in each script.


Solution

  • You obviously need require "whatever" somewhere in your program to use whatever. However, it needs only be required once, so you don't need to repeat requires that are already in other required files. They're added recursively.

    You don't need to require dependencies that are already required by other dependencies. You'll only have to require files to combine independent components. So, it usually shouldn't be such a large list. But I don't know your exact use case.

    Maybe you could consider extracting all requires to a separate file to keep the main file smaller. But I don't know if that's such a huge benefit, considering a scripting environment.