Sunday, October 28, 2007

Why MVC is Wrong

First of all: MVC is Right because the model separates problems into three relatively independent functions.

But, MVC is wrong because it's being used as though it is the Only way to do things.

It's Not.

The problem is that Presupposing or Requiring an MVC model interfers with the Design Process.

Here's the best way we've found to design and construct systems:

1. figure out what is to be done and define it precisely and succinctly

2. define a collection of tasks which can be performed in series or parallel where the results can be either combined or fed to successive tasks which produce the desired result. Ideally, these tasks can be defined as 'black boxes' - to use the term I was taught back in Engineering school.

3. Build the boxes, test, deploy and celebrate.

In my experience, every field - Engineering, Computer Science, Economics, etc etc - has rediscovered the same method and principles - but uses different terminology.

In CS, black boxes were 'objects'. Now they are Design Patterns. We used to talk about Heirarchic Decomposition, Information Hiding and Structured Programming. In client-server designs, we talk about clients, servers, and protocols.

It's all the same stuff.

1. We figure out what we want to do.

2. Then we chop it into pieces small enough to build.

3. Then we define some protocol to get inputs into and outputs out of each piece and use them to wire the whole thing together.

MVC Screws this up mostly because it puts the Chopping before the Analysis. This Adds complexity to the solution rather than taking it away.

For Example:

Suppose I have a semi-static web site. By that I mean, nothing changes all that much, but the owner would like to modify something on a couple of pages every once in a while.

I can Make this MVC, but why bother? There's nothing to Control. All I have are Views. The only 'model' I have is a chunk of Text. Most of my pages can look like:

<html>
etc
<?php include('owner-content'); ?>
etc
</html>

If I have a way for the site owner to update 'owner-content' - possibly a simple update page so she can edit the page on her home machine and then download it to the site - then I'm done.

I don't need MVC partitioning of this problem unless I want to use a prepackaged system.

The obvious answer is there isn't any need for all that machinery to solve simple problems.