3 ms·
There has been a lot of commentary along the lines that "OO sucks" since OO became mainstream in the early 1990s and there will be for a long time. I think you
by PaulHoule 4y ago
There has been a lot of commentary along the lines that "OO sucks" since OO became mainstream in the early 1990s and there will be for a long time.
I think your example of a dataclass replacing a dict is just fine.
I'd grant though that the single-method class is a special case, even in Java it is tempting to use a Function<X,Y> as opposed to define a specific class or interface for a particular use. Such a "class" can even be defined as a lambda message in Java and capture state from the environment as opposed to writing a class with fields spelled out.
I've found, however, that the "functional class" often adds more methods and attributes over time. In the case of Python, however, you can write something like
def fn():
...
fn.someAttribute = ...
so you can occasionally tack some extra functionality (say metadata) onto a function that way.
- parpfish 4y agoMost of the old discourse around the video turned into debates about OOP vs functional programming, but I feel like those debates alway make a mistake conflating "using classes" with OOP. Sure, classes can be used to build 'objects' in an OOP paradigm that have lots of methods and attributes that store state and all that. But if you instead think of classes as a simple way of extending the type system (e.g., the aforementioned dataclasses), defining classes can fit in really nicely with a functional programming paradigm by cleaning up function signatures. However, the benefits of this wouldn't have been visible in python 10 years ago because there was little/no typing.
- PaulHoule 4y agoYep. I code a lot in Java and in Python and my experience in one informs the other and I particularly like seeing parallel developments in the two languages. In the case of Java I quite like how records and sealed classes can take the role of sum and product types from FP.