Tuesday, August 16, 2016

MVC or not MVC?

I've been away for a long time, without posting anything here, and I beg your pardon for that. I've been too busy with my life-project, the Emerald Framework. This framework will be the next good thing in web development. I'll talk a bit more about it soon. But those very curious may just drop me a message at emerald.framework@gmail.com and I'll send some material about it.

I'd like to talk to you about MVC. And the reason for that is exactly the fact I was talking about Emerald Framework with two people yesterday night and I got really surprised because when I said Emerald wouldn't use MVC  one of the guys (a developer!) asked me in surprise: "If it is not MVC, then what it is?" And he asked this question as if he never heard about other patterns for web development.

This moment I realized how MVC turned out to be popular in the last few years  and how people forgot about other patterns, believing MVC is kind of a "magical solution" to all problems.

Then, let me tell you some point about MVC people tend to forget:
  • MVC is far from being the unique pattern available. We have lots of them. In fact, here we may use that famous quote by Andy Tanenbaum: "The good part of standards it the fact we have so much of them". This ironic quote is oh-so-true when we talk about web development patterns: HMCV (Hierarchical MVC), MVVM (Model-View-ViewModel), PAC (Presentation-Abstraction-Controller), MVP (Mode-View-Presenter), NO (Naked Objects)... I could continue for a long time naming other patterns, but I prefer to let you free to research by yourselves visiting this link  here.
  • MVC is usually a BAD solution when it comes to performance, at least when compared to other options, but this is not MVC's fault. The fact is MVC frameworks were designed to favor maintainability  and readability, not to favor performance. If you really like MVC and is worried about performance, I suggest you to write your own MVC implementation designed for this.
  • MVC is not a good choice for small applications. It is counter intuitive in these cases. You will work too much to have a single page running with MVC, when compared to other options. In fact, if you have an application with only two or three pages, forget all you heard about patterns and code this yourself, in you own way, putting all possible frameworks aside.
  • MVC provides separation between code and presentation, but not as much as it would be possible. In fact, this is one of the questions I specially addressed when I was writing Emerald Framework. I just don't like ANY kind of Ruby (or other language) code mixed with my HTML code. ERB, for instance, is not a good choice to me. I don't like those <%= %> tags mixed with my HTML code.
  • Most MVC frameworks are going to force the web server to perform the inconvenient task of serving HTML code. It's just me or there are others here who believe a web server should be reserved to more noble tasks, like producing dynamic data? This is an old issue in certain circles: let the browser deal with interface generation, provide just JSON and let Javascript build the interface for you. Isn't this, for instance, the essence of knockout.js, for instance? Among other advantages, you may have not just dynamic data, but also dynamic interfaces, customized to each user.
And you? What do you think about MVC? I would really like to know what your opinion, so post a comment here and speak your mind.

See you next post!