0
$\begingroup$

Im wondering the pros vs cons of having an blender addon in a large python script (let say 7 thousands lines) vs splitting everything in different thematic modules ?

I think that In the end having everything in one file is much less prone to error for users (both installation and uninstall) and also less an headache of juggling with multiples files.

Is it all about personal preferences ?

$\endgroup$
1
$\begingroup$

It's better to split it into separate files. The reasons for this are:

  • Separation of concerns: It's easier to separate UI from state and logic when they are in separate files. Keeping everything in one file also results in low cohesion which is not desirable.
  • Maintainability: Keeping everything in a single file will likely result in tight coupling, which makes refactoring a lot harder.
  • Understandability The interaction between classes is difficult to grasp when everything is in a single file. Finding a function or class is challenging when you don't know exactly what it's named and with only a vague idea what it does. This is especially a concern if other developers try to contribute to your project or if you take a break then continue the development in couple a days/weeks/months/years. If for instance the functions for scatter distribution are in a separate file called scatter_distribution.py, then it's easy to find because you already know what's in the file based on its name.
  • Extensibility: Given that your add-on already reached approx. 7000 LoC, it's clear that new versions with additional features will increase the complexity further. This will impact the previous points negatively. If your code uses separate files you can easily extend it with another file for a specific set of features.
  • Reusability: Having separate files or modules allows to reuse code more easily in the development of future add-ons that require some of the features you've already implemented in the current add-on.

The add-on can be distributed as .zip which is the standard way of installing it through the preferences, therefore users don't have to deal with the individual files.

In conclusion there are plenty benefits of writing modular code. It may take more work at the beginning, however it can significantly reduce the effort of maintaining the software.

This answer is not a complete and definitive list of reasons, however it should highlight some of the most serious issues that occur when keeping the entire code in one file.

$\endgroup$
  • $\begingroup$ Thanks a lot for this answer @rjg very useful $\endgroup$ – DB3D Nov 3 '19 at 15:55

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.