📜 ⬆️ ⬇️

What is a beautiful code, and is it necessary? What do they think in Yandex

More than 6,000 people work at Yandex, and, according to some estimates, more than half of our employees have experience in programming. And of course, each of these people has his most correct opinion about what the ideal code should be.

As a result, we have disputes about whether the code should be beautiful. And it turns out that the concept of beauty here, as elsewhere, is subjective: “Preference in the code for programmers is like preference in women. Some people like brunettes, some like blondes. ”

In order to understand which properties of the code are being defended by different sides, I, hot on the heels of the next heated discussions, decided to ask my colleagues what a beautiful code is and should it be beautiful at all? Is it enough that it works well and is understandable? Or is the clear default code beautiful?
')


The survey involved bobuk , anatolix , anton , Andrey yafinder Plakhov, Anton Samokhvalov, Andrey Gulin, Vladimir Ivanov and others. The total programming experience of all participants in this micro-interview for eight is 198 years.


Andrew yafinder Plakhov
Programs 24 years. In Yandex - 6 years.

He came to Yandex in 2008 as a senior developer. His first task was to create a new type of ranking factors - domain. Engaged in ranking, created a system Spectrum. Candidate of Physical and Mathematical Sciences. Now manages the search functionality service - in particular, develops search tips . Understands deeply both the technology and the user properties of the product.

Andrey Plakhov

To ask a programmer what a beautiful code is and whether it should be like this is the same as asking an architect what a beautiful house is and whether it should be like that. What is a beautiful house is unlikely the architect will explain to you, and if you ask him whether he should be, he will, of course, say that he should.

The code, in my opinion, should be beautiful. It is very good if it is beautiful, but sometimes you have to do without it. In fact, each of us in our hearts dreams that someday he will build his own opera house in Sydney or something like that. In the meantime, you have to build communal.

Maybe this is a bit pessimistic, but if you put yourself in the place of a person who in the 50s moved from a communal apartment to his own house - even if a small five-story one, which we now dismissively call “Khrushchev” - this resettlement gave him much more happiness and joy in life than any beauty that he could be hung from above.

The beauty and clarity of the code is not exactly the same. The clearest code is code that is not there. The smaller the code, the better. The code of a hundred lines is clearer than the code of 10,000 lines, no matter how beautifully and magically the second one was written. This is the first. Secondly, it seems to me that clarity and general understanding of the code is like sex. In the sense that it is better not to engage alone.


Vladimir Ivanov
Programs 30 years. In Yandex - 22 years.

He started working as a Yandex programmer several years before the start of Yandex itself. In 1992, from what it was, I collected five computers into a local network - at night, out of curiosity. When Yandex was allocated to a separate company, it moved to the network and for a long time managed all the NOCs. Now he is programming again - for the most part things related to working with the network. Of the projects that have come out, one can name FastDNS in Yandex Browser . Deeply understanding the imperfection of the world, it is easy to rewrite the whole world.

Vladimir Ivanov

Whether the code should be beautiful depends, of course, on the context. Probably, the washing machine code may not be very beautiful, because not many people write it. And when a lot of people are involved in the project, the code should at least not be very nasty. What is a dirty room in which cigarette butts creak under their feet, this is probably understandable. The code may also be the one you want to run away from, yes. And where a person has a feeling of rejection, I do not want to work.

Probably, the code should be to some extent beautiful, and to some degree decent. In beautiful letters, you can write some utter nonsense. And it happens ... That is, it is not only indents, of course.


Anatoly Anatolix Orlov
Programs 25 years. In Yandex - 9 years.

The first two years in Yandex wrote the Market, then "he made the St. Petersburg office a little bit", he was engaged in a search for a long time - mainly by its performance, and then the rest. Now he is engaged in various projects in the field of speed, architecture, etc. They say that Anatolix is ​​the most cunning of Yandex programmers.

Anatoly orlov

Recently, I took a course in neuroscience at Curser. In it, people were put in an MRI, showed pictures, and asked to say which ones are beautiful and which ones are not. Then the researchers looked at which areas of the brain are activated by the participants. In short, at the sight of a beautiful picture, that area of ​​the brain, which is responsible for what you can eat, is activated, and at the sight of a bad picture, the area that is responsible for escaping is activated. Beautiful code is a code that is suitable for food, and from which you do not want to run as far as possible.

Everyone wants beautiful code. More seriously, in practice, in large systems, the perfect beautiful code is impossible. The code should not be disgusting, because the disgusting code cannot be used. And you will need to spend time to bring it back to normal. But ideally beautiful code is also some time spent. Teams do not have time to lick it.


Anton pg83 Samokhvalov
Programs 18 years. In Yandex - 9 years.

Nine years ago I came to Yandex Market as an ordinary C ++ programmer. He worked on various tasks of the service - there were very few of us then. A few years later I moved to search, where I took up the reliability and performance of the runtime search. He worked a lot on our meta-search, robotic trap, load balancing system. Now he is working on an assembly system that will allow us to collect our entire code base in a few minutes on a large distributed cluster. Anton belongs to a group of programmers who say they write right away without errors. Only, it seems, he does so, and not only speaks.

Anton Samokhvalov

Beautiful code is a minimalistic code. This means that it should not do anything extra in addition to the task that we are actually trying to solve with this code. To avoid spreading noodles, but simply a clear concise description of the thought that exists. That's what a beautiful code is.

The code should be readable, but that does not make it beautiful. I have seen a very readable code, which, from my point of view, is not beautiful.

Oddly enough, the code probably does not have to be beautiful. Beauty is a good quality of his, but completely optional. The code, first of all, must be well-functioning, be understandable to people who read it, not be excessively complex for the problem to be solved. Will he be beautiful? It would be nice if he was beautiful at the same time, but in principle it is not necessary.


Andrey Gulin
Programs 25 years. In Yandex - 9 years.

Came to Yandex programmer in C ++. The first task was to remake the format of the inverted index to write information about the exact form of the word in the documents (only the lemma was stored before). One of the main creators of Matrixnet , our machine learning technology. Now leads the ranking service. If Knut had not written his three-volume book, it would be worth giving this work to Andrey. Andrew himself to the question of what he does in Yandex, replied: "I work at the computer and do all sorts of things so that everyone is good."

Andrey Gulin

I do not know what a beautiful code is. Beautiful is some kind of aesthetic category. Does it fit on the screen, does the image resemble. It is difficult for me to operate with these concepts. They do not really interest me, to be honest.

The best code is one that does not exist. So if you already had to write the code, then something went wrong. But if you write it, write so that it is easy to read. Because if a person is unpleasant to read your code, then you tried in vain. In general, writing code takes 10% of the time, and the remaining 90% is reading what has already been written. Therefore, I do not know if a beautiful code is needed, but a well-readable code is important.

The unreadable code is usually written by new developers. And, of course, we have to deal with this when we recruit new people or when we download something from the Internet. Despite the fact that it is useful, and we could use it, someone wrote everything so that it is impossible to read, the variable names consist of one letter, and the efforts that need to be spent on reading are comparable to writing everything. again. Therefore, this code, of course, ugly. Beautiful is a clear code, and especially beautiful code that is not.

That is, if you managed to simplify the problem and solve it by a method that is not much worse or even better, then this is undoubtedly a gain. If you have a system and you managed to erase half of it, this is a great celebration to celebrate. If you can avoid the invention of a complex method, then so be it. If simple linear search works fast enough, then fine.


Andrey Mishchenko
Programs 24 years. In Yandex - 9 years.

He came to Yandex as a developer in C ++, for a long time was the head of the Blog Search Development and wrote in Perl. Andrey is a Candidate of Physical and Mathematical Sciences. Now he is working with Andrey Gulin on improving machine learning algorithms in search.

Andrey Mishchenko

For me, the main feature of a beautiful code is flexibility. What is his development potential? When you do a task that is complicated and changes right under your feet, you want to avoid redrawing the half-project every time. You make changes in several places - everything is ready. The code must be provided in advance for all growth points. I believe that the programmer should turn the feeling of beauty precisely in this direction.

It can be trained. Show the programmer a beautiful code, teach him to admire him. And then a trained sense of beauty will help make the right architectural decisions. They will look beautiful to you.

And I think that it’s right to arrange spaces, which variable names to give, for which files to expand your project and into which daddies, I think is vanity. You have to be above this: as you agree with your colleagues, so do. Let others argue about this.


Anton anton Volnuhin
Programs 23 years. In Yandex - 8 years.

The programmer who solves problems in the shortest way. Came to Yandex in 2006 as a project manager. For many years, he was the head of the Blog Search service. Now he is in charge of the technology distribution team: “I try to make everyone aware of how many cool technologies there are in Yandex, and increase the quality of technology stories and an understanding of their importance in Russia as a whole”.

Anton Volnukhin

It seems to me that the term “beautiful code” means two different things. People who have recently programmed one beautiful code, but for those who have been doing this for a long time and stumbled upon a lot, another. The first is an aesthetic that falls on some abstract representations of beauty in my head, and if this happens, it seems that the code is perfect. And the other is when the code performs its role well and will be understood, for example, by one hundred people who will read this code after me. And this often turns out to be very different codes.

Whether the code should be beautiful depends on a particular goal. In general, it seems to me that yes. People should strive for what they themselves like. And beautiful code is something they like. If people write something, in their opinion, unpleasant and terrible, they will not like what they do. Then, for example, and Yandex will be bad. So everyone should strive to write beautiful code, but with some corrections that occur over the years in their heads.


Gregory Bobuk Bakunov
Programs 25 years. In Yandex - 10 years.

When asked what he does in Yandex, he replied: "To everyone." Once came to work as a system administrator, and now - director of technology distribution.

Grigory bakunov

Beautiful code is for me two completely different categories. An algorithmic solution can be beautiful - and this is one story. And maybe, for example, some beautiful trick. For example, in ancient times, in order to quickly clear a piece of memory, there was really a quick-fast pushing by just an assembler command to push, because the push worked faster than filling it through registers. And it was just a beautiful trick. Beautiful tricks in industrial programming - in the place where we are talking about serious loads, some big serious decisions - most often there is no place. But there is always a place for beautiful algorithms. And, of course, the code should be beautiful and everyone should know that the code is power.

The main task of the code is to solve the task that has been set for it. The most important thing the code has to do is work. Can be broken down into stages. First, the code should be compiled (if it is code in compiled languages), then it should pass tests, then it should work. And finally, if this is a code addressed to the user, he should please him. That is, the code performs a huge number of different tasks. Should the code please the programmer himself? Well, of course, should. Otherwise, why should he actually work as a programmer? Not for the money, we all work here, right?


These are the opinions I collected. In fact, they differ only in what code everyone considers beautiful. The most important thing, with which everyone agrees, and of which no one doubts so, the code should work. And what matters is how your colleagues will work with your code. Surely you have your own point of view in this matter. I wonder if she is different. Tell us in the comments.

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


All Articles