Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unmaintainable code behind to the non-technical

Tags:

code-behind

How would you explain to a non-technical person why writing code (business-logic) behind the onclick event is a bad practice and leads to unmaintainable code?

Edited: I have to explain management why some refactoring is needed, also why some code is not passing code review. To some people in management this only means more funding. I came up with this example because at some point of a discussion somebody said: ..put the code behind the button and forget all that model-view-controller hype, you will finish your task faster.

like image 852
AlejandroR Avatar asked Aug 18 '09 23:08

AlejandroR


2 Answers

This is how I would explain it:

The difference between writing code behind onlclick events and writing applications that are tiered or layered, is like the difference between a medieval town and a modern city.

In a medieval town, everyone plows it's field, everyone sews his clothes, builds his house and educates his children to the best of his abilities, no one is really specialized to do a task well, they have to do all the tasks necessary for survival. This is what writing code behind onclick events is like, the code has to do everything, handle UI interactions, do business validations, handle database access, and this repeats for every event.

In a modern city there are farmers that practice agriculture at a larger scale and specialize in it, there are tailors that can sew better clothing for everyone because of greater experience and specialization, there are builders, there are teachers that teach children in schools and can do a better job at it because they have more time to do it. This is what writing a tiered application looks like, the UI tier is responsible for handling user requests and updating the user interface only and therefore is more easy to change replace or extend by having no extra code burden, the business tier is responsible for business logic and all the logic is centralized, reusable, the business logic code is more compact and clean, the data access tier handles database interaction and specializes in doing it possibly interacting with more than one type of database.

Writing code behind onclick events is a rudimentary style of programming that is not the most efficient style and doesn't yield the best possible results in the long run, although the results are more than often acceptable (the application works), it can work allot better, be easier to maintain and extend and be more consistent (regarding ui, interactions, error reporting, workflow, etc) by using a proper tiered design that employs good coding practices.

like image 128
Pop Catalin Avatar answered Oct 10 '22 21:10

Pop Catalin


Because you would not connect the doorbell directly to the release buzzer.

like image 25
Ozan Avatar answered Oct 10 '22 21:10

Ozan