[Translation] 13 simply outstanding encoding rules (from my 15 years of experience)

Original Address: HTTPS: //hackernoon.com/few-si ...

clipboard.png

Hi, I work as a programmer for over 15 years, and using many different languages, examples, frameworks and other dog feces. I would like to share my rules written code.

VS optimization optimize readability fuck

Always easy to read and write coding for developers understandable code. Because the time and resources spent on the hard-readable code is much higher than would be obtained from the optimization.
If you need to be optimized, so as to make it independent modules DI, with 100 percent test coverage, and will not be touched at least one year.

The first architecture

I see a lot of people say, "We need to do something fast, we do not have time to do architecture." Of which about 99 percent of people because of this idea encountered a big problem.
Write code regardless of its architecture is of no use, as there is no plan to achieve them, as dreams you desire.
Before writing the first line of code, you should understand what it will do, how it will use, how module, service work with each other, what structure it, how to test and debug, and how to update.

Test coverage

Testing is a good thing, but they are not always affordable, the project makes sense.

When you need to test:

  • When you write a module, micro service will not be touched at least one month.
  • When you write open source code.
  • When the core code or code you write involving financial channels.
  • When you have updated code while updating the resource tests.

When you need to test:

  • When you're a business.
  • When you have a small team and code changes are fast.
  • When you write a script, you can output simply by their manual testing.

Remember 带有严格测试的代码可能比没有测试的代码更有害that .

Keep it simple, extremely simple

Do not write complex code. More and more simple, then it may have fewer errors and less time to debug them. Code should do is that it does not need a lot of abstract and other OOP shit (especially involving java developers) + 20% of what might be required in a simple way to update it in the future.

Note

Explanatory Notes appears that your code is not good enough. Good code should be understandable, there is no line comment. But how to save time for a new developer? - write simple inline documentation describing what and how the method works. This will save a lot of time to understand, and even more - it will give people more opportunities to come up with better implementation of this approach. And it will be a good start for the world of code documentation.

Hard small coupling coupled VS

Always try to use the micro-service architecture. Monolithic software can run faster than the micro-service software, but only in the context of running a server.
Micro service allows you not only on many servers, and sometimes even on a single machine (I mean the process of distribution) efficiently distribute your software.

Code review

Code reviews can be good, and so the bad.
You can organize a code review, only if you have 95% of developers to understand the code, who can monitor all updates, without wasting a lot of time. In other cases, it will be just time-consuming, everyone will hate this.

In this section there are a lot of problems, so the more in-depth description of this.

Many people believe that code review is a good way to teach a novice, or work in different parts of the code teammate. But the main goal is to keep the code review code quality, rather than teaching. Let's imagine your team make the code used to control the cooling system of a nuclear reactor or a space rocket engine. You made a huge mistake in logic very hard, and then you give this guy a new code review. How do you think the risk of accidents happen? - I practice more than 70%.

Good team is that everyone has their own role, responsible for precise work. If someone wants to understand another piece of code, so he went to a responsible ask him. You can not know everything, and better quality of understanding and not understanding all the pieces of code.

Reconstruction futile

In my career, I have heard many times, "Do not worry, we will reconstruct it later." In the future, this technology will lead to a large debt or delete all the code from scratch and writing.

So, do not get a debt unless you have money to develop your software from scratch several times.

When you are tired or in a bad mood do not write code.

When developers are tired, they are making 2-5 times or more bug. So more work is very bad practice. That's why more and more countries think six hours working day, some of them already have. Instead of using mental work your biceps.

Do not write all the time - the development iterations

Before writing code analysis and forecasting, your clients / customers really what you need, then you can choose to develop high-quality in the short term MVF (most valuable features). The use of such an iterative update to deploy quality, not waist time and resources and desire and sacrifice the quality of the irrational.

Automated Manual VS

Automation is a 100% long-term success. So if you have the resources to automate things that should be done now. You might think that "only takes five minutes, why should I automate? But let me calculate this. For example, it is a daily task five developers. 5 minutes 5 days 21 days * 12 months = 6 300 minutes = 105 hours = ~5250 $ 13.125 days.
If you have 40,000 employees, how much it will cost?

The waves go out, learn a new hobby

Differentiated work can increase mental capacity, and to provide new ideas. So, now suspend work out for a breath of fresh air, talking with friends, playing the guitar and so on.
ps: 莫春者,春服既成,冠者五六人,童子六七人,浴乎沂,风乎舞雩,咏而归。------《论语.先进》。

clipboard.png

Learning new things in my spare time

当人们停止学习时,他们开始退化。

Guess you like

Origin www.cnblogs.com/baimeishaoxia/p/12550087.html