Most Common Architecture Mistakes When Using MVC Paradigm

Programming

This posting discusses bad habits when coding. I will be giving several examples of most common architecture mistakes. Beginners might find this information interesting, while the developing guru may want to breeze through it.

FSTC (Fat Stupid Ugly Controllers)

You can often face the situation when developers describe only the working functional with database in models and all the rest logics stays in controller. The slang acronym of such controllers is FSUC (Fat Stupid Ugly Controllers). The main purpose of controller is operating input/output, controlling access rights and exception handling. All applied logic should be described in models.
The function of the model is to describe general behavior of the essence and not only to work with the database. Also, using FSUC causes such problem as functional copying.

Functional copying

As an explanation I will give you the following examples:
a) Developer has written an action of creating an entity and then when he had to write an action to edit this entity, he copied the form description code completely from the previous action into a new one.
b) In most of the actions in controller there is a need to check the access of entity controlling. In many cases this functional is simply copied.

Solution: You shouldn’t forget to put similar functional into separate methods and into models or library in case with applied logic. Probably you should never use Ctrl+C -> Ctrl+V. You should better think about whether you can split the actions functional somehow into small logical pieces and put them into separate methods.

Cracking a nut with a sledgehammer

Sometimes when looking for a universal solution developers complicate the code too much, trying to take into account all the possible using options. Experience shows that sooner or later the unexpected situation happens anyway and you will have either to copy the existing functional with some corrections or to create spikes. The simpler functional implementation is - the easier it is to expand.

Inventing a bicycle

When using frameworks you have to study the details of their documentation quite attentively. Not knowing all the framework features makes you wasting your time on implementing existing functional and such implementation would be unlikely to have any advantages. Better spend your time on investigating the ways of using existing features than producing your own ones.

The last two paragraphs refer not only to MVC, but to programming in general, so it is what it is:). I would be happy to receive feedback or remarks in comments.

See also: Most common CSS and HTML mistakes

Comments