During my career as a programmer, I have repeatedly come across the fact that programmers do not know how to write code. And this may concern both beginners and already very experienced people. Honestly, in my opinion there are units that really know how to do it. I do not pretend to complete the coverage of the problem and the fact that my opinion is correct, but I will consider it from my point of view.
In my opinion, there is not and cannot be a single standard, and every person is free to choose and adapt their own approaches to programming. But there is a set of practices that helps in the vast majority of cases.
First of all, I would like to turn to the primary sources of the problem. What is wrong and why you need to change something. I think that the dream of every programmer is to write code as quickly and as beautifully as possible, and that everything should work clearly the first time. This will allow more often to read chips and drink coffee with testers, for particularly ardent ones it will give more time to develop themselves as a specialist.
One of the main differences between a professional programmer and a beginner is the system of priorities. As a rule, it is not very difficult to make the code work; it is much more difficult to make it understandable (of course, it is desirable that it also remain working). Therefore, a professional often spends more time refactoring than debugging, which is good in itself, but I would also like to reduce the refactoring time to a minimum.
So the main ideas that can help write code better.
Have an idea
In any of your implementations, there should be an idea; it’s like a line that runs through all the functionality and ties it together. Before you sit down to write something, you should more or less imagine how it will all work, what blocks there are, how they interact with each other. Do not sit down to write just like that, think up a concept, and more interesting, and often the resulting code will become clearer. Naturally, having already invented something, you should stay within the framework of this concept as much as possible, you should not change everything at the first problems, there will always be problems. Also, do not be lazy and with the words, "oh well, and so will drag" stick some kind of plug. It will not lead to good.
There is no ideal
And of course I want him to be, but he is at 99. (9)% no. You should not try to make the code perfect, it will turn out even worse to spend much more time. It's just a struggle with windmills, yet we are paid for the fact that our application works and for how it is elegantly written. Often, the search for the ideal leads to constant changes of concepts, endless rewriting of the same, ultimately annoying, the person throws everything, stops all the plugs and “oh well and so drags”. It should be good and convenient, the ideal is not the lot of engineers, this is the lot of poets, but programmers are still engineers.
')
Keep focus
One of the main problems especially for beginners is digging into details. It is necessary to focus on 1 task per unit of time. What I want to say is that you are writing some function, stumble upon some not easy moment with which you need to figure it out. In most cases, you know that this problem is solved 100%, but you do not know how. If you switch to its solution, you will get off the focus of the current problem, then in order to return you will have to spend time, context switching has never been a free operation. This idea also applies to implementation details. Suppose you need to write a function that reads some data from the database and writes it to a file. That is your context. Solve this problem then solve the rest (ie reading from the database and writing to the file). Initially we write the following:
var data = Read();
Write(data);
2 Read Write, alt+shift+f10, ( f1, f1 , ). . -, . , , . , . , . .
, . , . , - , . , , , , . , !
, . . result, , , , . var ( ). i,d,v,k , . currentNode n ? , . , .
? ? ?
. ? ? ? ? ? ? . , .
, , . . , . . , . , , ? ? .
— , , - .
— , . , , . .
— , , . , .
, C# ( ), , PHP, C++, Delphi, C# . ( ).
, - , . . , . “ , ” . , .