Snow-white code

What is clean code? This is what everyone is looking for, but no one can find. People rarely agree on what it is and how to put it into practice. You can find countless articles on this topic, and this will be another one. I will try to understand what clean code is in itself, in isolation from languages, paradigms and areas of application.

To begin with, I would like to think about the place where the code is applied – about the program. A program is a part of a product that runs on various computing devices. It could be a server, a mobile phone, a browser, or even a coffee grinder. Although the product consists of many components (advertising, content, in a sense, community), now we will limit ourselves to only the software component. This digression is necessary to avoid confusion as if the program is a product. The software reflects or may reflect only part of the author’s intent.

When developing part of the project, we rely on the general idea, on the technical specifications. I think that in any field of activity, completing a task looks something like this: the master performer becomes familiar with the task, plans its implementation, and only then begins the process of direct labor. In any case, this is exactly how things are with programming. The programmer reads the specification, comes up with a solution and writes the implementation. Why does the stake sometimes turn out to be clear and simple, and sometimes not?

In the process of writing code, a programmer is engaged in translating images from his head into a language that both the computer and another person can understand. A program is nothing more than an unusual type of embodiment of thoughts.

Any text is easy to understand only when its author has deeply analyzed the topic, thought everything through, structured his thoughts, and only after that presented them “on paper.” All ideas have been thought through for a long time, and therefore are simple. After all, this is the only way a well-understood idea can be. The human brain cannot contain objects that are too complex. Even when we think about such complex things as protein folding, there is nothing supernatural in our heads. Each idea refers to several others, and those in turn refer to others… these chains (graphs) can be very extensive, but their links are extremely primitive. If we cannot imagine an idea as something tree-like, when there are some complex and incomprehensible things that cannot be explained to others, this essentially means nothing more than that we ourselves do not have a complete understanding of what is happening. There is a well-known myth that refers to this: if you cannot explain something to a 7-year-old child, then you yourself do not understand it. This is true except that explaining the tree (graph) of some idea can take so long that the child will no longer be seven years old when you finish.

The same reasoning applies to texts written not only in Russian, English or any other human language, but also for formal languages.

Of course, in any language you can express the same idea in many ways, each more complex than the other. But the skill of presenting thoughts in a simple form is general. There is no need to make plot changes in Dostoevsky’s novels when translating from Russian into German: the story is already told clearly, beautifully and deeply. It’s the same here.

Without a doubt, it is necessary to learn to write sentences correctly, so that it is not dry or overloaded, etc. There are general techniques for this, and there are local ones for a given language. But this is just tinsel. There is such a concept as “the language of the author” (for example, “Dostoevsky has a heavy language”) and it fits perfectly here. Each person has his own way of choosing language structures to form a text, but this is only a small part of how the author’s idea is conveyed.

All existing paradigms, design patterns, best practices, etc. are nothing more than popular ways of organizing ideas. These are comfortable, well-trodden paths that are familiar to everyone. Simply put, templates such as adapter, three-part act structure, decorators and the like help the reader understand the work more easily.

——————————

The more humanity thinks about an object, the better it understands it. Every programmer should strive to fully understand the task in order to be able to break it down into its simplest parts in order to assemble a beautiful, simple and understandable program from this constructor.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *