Functional and oop programing

I’m studying “oop” and “Class”. It seems to me that functional programing and oop complement each other. They both should be balanced by what they both do best, and both can be used in the same program.
Am I on the right track in my understanding?

Absolutely!

Classes are great for modelling data structures that combine state (data) and behaviour (methods).

Functional programming is more of a mindset than anything else. Your program as a whole should avoid functions with side-effects (or at least, those side-effects should be encapsulated into the internal state of an object).

Once, long ago I stumbled across a blog or essay that claimed that using F.P. techniques in your code was a good way to make your code more robust, but only up to a point of about 80%. After which diminishing returns set in and trying to make your code 100% F.P. style didn’t gain you much. Unfortunately I’ve lost the URL.

These may help you decide when to write classes:

Stop writing classes!

Write more classes!

Also check out the PyCon talks given by Raymond Hettinger. You can find them on Youtube.

2 Likes