Resource for OOP Python
For Python, I really like the python-course.eu tutorials/writeups.
They have a whole series about OOP (object oriented programming is a deeeep rabbit hole in python): OOP Python Tutorial: Object Oriented Programming
My thoughts on OOP
The definition of OOP is not set in stone and most people understand something different under it.
However, most languages use OOP as a kind of “syntactic sugar” to enable (hopefully) more readable code.
Instead of the need to include the object in the function parameter list, e.g.,
do_something(object,a,b,c) it enables one to express it in a construct that is similar to the English sentence structure (Subject Verb Object (SVO))
object.do_something(a,b,c): this can be read as “object do something with a,b,c”. (The
object is the subject,
do_something the verb and
a,b,c the objects).
Functional programming is all about having as little side effects in the code as possible:
When looking at a
do_something(a,b,c) function call, a side effect could be that one or multiple of the parameter objects (a,b,c) are changed after the function call. Global variables can be also seen as parameters of the function. Also for
object.do_something(a,b,c) the object can be seen as a parameter and should therefore when programming functionally not change.
Now in python it is not possible to enforce these functional restrictions within the “python language”, which is why so many people recommend learning a functional language like haskell such that one is forced to program in a functional style.
There is an additional “problem” with functional programming: a program with no side effects will do, effectively, nothing. This tells us that at some level “code with side effects is necessary”. For example the
So why is functional programming becoming popular? The reason is that functional code is a lot easier to reason about.
Edit: do no longer use the term “purely functional program”