“Programming is better than sex”



At the dawn of my career, I heard this phrase from the head of the ACS department of one of the Soviet factories when he offered to go to work in his department.

Naturally, then I didn’t think, and now I don’t think that programming can be a substitute for good sex. But only after years, was he able to fully appreciate the depth of emotions that he put into his catch phrase. Including because I myself sometimes feel trembling feelings when creating the perfect architecture or beautiful program code. And although the concept of beauty for each person may have his own, but the craving for perfection is the same for everyone.

However, emotions are one thing and the man engineer reasonable, it is different. And I have long been interested in the question, but what is the real reason why I want to make the code beautiful?

Anyone interested in thinking about the rationale for finding the beautiful in software development and in other technical disciplines, I ask under cat.

Foreword


The impetus for writing this article was the recent material on Habr " Stop already fearing subjectively beautiful decisions in the code - you are not robots, " in which the author tries to substantiate his intuitive craving for creating beautiful code.

However, judging by the comments on that article, not all readers share the author’s arguments at the level of “engineering chuyka”. Although there are consonants with such an argument:
“Of course, the code should be beautiful. Christmas trees, sticks, EVERYTHING in life should be beautiful! Otherwise, if something is ugly, you can reinforced concrete say "this is a bug" (sometimes you have to live with it, but it is a bug!) "
True, others suggest resisting the inner voice and not delaying the start of treatment for "pathological perfectionism, which may be a form of obsession, compulsions or OCD."

But if we discard banter and jokes, then the phenomenon of craving for beauty has been noticed since ancient times and is not alien to any of the technical disciplines. After all, it is unlikely that anyone will argue that the result of the work of an architect or an engineer in the design of automobiles cannot be both technical and aesthetic perfection.





But for me, software development is closer, which will be discussed later.

Sacraments of the software creation process


Software development can be approached from different angles. On the one hand, this is a purely technical discipline that does not allow liberties, built on a tough and consistent approach to development. This is a long-established and debugged process, which includes the collection of requirements, the development of technical specifications, planning, monitoring the implementation of plans, execution of the results obtained, etc.

Another option for developing a software product is reckless Agile, which spits on conventions and extols customer desires. He is ready to remake at least every iteration the architecture of the software product in an attempt to achieve the desired result. Such a method is more like the art of striking a balance between getting working software and a complete exhaustion of trust and customer resources.

And only with time you begin to understand that common truths are much more flexible. And in a clear waterfall there is a bit of flexibility, and in Agile there are plans and deadlines. Therefore, the truth, as always, is somewhere in between.

But all this applies only to the external side of the work process. And the saddest thing is that creating beautiful code in no way depends on it.

Moreover, the same code can be recognized as beautiful and ugly at the same time! And this means that the concepts of beauty are purely individual (who would doubt it). What is beautiful code, and how to write it? , The results of the 20th International Competition of unknown code on the C .

Therefore, I had to dig deeper, to the base of this process. In the direction of the developer’s personal identity, which can act as a programmer, architect, tester, analyst, or even be all of them at once at the same time or at different points in time.

So what drives these cogs, in small companies and large corporations, in the soulless machines of the software industry?

Of course, the search for a driving force cannot do without psychology.

What is the driving force?


No, I'm not going to quote scientific papers on psychology or personal motivation. Now anyone, if desired, will find many articles on these topics.

I was interested in the classification of motivating reasons that motivate developers to create program code. Since there was a hope that in this it is possible to find the reason for the developers’ craving, sometimes evaluate the source from an aesthetic point of view.

Unfortunately, I didn’t meet such a classification (maybe I didn’t find it or wasn’t looking there), therefore, as a result of analyzing my own experience and communicating with my colleagues, I decided to independently identify the following types of motivation for developers with conventional names: Material , Social and Internal .

Material motivation


This type of motivation is based on economic incentives. The developer does not care what and how to write. He will try to adhere to the approved coding style in the project and he does not care about the beauty of the code. Accordingly, the evaluation of the results of work (both their own and the results of the work of colleagues) will take place from a formalized point of view, where there is no place for aesthetics.

Social motivation


In this case, the main criterion for evaluating the results of work is the opinion of the team, which may be work colleagues, friends at the university, etc. Moreover, the assessment is made not only by formal criteria for compliance with the coding style. There is already an emotional component, an abstract criterion of beauty.

And it’s already becoming important for the developer that the result of his work should be first of all accepted and approved by the team, and material reasons may go by the wayside. In the most advanced cases, the developer is ready to write code even “for food”, in order to satisfy a sense of self-worth among the target group or in his social environment.

Intrinsic motivation


Such motivation is very similar to social, only the evaluating factor is not the team, but the developer himself. With internal motivation, material incentives are completely absent, and the result of the work may never be published at all, because he has already brought (or continues to bring) satisfaction to his author simply by the very fact of his existence and does not require any confirmatory assessment from the outside.

Of course, such a separation of motives for programmers is conditional and can flow from one type to another or even be a combination of several motivating factors.

But if you look at the result of the work of programmers from this point of view, then in such a classification system you can already find some logic and try to find beauty in almost any source code (program from the IOCCC contest ):

typedef unsigned char t;t*F="%c",l[]="|\\/=_ \n](.\0(),*(.(=(}*.)[[*.",N='\n',*
r;typedef(*H)();extern H Ar;Q(a){return(a|-a)>>31;}H S(c,a){return(H)(a&~c|(int
)Ar&c);}extern t*ist;V(t*u){*u^=*u&2^(*u>>7)*185;}Z(t*u,t n){*u-=n;}e(t c,H h){
R(h,Q(*                                                                 r^c));}
I(){r=l                                                                 +7-4*Q(
getchar                                                                 ()^*l);
}R(H h,                int                                              c){Ar=S
(c,h);-                main()                                           ;}P(){r
++;}z()                {                                                O(&N);}
O(t*c){                    printf(                                      F,+*c);
}T(){r=                        "This is not a function\n"               ;}w(U){
U=Z(r,8                    );                                           r-=~Q(*
r/8-4);	                   return 0;                                    }M(){r=
ist-68;                }                                                h(){t G
=r[1]-r                                                                 [2]^*r;
G^=30;V                                                                 (&G);e(
0,(O(&G                                                                 ),P(P(*
r++)),z));}g(){M();R(h,0);}f(){P(O(r));e('f',g);}p(){P();e('a',f);}d(){P(O(r));
e('n',p);}c(u){u=r[-2];T(Ar=d);R(f,Q(u^'"'));}n(){e(w(O(l+*r%8)),c);}a(){I();R(
n,0);}main(){S(Q(Ar),a)();}H              Ar;t*ist="Rene Magritte"-(1898-1967);

When a joke makes you think


Initially, this article was written as a joke, and its name speaks for itself, so the picture was chosen accordingly.

Imagine my surprise when I realized that the formulated classification of motives for craving programmers for beauty reminds me very much of something. These motifs are very clearly projected onto Maslow's famous pyramid of needs.



Material motivation closes the need for the foundation of the pyramid. These are physiological and safety needs. Social motivation falls in the middle of the pyramid and leads to the satisfaction of needs for belonging, love and recognition. And finally, Intrinsic Motivation very clearly projected to the very top of the pyramid and closes the need for knowledge, aesthetics and self-actualization.

Is this not a joke?


As a result of a not serious attempt to study cravings for beauty among programmers, quite reasonable conclusions were obtained which, if desired, can be used in the software development industry.

Indeed, in the case of the emergence of a real methodology for assessing the beauty of code from the point of view of motivation, it will not be difficult to add it to various utilities for evaluating the coding style, such as pylint, cpplint and other lint. And after that it will be possible to assess the motivation of specific developers without conducting any psychological tests and filling out boring questionnaires. It will be enough to pass their code through the analyzer.

Perhaps I even let the genie out of the bottle, because if it becomes possible to measure motivation by the created code, then the next natural step will be the transition to its management. Indeed, this method of assessing motivation is very easily automated, and where there is an opportunity for operational measurement, there is also the opportunity for operational management of the measured parameter.

In other words, the availability of operational information on the mental state of team members for project managers will help them evaluate the results of attempts to shift motivation towards social or internal motives, naturally, to save on economic incentives. ;-)

UPDATE 1: I will leave a link to the sketch fromjanvarevon the topic of the article: Sergey and “programming is better than sex”

UPDATE 2:
According to the first results of the voting, a tendency emerged to vote mainly for intrinsic motivation (145 - 60.3%). But before choosing the third option when voting, please consider this: Who sets the criteria for quality (or aesthetics) in your project?

If you are a team leader, architect, or other person who accepts or significantly influences the rules for determining such an assessment, then your choice is the right one.

But if your contribution to the formation of code quality criteria is insignificant (for example, such criteria were determined even before you joined the project), but everything suits you completely, then most likely you are in harmony with internal and social motivation, but when interviewed, the right choice vote for the second option i.e. social motivation.

To verify this unequivocally, imagine a situation in which you have a bad "black" mood and the result of work (the program code written at that time) corresponds to it. Will your commit be approved? If yes, even if you do not fully comply with accepted quality criteria, then your motivation is really Internal. But if your code is rejected, then your motivation is still Social, although usually it is in harmony with the Internal.

All Articles