1

The custom modules on the main site I work on evolve. I try to separate their functions and write multiple modules based on discrete needs but sometimes they grow into each other once written.

Now I have two modules that are inextricably linked to each other to the point where each of their .info files have dependencies[] = theothermodule in them to remind future site admins of this fact.

Of course I can undo this and separate the functions out, but thinking about it made me wonder why I should do it, and that advice on this topic might be useful here.

  • I dont see much use of this question. If it's not a community module it really doesn't matter. If it is a community module then I recommend making submodules as needed that are not co-dependent. This should all be easier in Drupal 8 and OO paradigms moving forward from Drupal 7. – tenken Dec 17 '14 at 23:41
  • "If it's not a community module it really doesn't matter." This is exactly the kind of advice I was after because I really didn't know, cheers. – Darvanen Dec 17 '14 at 23:48
3

From wikipedia on "modular programming"

Modular programming is a software design technique that emphasizes separating the functionality of a program into independent, interchangeable modules

If you have two modules, and they depend on each other, they are no longer independent, and in fact, are no longer two modules, but one. At least in theory, that's a bad thing, because you can no longer make changes to one, without changing the other.

Sooner or later, you'll also likely find that this becomes a practical problem, because as the module grows, it becomes increasingly difficult to keep up appearances of an external interface. Both modules are calling functions in both modules, and again, you can no longer change one without also updating the other.

| improve this answer | |
  • There are some APIs (mail system and fields for ex maple) that only call hooks from the originating module. So there are limitations of a module's reachability to hook into other modules. Take hook_mail, hook_validate for example. So you better combine them into a single logical module. +1 to the answer. – AyeshK Dec 18 '14 at 9:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.