What is beautiful code, and is it needed? What do Yandex think

    Yandex employs more than 6,000 people, and, according to some estimates, more than half of our employees have experience in programming. And of course, each of these people has their own correct opinion about what an ideal code should be.

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

    In order to understand what features of the code different sides advocate, I decided to ask my colleagues, what is beautiful code, and should it be beautiful in the hot pursuit of the next heated discussions? 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.

    Andrey yafinder Plakhov
    Programs for 24 years. Yandex is 6 years old.

    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 the Spectrum system. Candidate of physical and mathematical sciences. Now he runs the search functionality service - in particular, he develops search hints. He deeply understands both technology and user properties of the product.

    Andrey Plakhov

    Asking 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. It is unlikely that the architect will explain to you what a beautiful house is, and if you ask if it should be like that, he, of course, will say what 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 apartments.

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

    The beauty and comprehensibility of the code is not exactly the same thing. The most understandable code is code that does not exist. The less code, the better. The code of one hundred lines is more understandable than the code of 10,000 lines, no matter how beautiful and magical the second is written. This is the first. Secondly, it seems to me that comprehensibility and generally understanding the code is like sex. In the sense that it is better not to do it alone.

    Vladimir Ivanov has been
    programming for 30 years. Yandex is 22 years old.

    He started working as a Yandex programmer a few years before the start of Yandex itself. In 1992, from what was, he collected five computers on a local network - at night, out of curiosity. When Yandex was singled out as a separate company, he switched to network business and for a long time led all the NOCs. Now he is programming again - for the most part, things related to working with the network. Of the projects that were published, you can call FastDNS in Yandex.Browser . Deeply understanding the imperfection of the world, he will easily rewrite the whole world.

    Vladimir Ivanov

    Whether the code should be beautiful depends, of course, on the context. Probably, the code of the washing machine may not be very beautiful, because not many people write it. And when a lot of people participate in the project, the code should be at least not very nasty. What is a dirty room in which cigarette butts creak underfoot, this is probably understandable. The code can 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 beautiful to some extent, and decent to some extent. In beautiful letters, you can write some kind of utter nonsense. But it happens ... That is, it’s not only indents, of course.

    Anatoly anatolix Orlov
    Programs 25 years. Yandex is 9 years old.

    For the first two years, Market wrote on Yandex, then “made a little St. Petersburg office”, for a long time I was engaged in search - mainly its productivity, and then everything else. 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

    I recently took a course in neurobiology at Kurser. People put him in an MRI, showed pictures, and asked to say which of them are beautiful and which are not. Then the researchers looked at which brain areas were activated in the participants. In short, when you see a beautiful picture, that area of ​​the brain that is responsible for what you can eat is activated, and when you see a bad picture, that zone that is responsible for running away. A beautiful code is an edible code that you don’t want to run away from as far as possible.

    Everyone wants a beautiful code. Seriously speaking, in practice on large systems, perfect, beautiful code is not possible. The code should not be disgusting, because disgusting code cannot be used. And you will need to spend time to bring it to normal. But a perfectly beautiful code is also some kind of time spent. The teams do not have time to lick it.

    Anton pg83 Samokhvalov
    Programs for 18 years. Yandex is 9 years old.

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

    Anton Samokhvalov

    Beautiful code is minimalistic code. This means that he should not do anything extra than the task that we are trying to solve with this code. That there was no loose noodles, but simply a clear, concise description of the thought that is. Here is what beautiful code is.

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

    Oddly enough, the code probably does not have to be beautiful. Beauty is its good property, but completely optional. The code, first of all, should be well-functioning, understandable to the people who read it, and not overly complicated for the task being solved. Will he be beautiful at the same time? It would be nice if he was beautiful at the same time, but in principle this is not necessary.

    Andrey Gulin
    Programs for 25 years. Yandex is 9 years old.

    He came to Yandex as a C ++ programmer. The first task was to redo the format of the inverted index in order to record 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 runs the ranking service. If Knut had not written his three-volume, this work would have been worth giving to Andrei. Andrei himself, when asked what he was doing at Yandex, replied: “I work at a computer and do all kinds of things so that everyone is happy.”

    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 it resemble a picture. I find it difficult to operate with these concepts. They don’t really interest me, to be honest.

    The best code is code that doesn't exist. Therefore, if you already had to write code, then something went wrong. But if you are writing it, then write so that it is convenient to read. Because if it is unpleasant for a person 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 don’t know if a beautiful code is needed, but a well-readable code is important.

    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 in such a way that it is impossible to read it, the names of the variables consist of one letter, and the efforts that need to be spent on reading are comparable to writing everything again. Therefore, such a code is, of course, ugly. Beautiful is a clear code, and code that is not beautiful is especially beautiful.

    That is, if you were able 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 big celebration that needs to be celebrated. If you can avoid the invention of a complex method, then this is what you need to do. If a simple linear search is fast enough, then fine.

    Andrey Mishchenko has been
    programming for 24 years. Yandex is 9 years old.

    He came to Yandex as a C ++ developer, for a long time he was the head of the development of Blog Search and wrote in Perl. Andrey is a candidate of physical and mathematical sciences. He is currently working with Andrei Gulin to improve search engine learning algorithms.

    Andrey Mishchenko

    For me, the main feature of beautiful code is flexibility. What is his development potential. When you do a task that is becoming more complicated and changing right under your feet, you want to not have to redo half a project every time. You make changes in several places - everything is ready. All growth points must be foreseen in the code in advance. I believe that the programmer should be turned in this direction a sense of beauty.

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

    And I think the way to put spaces correctly, which names to give to variables, on which files to lay out my project and in which folders, is a fuss. You have to be higher than this: as you agree with your colleagues, do it. Let others argue about this.

    Anton anton Volukhin
    Programming 23 years. Yandex is 8 years old.

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

    Anton Volnukhin

    It seems to me that the term “beautiful code” means two different things. For people who have recently programmed, one thing seems to be beautiful code, but for those who have been doing this for a long time and have come across a lot of things, it’s another. The first one is aesthetic, which rests on some abstract representations of beauty in my head, and if this happens, then it seems that the code is perfect. And the other is when the code performs its role well and will be understandable, for example, to a hundred people who will read this code after me. And these often turn out to be very different codes.

    Whether the code should be beautiful depends on a specific purpose. 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 that they think is unpleasant and terrible, then they will not like what they do. Then, for example, Yandex will be bad. So everyone should strive to write beautiful code, but with some corrections that happen over the years in the head.

    Grigory bobuk Bakunov
    Programs for 25 years. Yandex is 10 years old.

    When asked what he was doing at Yandex, he answered: “To everyone.” Once I came to work as a system administrator, and now I am the Director for Technology Distribution.

    Grigory Bakunov

    Beautiful code can be for me two completely different categories. An algorithmic solution can be beautiful - and this is one story. Or maybe, for example, some beautiful trick. For example, in ancient times, in order to quickly clear a piece of memory, they really quickly and quickly pushed it there simply with the assembler push command, because push worked faster than filling 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 for beautiful algorithms there is always a place. And, of course, the code must be beautiful and everyone should know that the code is power here.

    The main task of the code is to solve the problem that is set for it. The most important thing the code should do is work. Can be broken down into stages. First, the code must compile (if it is code in compiled languages), then it must pass the tests, then it should work. And ultimately, 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? Well, of course it should. Otherwise, why would he actually work as a programmer? Not for the money, we all work here, right?

    These are the opinions I have gathered. In fact, they differ only in what code everyone considers beautiful. Most importantly, what everyone agrees with and no one doubts, the code should work. And what matters will be what your colleagues will work with your code. Surely you have your own point of view on this issue. It is interesting to know if it is different. Tell us in the comments.

    Also popular now: