I propose to the readers of
Habrakhabr a translation of the publication
“ Scott Shipp.
One of my favorite quotes for all times is Brian Goetz, the cleverest dude from the world of Java, one of the authors of “
Java Concurrency in Practice ”, among other things. The quotation is taken from an interview published on the Oracle website under the heading "
Write a Dumb Code ". Getz was asked how to write well working code.
Here is what he said:
“Often writing fast Java code means writing blunt code — the code is simple, clean, and following the most obvious object-oriented principles.”
The remaining 1000 words explained why attempts to optimize code and attempts to be smart are common programmer errors, novice errors, if you wish.
Code of experienced developers
If you, like me, were once a junior, you may remember how you first investigated the code of the senior and thought: “I can write like that. Why am I not a senior? ”
')
I tried to write such code for a long time, and I did not succeed.
Mysterious in the code of senior was not what I could not understand him, but what I could understand him instantly. He was specifically stupid and it seemed that there must be something else there. I thought, “Where is the rest? How does this code do all this? ”
Since then I have studied the names of all the principles and features of a code that make it stupid: YAGNI, the principle of sole responsibility, DRY, the principle of a single level of abstraction, weak hooking, etc. And I became senior. In fact, I hate the term "senior" and call myself just a software developer, but that's another story.
The main lesson I learned is that writing stupid code is difficult, but it brings an exponential gain.
How to distinguish junior per kilometer
In his book
Refactoring: Improving the Design of Existing Code , Kent Beck says:
“Any fool can write code that the computer can understand. Good programmers write code that people can understand. ”
You can always find out a novice developer by looking at the code full of "smart" one-liners, dubious abstractions and masses of specific language constructs. I would say that the latter is most characteristic. It looks as if the code is trying to say: “Look at me! My creator knows the language perfectly! I use the JavaBean local stream synchronous copy constructor with a default interface and unchecked custom generic exceptions along with the enhanced security JAXB Lombok code generator! ”
Yes, I said nonsense, because the code in the hands of those who think exclusively about the computer side of things instead of the human turns into nonsense.
Code is communication between people
and instructions for a computer, but the first one is significantly larger than the second. The compiler itself takes care of converting what is written by a programmer into machine code. Often there are several layers of such a conversion, for example, when Java is compiled into bytecode, which is read by the virtual machine and eventually translated into zeros and ones.
But code is human language. He explains all the “who”, “what”, “when”, “where”, “how” and “why” tasks, at the same time giving instructions to the computer. It should make sense and five years later, when the company is sold, and the new team, who has never seen this code, will open it for improvement and correction.
Yes, writing stupid code is hard. I am convinced of this more and more over time. I feel satisfied when I receive comments like: “Clean code!” On code review. I know that the best thing I can do for my team and for future code maintainers is to write stupid code.
Here is the thought attributed by Dave Carhart:
“Always code as if the guy who will support your code is an unbridled psychopath, and he knows where you live.”