0

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.

ol'bob dole
  • 119
  • 8
  • Please provide a more detailed question such as providing a use case or scenario for which you would need to include a large number of requires. As far as I'm aware there shouldn't be (if any) many scenarios in which you would have to do such a thing, especially so since Crystal is still at version 0.24.x (correct as of 15/05/2018) – madcrazydrumma May 15 '18 at 19:10
  • @madcrazydrumma I'm not entirely sure what relevance the version of crystal is to the number of potential dependencies I may have. Certainly in web applications I find there is often a lot of dependency requirements, so my question reflects this. For example in php we use autoloading to avoid large numbers of include statements in modules. If the answer below is relevant then the question is relevant. – ol'bob dole May 16 '18 at 10:49
  • The version of Crystal in my comment referred to it still being in development and the potential for a large number of includes in unlikely. However, you have just supplied a use case. Can you update the OP with a more detailed use case based off what you said just there? So that other people can look at this and get more information? – madcrazydrumma May 18 '18 at 08:06
  • 1
    @madcrazydrumma fair enough - will do – ol'bob dole May 18 '18 at 13:27

1 Answers1

2

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.

Johannes Müller
  • 5,581
  • 1
  • 11
  • 25