Skip to content

Instantly share code, notes, and snippets.

@shajra
Last active August 29, 2015 14:10
Show Gist options
  • Save shajra/ea7b2d2d6ba8b2d01604 to your computer and use it in GitHub Desktop.
Save shajra/ea7b2d2d6ba8b2d01604 to your computer and use it in GitHub Desktop.
response to Bob Martin's "OO vs FP" post

A Response to a Response

Bob Martin wrote a blog article titled "OO vs FP".

Bob has a style of writing that makes it hard for some to see clearly his position objectively. In fact, his post is itself a response to a slide from another presentation arguably suffering from the same qualities.

I just wanted to summarize points I agree with that Bob makes, but also highlight some issues I have.

An attempt to settle debate

Before we can talk at all about "object orientation," we have to first agree on what an object is at all. I argue that if we can decide on that, then what qualifies as "orientation" is not interesting.

I choose to talk about "objects" as first-class modules. This is something I take from William Cook's treatment.

There is an architectural benefit to seeing objects this way. An architecture is merely a constraint (or set of constraints) that leads to universal invariants. Our job as engineers is to align these invariants with social requirements -- so that we have an element of proof to back our claims that we've made society better.

In this case, objects give us the following architectural constraint:

Never rely on knowing details about the implementation

This constraint is what Cook calls "autognostism," and it this is familiar to the OO practitioner that knows to avoid "instance-of" dispatching.

From this constraint, we get the guarantee that our interface is extensible by clients.

Of course, we can additionally augment our object with other invariants, but the constraint above is fundamental to all objects.

Incidentally, a simple function also represents an interface. A object just often has more than one interface in a record. So if a function is higher-order and accepts any function of a particular signature, then it is just as much a "object" as the definition above. This is what leads Cook to the comment "the untyped lambda-calculus was the first object-oriented language." This on face value may sound provocative, but it can also be interpretted as mundane.

Agreement

Bob never outright dismissed the slide

It's very true that functional programming does a lot with simple functions. Bob doesn't say otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment