The COMPLETE Liskov Substitution Principle

LSP (short for Liskov Substitution Principle, not for Language Server Protocol) is probably one of the least understood concept of the SOLID principles. So in this post, I want to actually address the complete principle, not just what people know.

Because of the “typed” nature of the LSP, I’ll try to use a language that people are familiar with, and that I can show in a playground somewhere: Typescript. Truth to be told, I am not a Typescript developer (nor do I actually like the language) so my code might be a little weird. Anyway, moving on:

What people know

The actual text is

Let Φ(x) be a property provable about objects x of type T. Then Φ(y) should be true for objects y of type S where S is a subtype of T.

This is actually hard to read, so people simplify, usually, with:

Objects of a superclass shall be replaceable with objects of its subclasses without changing behavior

Which is correct, but incomplete.
(more…)

The infinite arrogance of software developers

Yeah, sorry for the bold title, but sometimes I get tired of software developers expecting they figure out the secrets of the universe. And let’s be honest: at some time in my career, I was one of them. Sometimes by accident, sometimes… not. Anyway.

First, a little disclaimer: this post is not targeted at anyone in special, and I’ll not mention anyone here – just quotes, slightly modified. Anyway, although I love my profession, sometimes it feels like we’re this programmer guy from XKCD:

I'm here to solve it with Algorithms, then six months latter: wow, this problem is really hard (Megan: You don't say?)

There are LOTS of things that bother me at this programmer mentality, so I’ll separate this post into multiple sections. If you’re reading this and feels like it’s a personal attack against you, please don’t – I’m not really attacking anyone, just trying to change a toxic mentality that poisons our abilities to be better professionals, people, and human beings.

“Not a real programmer”

The first one is classic: people define what a “programmer” is, based on their own experiences and expertise, and dismiss people that don’t fall into their categories. Wikipedia, for example, defines Computer Programming as:

Computer programming is the process of designing and building an executable computer program to accomplish a specific computing result or to perform a particular task

As for the “Computer program part”, Wikipedia defines as:

In imperative programming, a computer program is a sequence of instructions in a programming language that a computer can execute or interpret. In declarative programming, a computer program is a set of instructions.

So it’s hard to find a good definition on what programming is, but if we try to merge the two explanations from Wikipedia, we get that, to program a computer, you have to design an executable “sequence of instructions” or “a set of instructions” so that you can accomplish a specific result or perform a particular task.
(more…)