[Directory Post] Good coding habits to improve efficiency

Programmer, why are you so tired?


 
First of all, thank the author for sharing, the original text

 

When everyone mentions programmers, the first thing that comes to mind is the following labels: hard work, overtime, staying up all night. However, as all working classmates know, in fact, most programmers do very simple things. The code CRUD can be said to have no technical content . Even if thread concurrency is high-tech, the threshold for programmers is actually relatively low. (Most of them are mentioned here, some of them are awesome, please skip automatically if you write algorithms, jvm, etc.)

Do you feel that it is very contradictory, on the one hand, the work is not complicated, on the other hand, it is exhausted . Ever wonder where the problem is? Ever wonder where you spend your time?

For me personally, coding is still a relatively easy job (I am in charge of the company's it system, there is not much technical content, the amount of data is large, but the amount of concurrency is not large). From work to the present, I still have relatively little overtime coding time. I still code every day until now, and I rarely work overtime because of coding work.

What everyone writes is some crud business logic code, why are everyone so tired, working overtime and working overtime every day are strugglers? From the observation of the projects I brought, I found that most people spend most of their time locating the problem + changing the code , and there is not much time for real development. Positioning problems include problems found during development and testing and problems found after going online. Code changes include bug changes and code changes due to changes in requirements (a special post will be posted later on how to deal with changes in requirements).

So, simple is not easy. Many people just think it's simple, so it's ok if the function is completed and tested by themselves, and they don't think about whether there is a better way. In the final analysis, it is because the coding habits are too bad and the code written is too bad, which makes it impossible to locate frequent modifications and frequent problems . (I'll go into more detail about most of the coding problems I see later.)

In fact, for individuals, technology is very important , but for work, coding habits are more important than technology . Most of the techniques you interview for at a job don't need to be used. At work, because your coding habits are not good, the quality of the code you write is poor, the code is redundant and repetitive, and a lot of irrelevant code is mixed with business code, causing you to struggle with all kinds of problems.

So as an SE (system architect) , no matter I take over any project team, the first step is to formulate the code framework , formulate the development specifications of the project team, and reduce the amount of code . In fact, it has been proved that after this step, everyone's code volume can be reduced by at least 1/3, the number of problems in the background has dropped significantly, and everyone's overtime will be less than before .

 

Let me give you an intuitive example. The following is an interface of the controller to delete data. It looks like what everyone wrote before I came (in fact, it was much worse than this at the beginning). The function is very simple. Enter an object id to delete it and return whether the deletion is successful. Do you think there is any problem?

 

In fact, the above code is not a big problem. And after I take over, I will develop my own code framework , and finally the code delivered by the code framework is as follows (this is the controller part):

 

 

The technology used is AOP , and it is not an advanced technology. how about it? The amount of code is only one line , and none of the features are lost . This is what our project team's controller looks like now! (If there happened to be someone in the project team I took, they should be familiar with ResultBean<> and know who I am), so it doesn't matter how high or low the technology is, it depends on how you use it.

The above code briefly explains the problem:

(1) First, lang has nothing to do with business, and the code framework behind me has been removed (not that my code behind does not have this function, but it is hidden and transparent to developers, and the technology used is ThreadLocal ).

(2) Second, the previous code actually only works on one line , and the rest has nothing to do with the business code, and I can't see it in my code framework at all .

The technology used is really simple, but the coding effect is very good, because everyone should not feel that it is not important because the technology used is elementary! ! After using this framework, you no longer need to write some boring code most of the time , and you can spend more time learning other technologies. To be honest, the developers in my project team are relatively lucky and feel that they can learn something. They are not like other project teams who have written the same CRUD code for a few years. Although I am strict, they are still willing to stay with me. The project team, after all, works less overtime than other project teams.

This is what I mean at work, where coding habits (or coding style) are more important than skills. I have been working for a long time, and I think these are the places where I have the greatest personal value. In fact, I understand the same technology as everyone else, but I still think that I can surpass most people in coding. Later, I will write down the coding problems of our business systems one by one, and share my solutions.

 

 

The initial issues are as follows:

  1.          Interface Definition Specification

  2.          controller specification

  3.          log specification

  4.          Exception Handling Specification

  5.          Internationalization Specifications

  6.          Parameter verification specification

  7.          Tool class specification

  8.          Function writing advice

  9.          Configuration Recommendations

Install the Ali Protocol plugin

 

These specifications are not the programming specifications on the Internet. To be honest, which ones are long and cumbersome, and it has proved difficult to implement in practice. The specifications here are relatively few. Stay tuned!

 

 

 

 

 

 

 

 

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326218654&siteId=291194637