Separate logic from data

OOP is the legacy of the Gang of Four along with JVM, .NET and Ruby on Rails. I recommend that you read Steve Yegge’s article “Execution in the Kingdom of Nouns“. This is the reason why you should not adopt class-based OOP.

Below is an excerpt from Joe Armstrong’s article “Why OO Sucks“:

Objects bind functions and data structures together in indivisible units. I think this is a fundamental error since functions and data structures belong in totally different worlds. Why is this?

Functions do things. They have inputs and outputs. The inputs and outputs are data structures, which get changed by the functions. In most languages functions are built from sequences of imperatives: “Do this and then that …” to understand functions you have to understand the order in which things get done (In lazy FPLs and logical languages this restriction is relaxed).

Data structures just are. They don’t do anything. They are intrinsically declarative. “Understanding” a data structure is a lot easier than “understanding” a function.

Functions are understood as black boxes that transform inputs to outputs. If I understand the input and the output then I have understood the function. This does not mean to say that I could have written the function. Functions are usually “understood” by observing that they are the things in a computational system whose job is to transfer data structures of type T1 into data structure of type T2. Since functions and data structures are completely different types of animal it is fundamentally incorrect to lock them up in the same cage.

This is also the reason why you should avoid using stored procedures in relational DBMS. Applications have their own life cycle so you should separate logic from data.


Subjectivity aside, leave a reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s