I am asking this for Ruby, but I guess this principle can be applied to every project with multiple files. Say I have a main file e.g. application that requires some other modules model1 and model2. Both those modules need the common module. I’ve seen many Ruby projects that would require common in application and not in model1 and model2. While this works if you always use application directly, if you require one of the modules from elsewhere, you get a NameError. So maybe this impacts the modularity of the project? Should I always prefer requiring explicitly all the dependencies from every file? (By not making any assumption about where the file is required from)
I am asking this for Ruby, but I guess this principle can be applied
Share
I would always require all dependecies if a module is designed to be loaded from different applications. If
model1is only an application specific element, you don’t need to load already loaded modules.But it would take a look, what’s really needed.
Does
model1andmodel2needcommonor does require the mainfile.rb? (I don’t think, that’s the case in your specific case) Sometimes you don’t need to load all requirements, if one of your requirements (let’s call it main-requirment) already loads the other (sub-)requirements.