"The principle of Anna Karenina" devoted a lot of scientific publications and even a separate article in Wikipedia. Apply to IT and programming? Or maybe he is already working against your project?
I published the first version of this article in my English-language
blog and placed links in several highly specialized forums. The discussions that took place there motivated me to offer its version in Russian to Habr's readers.
The article discusses one of the philosophical principles, which from the point of view of the author:
a) objectively exists
b) is relevant for IT projects and programming.
If you, dear reader, are not interested in such topics, you can hardly read this article further.
')
Recently, I re-read Leo Tolstoy's great novel Anna Karenina.
The first time I read it in school years, because the teacher of literature demanded from us. But in order to understand such books, they must be read in adulthood, having accumulated enough of their personal life experience and understanding of human characters.
From chapter to chapter, Leo Tolstoy describes the events taking place, as if observing them with the eyes of one or another participant in the events. And the actions of some of the heroes of the novel, who were previously perceived as frivolous antics or manifestations of their evil will, viewed from a different perspective, seem to be deeply logical and even the only possible.
And after reading the novel, the impression remains that it could not be otherwise. A slight flirtation between a married woman and a young brilliant aristocrat officer turns into passionate love, then into a moral change in the relationship between lovers and, in the final, the suicide of the heroine under the wheels of the train.
And every link in this terrible chain of events at the time of reading seems clear and logical.
After reading the novel, everyone can decide for himself what this mysterious, very first sentence of the novel means:

“All happy families are alike, each unhappy family is unhappy in its own way.”
One possible explanation is that Lev Tolstoy in this proposal formulated a much more general philosophical principle, which is manifested in medicine, sociology, biology, global geophysical phenomena and, in my opinion, in IT in general and in programming in particular.
What does the principle of Anna Karenina mean?
Many scientific publications and even a separate article on Wikipedia are devoted to interpreting this principle, which received the name “Anna Karenina’s Principle”.
What does this principle mean? Very complex chemical, physical, biological, psychological, social, etc. Systems can exist for a long time and successfully develop and develop only if their parts are well suited to each other and to the external environment.
If we were able to describe such systems by some number of parameters, we would notice that for each class of systems there are quite a few “successful” combinations of these parameters.Note: To give our parametrized models greater reality, we need to talk not about individual parameter values, but about the equivalence classes of the parameters. But this does not change the essence.Paradoxically, but the more complex the class of systems, the less it has “successful” combinations.
Coffee makers from different manufacturers differ from each other in the technical solutions used and even in appearance are stronger than passenger cars, and those are stronger than passenger aircraft.
Anna Karenina principle and animal domestication or limited and secondary selection parameters
The British scientist Francis Galton, who lived simultaneously with Tolstoy, formulated a principle similar to the Anna Karenina Principle, considering the domestication of animals:

It seems that all wild animals had a chance to become domesticated. At the same time, few ... were domesticated a long time ago, and a huge number of others, who had never used their chance due to some minor features, condemned themselves to the eternal wild state.
Further interesting discussions about how this principle worked can be found in
Jared Diamond's fascinating book
“Guns, Microbes and Steel”.Chapter 9. Zebras, unhappy marriages and the principle of “Anna Karenina” of this book begins with this phrase (translated into Russian):
All domesticated animals resemble each other, each non-domesticated animal is non-domesticated in its own way.
If you thought that somewhere you already read something like that, you were not mistaken. Change a few words, and you get the famous first sentence of Anna Karenina, the great novel of Leo Tolstoy: "All happy families are alike, each unhappy family is unhappy in its own way." This phrase Tolstoy wanted to say that only marriage can take place in many different aspects: between spouses there is mutual sexual attraction, relations with each other are established, there are no disagreements about finances, upbringing of children, religion and other vital issues. Failure in one of these critical areas can ruin a marriage, even if it has all the other ingredients for happiness.
Further, the author names the factors that did not allow, despite numerous and ongoing attempts to domesticate wild animals. There are not many of them: diet, growth rate, problems with reproduction in captivity, “wildness” of character, tendency to panic, social structure.
It is interesting to note that all the factors listed by the author are “secondary”. For example, humanity grows and slaughters not rhinoceros on meat (3 tons of meat) but much smaller animals - cows, pigs and sheep.
In other words, if we were programming an algorithm for selecting animals for domestication, we would have to use not the primary attributes of this type of animals (weight, height, life expectancy, etc.) as parameters, but secondary ones calculated using special functions. And already on them we would impose rather rigid restrictions.
If you're interested, find and read a book.
But the author explains the operation of the principle in a particular subject area. Is there a broader interpretation of it?
Principle of fragility good
The brilliant mathematician Vladimir Arnold tried to look at the problem from wider and at the same time purely mathematical positions in his book “The Theory of Disasters”
There he describes the so-called.
"The principle of the fragility of good .
"He's writing:

... for a system belonging to a particular part of the stability boundary, with a small change in parameters, it is more likely to fall into the instability region than into the stability region. This is a manifestation of the general principle that everything good (for example, stability) is more fragile than bad. Apparently, all good objects satisfy several requirements at the same time, but an object that has at least one of several disadvantages is considered bad.
.
In the context under consideration, Vladimir Arnold was probably right. But in a broader context, one can see that in fact he speaks of fragility, or rather, of the rarity of stability, and not of “goodness”.
Not everything unstable is bad and not everything stable is good.
Whoever has ever crossed a puddle or ditch on a log, understands me. Unstably moving on a log is better than falling down and taking a stable position in a ditch.
On the other hand, any movement is rather an imbalance. Trees and flowers are good as long as they are alive and growing, and those that are withered are usually not.
And at the same time, about a tree that has been growing for hundreds of years, I intuitively want to say that it is stably growing.
Let us sum up the intermediate result: Stability (stability) and “goodness” - the indicators are rather independent of each other and depend on what we measure or model. At the same time, it should be added that sustainability is rather an objective, measurable parameter. What is good and what is bad is a subjective decision of the observer.
The principle of Anna Karenina and attractors
Reflecting on dynamic instability, we will almost inevitably come to the concept of chaos.
Chaos theory is a relatively young science. The book "
Chaos. Creating a New Science " by James Gleick is fascinating about its formation and first steps. One of the most fascinating stories in this book is the discovery of such a phenomenon as attractors.
According to the definition of Wikipedia, the “Attraktor” (eng. Attract - attract, attract) is a compact subset of the phase space of a dynamic system, all trajectories from a certain neighborhood of which tend to it at a time tending to infinity. An attractor can be an attracting fixed point (for example, in the problem of a pendulum with air friction), a periodic trajectory (for example, self-excited oscillations in a positive feedback loop), or some limited region with unstable trajectories inside (like in a strange attractor).
Below is one of the variants of the Lorenz Attractor.

What does attractors have to do with the Anna Karenina Principle?
I think from a philosophical point of view, attractors in the world of chaos represent “the same happy families” while the other points of the phase space are “unhappy families, unhappy in their own way”.
There are few trumps in the deck ...
You have probably heard about the long debates between Einstein and Bohr about the fundamental principles of quantum physics. The discussion was conducted around the question of which model determines the trajectory of an individual elementary particle: deterministic or probabilistic. Two great physicists have abstracted the essence of the dispute to the humorous question: Does God play dice, controlling the movement of the particles that make up our world?
Over the past century, models of describing the world have incredibly multiplied and become more complex. Continuing the line of Einstein and Bohr in relation to the current situation, we can say that to control the world, God needs tools more complicated than dice. For example - a deck of cards.
Then, taking into account the Principle of Anna Karenina, we can say that the deck of cards that God chooses to manage natural and social phenomena, as a rule, are not very good. There are too few trumps in them ...
Well, the phenomena themselves are divided into stable and unstable. At the same time, the “very” unstable with time often “roll down” to attractors.
How we divide them into good and bad depends on us. But it seems that in the current world there is more unstable than sustainable. And the bad is more than good.
In other words, the world looks like in my picture below.

The principle of Anna Karenina in IT
All this can and does seem to be true, perhaps some of the readers have already thought to themselves. But where is the promised IT title and programming? Does the Anna Karenina Principle work in these areas of human activity?
Sure is valid. If only because this general principle simply must act in this particular subject area. At least for those software and hardware and purely software systems that are quite complex and dynamic. And many of them really are.
Anna Karenina syndrome
If the Anna Karenina Principle (PAK) is present in IT, how to notice it?
First, if your system is stable and allows you to safely expand and configure yourself, you do not need to worry too much. Your system is in a stable, good part (see picture above).
If your system is not very good or not good at all, but is stable and does its job (is in a stable and bad part of the world), or is good but unstable, you should think carefully about whether it is worth the risk and something radically changed.
The PAC begins to show itself from its negative side, if attempts to correct specific errors only worsen the situation. Errors are really corrected, patches are installed, but new, more tricky errors appear “out of nowhere”. In such cases, we can talk about Anna Karenina Syndrome (SAC).
Recall that the syndrome is a complex of organically interconnected signs (symptoms), united by a single mechanism of its occurrence and development.
Depending on the size of the system, the NAO shows itself differently. But most of the manifestations are reduced to certain "scandals."
Below, I tried to give lists of (far incomplete) characteristic symptoms belonging to the SAH, depending on the size of the system.
In the enterprise scandal people
In large enterprise systems, the software and hardware problems of the IT component are quickly transformed into managerial scandals and psychological division wars. If we try to filter out the subjective psychological aspects, then objectively recorded phenomena often remain:
- We have to do more and more workarounds.
- In workflows, the phantom instances of processes are self-generated.
- Workflow instances split or do not end correctly and begin to wander around the workflows. Due to their incomprehensibility, the staff voluntarily or unwittingly pushes them further and further.
- Automation workflows replaced by manual operations.
- The data is corrected using nightly scripts.
- A working system has to be stopped and restarted more often.
In large client-server systems scandal components
At the level of individual systems included in a large enterprise, or independent large systems with a client-server architecture of the SAC often manifests itself in this way:
- Zombies appear unexpectedly in Data Banks (Incomplete entries with incorrect external links that cannot be created by regular scripts and processing programs. In German IT jargon they are called Leichen - dead bodies).
- The braking system is becoming more frequent when it “crawls on all fours”, and sometimes it just “falls”.
- There are “black spots” - groups of web-pages or data entry forms, which only a few users dare to use.
- There are “reserved places” - groups of masks, access to which for obvious reasons is organizationally or technically closed.
- There are frequent errors when converting data, for example, when sending them to partner systems.
In small systems, modules and classes are scandalous.
At the level of small systems (for example, Desktop Applications) SAK manifests itself in the fact that:
- The idempotency of operations is lost (for example, calculations that should not change the state of the system in theory, repeated several times give different results.
- Users complain of phenomena that cannot be reproduced.
- Linear extensions (adding to the system the functionality of the main profile, for example, a new business function) leads to errors or failures in the previously working modules.
- Secondary changes (for example, changing the color in the GUI) lead to errors or failures in the main functionality.
Is it possible to change the quadrant?
Is it possible for our system, which finds itself in the left lower quadrant, to change it to another?
I think not always. Sometimes the system is easier to replace than to try to cure. Fortunately, the average lifespan of modern IT systems is short - about 10 years. (This figure is the result of my observations, not of official statistics. It is amazing that about the same time is required for the complete renewal of the cells of our body.)
Where do our problems come from? As a rule, most problems arise when an incorrect choice or programming of individual components or using elements of the basic frameworks occurs.
For example, in my professional career, I observed the development of several projects that were born on the basis of the implementation of supposedly ingenious algorithms. These algorithms have been implemented in obsolete programming languages. The importance of these initial points of growth (nuclei) seemed immense at the beginning of the project. Therefore, customers have insisted that these cores always remain in the system.
The architecture and even the user interface of systems was adjusted to these cores. In the end, the cost of these prilad ten times exceeded the cost of the implementation of the cores themselves (if they were implemented again). Priladas turned out to be flimsy and it was possible to unambiguously diagnose SAH in the finished system.
What to do?
An enterprise can often afford a radical solution — replacing one component with another. Often this is really the only acceptable, although very painful decision.
If the system is unique, too sharpened for your business, or the migration and cost of licenses of the new system are too high, you should try to deal with the SAC on the spot. Then the natural question arises:
What is wrong with us?
This is the key question. Why does a competing or similar system fall in this place, and yours fall?
Often, because your system has several components that are programmed or configured “not according to the rules” - they do not correspond to well-established best practices or common sense.
If you find them and systematically fix, replace, properly configure - then maybe your system will become less unique, exotic, esoteric, mysterious, but it will stop torturing you. But again, the task is not to correct the accumulated errors, but to conduct a system analysis and, according to its results, to refactor or reengineer your system.
But then ...- it will become more like other successful systems. Just like "... All happy families are alike."
In the end, let me offer a specialized formulation of the Anna Karenina Principle with reference to IT systems and programming:
All successful systems of the same subject area are similar to each other, each problem system is problematic in its own way.
Problems arise from the use of non-standard, untested, in other words - "exotic" solutions and components. “Exotic” solutions and components “penetrate” into the system due to low qualifications or unwarranted enthusiasm of developers, managers or customers.
If the economic and technical indicators of the system are bad, the correction of some errors in it leads to the emergence of new ones - then most likely these are manifestations of the Anna Karenina Syndrome. As a rule, in this case, a radical refactoring of the system or its replacement of some parts with others or of the whole system is required.
I think your opinion, dear reader, will be interesting to other readers of Habr. Therefore, I will be very grateful to you if you take part in the survey.
Illustrations:
- A shot from the classic adaptation of the novel "Anna Karenina" Mosfilm. 1967.
- Lev Nikolaevich Tolstoy. Source: Wikipedia
- Francis Galton. Source: Wikipedia
- Arnold, Vladimir Igorevich. Source: Wikipedia
- Attractor Lorenz. Source: Newcastle Engineering Design Center - Newcastle University