3 ms·
Honest question: what are the reasons to code this up using OOP, creating a neural network object plus methods, instead of data structures and functions that op
by plg 8y ago
Honest question: what are the reasons to code this up using OOP, creating a neural network object plus methods, instead of data structures and functions that operate on them?
If it’s just personal preference, I’m fine with that, I’m not trying to start a flame war.
- claytonjy 8y agoPython, both the language and community, are very strong proponents of OOP. While you can do a lot of more functional stuff, esp. w/ functools, the community at large tends to discourage that. "Never use map/filter" is a weirdly common phrase among pythonistas. So this, like most python-driven examples, is doing things in a pythonic way. Coming from the R side, I tend to prefer structures & functions as well, but if I tried to write Python that way I'd be wary about showing that code to anyone more entrenched in the Pythonic way of thinking.
- jononor 8y agoThe never use map/filter is in favor of list comprehensions, which is not really a OOP construct. But sure, it's a conventional thing. And for a long time the built-in alternatives to a class for such a datastructure tuples and dicts, neither which are very nice for functions to operate on (dict values have to be addressed with d['key'] instead of d.key). With a class and method there is also no doubt as to what the function operates on, which is convenient when there type hints and IDE support is missing. This is changing since Python 3.5 and type checking tools like MyPy. Since Python 3.7 there are also data classes, a primitive for classes which just hold values. https://www.linuxjournal.com/content/introducing-python-37s-dataclasses https://www.linuxjournal.com/content/introducing-python-37s-... But it will take a while before programming conventions change.