📜 ⬆️ ⬇️

And if I do not sing a song ...

Introduction


Many words have already been said about the development and the program code. Some have already begun to pall such words as: refactoring, flexible methodologies, testing. Most of the community looks at the code through the prism of an ideal world. At the same time, the majority of developers cannot clearly answer the question: “When should code be rewritten?”

Main metaphor


A good phrase always helps to remember any data. In addition, in fairly abstract areas of human knowledge, it allows you to quickly understand the essence of the problem and its solutions.

Long thinking about the problems of co-ownership of a huge amount of code, it seemed that all the problems were clear, but there was a lack of a good metaphor for fixing the thought. She appeared suddenly and is well known to all lovers of Russian rock: “But should I sing a song ...” (song of the band Chizh and Co). Now we will understand why it is very well suited to the IT-world.

Systems


Conditionally divide all systems into new and old. This division is taken as the basis for simplifying the presentation of the material. There is a theory of complex systems, but then it is a theory to describe systems in a sufficiently precise and non-trivial language.
')
Separation of systems does not apply to a temporary feature.


The article mainly deals with old systems, although it will be useful for new ones.

My songs



All system developers are singing birds. The system is a forest song in different ways, cheerful, sad, fast, slow. Sometimes the state of the system is like complete silence ...

Ordinary situation. The developer needs to implement some functionality, based on the existing system. There are two opposite approaches to solving the problem:


Solo


Every nightingale developer turns out, once, in such places of the forest where no one has been in for a long time.

A quick rewriting of the code, removal of whole classes, refactoring of all unloved sections of code begins. The system is becoming slimmer and slimmer, but only one performer can “sing” in this system. All other developers will not be able to quickly enter the desired stream. At the same time, signs of instability and destruction of the system are possible ...

Bazaar


Every nightingale developer turns out, once, in such places of the forest, in which everything happens and very often, he also does not want to linger here for a long time.

Such places are characterized by multiple copying of the same sections of code, huge methods and functions of 1000 lines or more. It is not possible to understand the common logic of a beginner, so he quickly inserts a couple more lines into a huge method and retreats to another task.

Developers familiar with the system from the cradle know perfectly well where the right branching in the giant method is, all the rest never reach such heights.

Music


Coordinated actions of all developers. The ideal system, the world-recognized "musical" masterpiece. Usually not attainable.

The system has a clear structure, perfect decomposition, simple methods. Any new developer quickly understands the basics of code functioning.

Thoughts that something to fix in the surrounding code does not even arise.

When is it worth rewriting ...


Do not talk about flexible methodologies. They simply do not work on projects with a 15-year history, tens of thousands of classes. To rewrite all this is absolutely impossible.

Everyone knows that the entropy of any system increases, which inexorably leads to its destruction. Any system, when that, will end its existence. It may become unnecessary, it may fall apart from the abundance of disparate functionality, it may lose in the competitive struggle of technologies.

But it is always worth remembering that the increase in entropy can be slowed down. To do this, you can not make giant edits to an already established system. If such a desire arises, maybe you should write a new one? It is possible and necessary, when introducing additional functionality, to modify the code of individual parts of the system to simplify perception (it must be remembered that the “old-timers” can easily get lost in the new code, you need to leave the bread crumbs ”). Never create new functionality, making additions to existing methods, he deserves to be seen in new sections of code.

Conclusion


Many times I encountered a situation when, modified beyond recognition, the code looked perfect. But at the same time, the main ideologue and developer of the basic functionality was simply lost in it, it took him time to parse the code. Therefore, rewriting code can be considered a bad practice. Reduce entropy and write new systems!

Afterword


If you listen to the song and reflect on the development, then there are many interesting points from the practice of software development that come to mind.

Source: https://habr.com/ru/post/122862/


All Articles