BTW, this is tangential. Someone commented on that thread stating that it is better to have separation between executable definitions and libraries.
I used to also think this way, but actually there is a better argument.
- Library code inside packages is not that different from executables
- Rephrased: where is the boundary between executables and libraries?
One could consider two extremes:
- Every executable is a minimal
main
function which just bootstraps a package
using MyPackage
function (@main)(ARGS)
MyPackage.run(ARGS)
end
- or: Every package is designed to be as general as possible, good examples of which are datetime utils, calendar utils, and math libraries.
Clearly none of these examples can be an executable. (What function should it perform? Return todays date? Add 1 and 2? It doesn’t make sense because they are general purpose.)
In the case of the former it is clear what function it should perform, but the package has no generality. It does one business logic thing that it was designed to do, and nothing else.
The latter is actually very difficult to achieve in general, unless you are writing a package/library, and this your entire objective. You don’t intend to use it or write an application using it.
(Please use your imagination a bit here.)
Generally speaking, as soon as you move even slightly towards the realm of developing a production application, you tend to end up with library code which is not pure library code but some mix between code which is domain specific to your exact use case and context, and code which is “pure” general purpose libraries. Usually it is more weighted towards the former than the latter.
Python, much to my own surprise I will admit, sometimes, somehow, manages to do things which turn out to be genius design decisions - and I mean this in a literal sense. Whether the authors of those decisions knew what they were doing was genius seems unlikely - or at least if it was they certainly didn’t say so or even document it anywhere.
I suspect actually, like C++ template metaprogramming, these things were discovered rather than designed. Nobody designed C++ templates for sophisticated (although complex and arduous) metaprogramming, but it was discovered that templates and the compiler could be used to perform sophisticated metaprogramming that no one knew was possible until someone discovered how to do it.
The problem in this particular (Python) case is almost nobody - and I mean literally almost nobody - knows how to use Pythons module and package system.
I only happened to come across this information by accident while working for a particular company for a short period of time. I have never seen it openly documented on the internet.