In the Brain of Uncle Bob at Skillsmatter

I went to an excellent talk last night at the Skillsmatter exchange on Object Oriented Programming by Uncle Bob (Robert C. Martin).

The talk was mostly about his S.O.L.I.D principles for OOP: Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion but also about the history of OOP and what makes it so powerful. It is this last part I am going to develop below because surprisingly, in a room filled with approximately 100 OOP developers, nobody was able to correctly answer how OOP was created and what is so good about it.

Object Oriented Programming was created by Ole-Johan Dahl and Kristen Nygaard in Oslo in 1966. They were simulating ships going around the fjords using ALGOL but were not particularly satisfied with it and started hacking it. All they did was move the data structure from the stack frame to the heap and were well surprised with what happened. ALGOL is a block structure language; it is possible to declare a function inside another function. Once moved to the heap, functions were still callable, the outer function still returned, local variables still existed. The outer function had become a constructor, the inner function had become an instance method and local variables had become instance variables. And they could call methods on these objects. Object Oriented Programming was born.

And now the tricky question: what is so good about Object Oriented Programming? The answers provided by the audience did not satisfy Uncle Bob Martin, especially not the myth of modelling the real world, probably invented by a developer who wanted his boss to buy him an expensive C++ compiler he reckons, or the myth of re-usability, which is not an advisable practice anyway. As per inheritance, mixing data structure and code and encapsulation, it was all possible in C, even easier in the case of encapsulation.

The true added value of OOP is polymorphism. Polymorphism was possible in C but very difficult to manage and generally avoided. OOP made polymorphism easy. And what polymorphism brings us? Dependency management. Until OOP source code dependency and flow control were always going in the same direction. Polymorphism gave the ability to take some dependencies and turn them around without changing the flow of control. What did that allow? Plugins. It allowed the creation of modules that could be called even if unknown; it allowed invoking methods on unknown objects. This is the beauty of OOP!

A great couple of hours at the Skillsmatter exchange, half-way between the tech talk and the one-man show. Brilliant.