3 ms·
In python you’d normally just use module level functions for that. Using a class without having instances and all static functions doesn’t really buy you anythi
by aidos 8y ago
In python you’d normally just use module level functions for that. Using a class without having instances and all static functions doesn’t really buy you anything.
- dnautics 8y agoIirc, modules have a dependency on bareword paths that can get awkward. I'm not a professional python programmer, so the fastest way for me to deliver something that I could be 100% guaranteed to work was that way. Maybe I'm wrong, but that was my logic.
- playing_colours 8y agoThe only problem I found with this approach is to manage state and dependencies: say, if the functions need to work with database, it is not convinient to send it as a parameter. A class instance initialised with a database looks more feasible in my opinion.
- dfee 8y agoYour alternative is dependency injection. What you seem to be describing is class factories (I.e. the use of meta classes) which /is/ OOP. That said, I think OOP is fine. And so is FP. They’re just tools, and I would prefer to model nouns in the former, and model verbs with the latter.
- aidos 8y agoThat’s a pattern I use a lot. Passing services and connections around everywhere is a pain, but I like to stick to a more functional style. I generally use classes as a place to hold context (E.g. dB connection) and then use a functional style within the class. Works as a fairly happy medium for me.