The drawbacks of OOP

OOP serves us extremely well, but it has its downsides.

Imperative programming allows, indeed relies on, functions having so-called side effects. This means they can have effects on the state of the program beyond simply returning a value. Here is an extreme case:

func tripleThisInt(i: Int) -> Int 
{
let result = i * 3
eraseTheInternet()

return result
}

Side effects represent several challenges.

For a start, you have to just know they're there; you can't see that they happen in the name of the method; there is no indication of them in the arguments to the function, nor does the return statement give any clue (these three together make the method signature).

Furthermore, we have the matter of mutable state and the problems that go with that. Object A expects object C to be in a certain state, but object B has just used object C's properties, changing its state in the process, and the whole program falls over.

Another thing to beware of with OOP is that programs become very complex very quickly, and software reusability and maintainability (which is the whole point of OOP) soon get lost in the heat of delivery and release deadlines.

Remember we said it's easy to imagine there is no other way? Well there are alternatives, and one that we will look at closely, to see what it can offer us in terms of expanding our repertoire of techniques, is declarative programming.