Behind every mountain of code is a bunch of R&D people who are familiar with code specifications.

Click the link to learn more

img


Introduction

Han Han wrote in "His Country": "We know a lot of truths, but we still can't live this life well." Although people know a lot of truths, they may not be able to apply these truths to real life. This phenomenon is very common in life. We have heard a lot of principles about success, but in fact, success and happiness cannot be achieved only by relying on these principles. It requires continuous efforts and practice to achieve your goals. In the development process, we will encounter similar problems. Although we have read "Code Cleanliness" well, we can still only write inefficient code. The industry often ridicules that "an excellent programmer can create employment for many people". What is missing among these? How to implement it quickly? This article will analyze it from several aspects. Welcome to read it.

Table of contents

1 time pressure

2 Business needs

3 Self-motivation

4 Teamwork and communication

5 Technical Debt

6 Automation tools and processes

7 Feedback and improvement mechanisms

8 personal implementation cases

01 Time pressure

During development, projects may have tight deadlines that need to be completed within a limited time. This may lead to time pressure, and during the development process, you may encounter some unforeseen delays and problems, such as technical difficulties, system failures, etc., which will lead to compression of development time. It makes it difficult for developers to spend enough time writing high-quality code.

img

Solution:

**▶︎Plan and manage time properly: **Before the project starts, develop a detailed project plan and schedule, and allocate time to each task reasonably. Make sure you give yourself enough time to write quality code.

**▶︎Priority management: ** Set the priority of tasks reasonably according to the importance and urgency of the task. Focus your time and energy on the most important tasks and make sure they are completed first.

**▶︎Ask for help and support: **If time pressure is too much, you can seek help and support from your superiors or team leaders. They may provide additional resources or adjust project plans to take the pressure off developers.

**▶︎Self-management and adjustment:** Developers need to learn to self-manage and adjust, and arrange work and rest time reasonably. Avoid overwork and fatigue, maintain physical and mental health, and improve work efficiency.

**▶︎Look for opportunities to optimize time: **During the development process, look for opportunities to optimize time. For example, using code templates, reusing existing code, leveraging open source libraries, etc. can reduce development time.

02 Changes in business requirements

During the software development process, business requirements may not be fully specified or may change frequently. This may result in developers needing to modify code frequently without enough time to refactor and optimize code quality.

img

Solution:

**▶︎Strengthen demand analysis and clarification: **Work closely with customers or project managers to ensure that requirements are fully analyzed and clarified. Reduce demand ambiguity and reduce the frequency of demand changes through detailed demand documents, user stories, prototypes, etc.

**▶︎Frequent communication and feedback: **Maintain frequent communication and feedback with customers or project managers. Provide timely updates on project progress to keep clients or project managers informed of development progress and possible impacts. This can reduce the frequency of demand changes and adjust the development plan in a timely manner.

**▶︎Agile development methods: **Adopting agile development methods, such as Scrum or Kanban, can better respond to changes in requirements. Through iterative development and short-cycle releases, requirements changes can be responded to in a timely manner and time pressure can be reduced.

**▶︎Requirement change management: **Establish a good requirement change management mechanism. Evaluate and prioritize requirements changes to ensure only truly important and urgent changes are accepted, and update development plans in a timely manner.

**▶︎Risk management and buffer time: **In the project plan, consider the risk of demand changes and set aside a certain buffer time for this. This allows for possible changes and reduces time pressure.

03 Self-motivation

Although developers know the importance of code cleanliness and code quality, they may lack the self-motivation to proactively improve their coding skills. They may be more focused on completing the task than on code quality.

img

Solution:

**▶︎Find the meaning and value of work: **Think deeply about the meaning and value of development work, and clarify your career goals and development direction. By understanding the importance of your work, you can inspire self-motivation to pursue high-quality code.

**▶︎Set clear goals and plans: **Set clear goals and plans and break the development process into small manageable tasks. By gradually completing these tasks, you can gradually improve the quality of your code and enhance your self-motivation.

**▶︎Enhance self-confidence: **Enhance self-confidence through continuous learning and improvement of your technical abilities. Participating in training, reading books, participating in open source projects, etc. can improve your professional knowledge and skills, so that you can confidently write high-quality code.

04 Teamwork and communication

In a team, without common code cleanliness standards and code quality awareness, it may be difficult for developers to maintain consistent code quality across projects. Lack of effective communication and collaboration can also affect the implementation of clean code.

img

Solution:

**▶︎ Develop unified code clean standards: ** The project team should develop unified code clean standards and clarify the naming standards, coding style, comment standards, etc. of the code. You can refer to industry best practices and coding standards, such as Google's coding standards, Clean Code, etc.

**▶︎Establish a code review mechanism: **Introduce a code review mechanism into the project to detect and correct code quality problems in a timely manner through inspection and review of the code. Code review can be done through code review tools or manually.

**▶︎Establish a knowledge sharing and exchange mechanism: **Establish an open knowledge sharing and exchange platform so that developers can learn from each other and exchange experiences. Technology sharing sessions, team building activities, etc. can be organized to promote cooperation and learning among developers.

**▶︎Reward and recognize excellent code quality: **For developers who perform well in the project, rewards and recognition can be given to motivate them to maintain high-quality code. This can be an incentive mechanism for developers to become more aware of code quality.

05 Technical Debt

During the development process, due to some reasons, developers may take some expedient measures and temporarily sacrifice code quality to meet needs. These stopgap measures can lead to the accumulation of technical debt, making the code increasingly difficult to maintain and improve over time. As follows:

int x = 10;int y = 0;int result = x / y; // 上面代码显然没有考虑处理除以 0 的情况,这种类似的情况还有很多。// 改进思路:int x = 10;int y = 0;if (y != 0) {    int result = x / y; // 添加条件判断,避免除以 0 的错误} else {    // 错误处理逻辑,如输出错误信息或者抛出异常}

img

Improvement methods and ideas:

**▶︎Phaseled delivery and iterative development: **Decompose the project into multiple phases, each phase has clear delivery goals. Through iterative development, some functions are delivered in time to reduce time pressure and avoid sacrificing code quality.

**▶︎Technical Debt Management: **Identify and record technical debt in a timely manner and incorporate it into the planning and management of the project. In the subsequent development process, technical debt is gradually paid off and code quality is improved.

**▶︎Technology selection and technology evaluation: **Before the start of the project, conduct sufficient technology selection and technology evaluation to select a technology stack that suits the project needs. Avoid later maintenance difficulties caused by improper technology selection.

**▶︎Code review and refactoring: ** Conduct regular code reviews to discover and correct code quality problems in a timely manner. At the later stage of the project, you can consider code refactoring to improve the readability, maintainability and scalability of the code.

06 Automation tools and processes

The lack of automated tools and processes can make it difficult to check for code cleanliness and code quality. Developers may need to manually conduct code review and testing, increasing workload and the possibility of errors.

img

Solution:

**▶︎Use automated tools: **Choose appropriate automated tools to assist in checking code cleanliness and code quality. For example, use static code analysis tools (such as SonarQube, ESLint, PMD, etc.) to check code specifications and potential problems. Use unit testing frameworks (such as JUnit, pytest, etc.) to automate testing of code. These tools can help developers reduce manual work and improve code quality.

**▶︎Continuous integration and continuous delivery: **Introduce the process of continuous integration and continuous delivery to automate the build, test and deployment process. Through automated processes, code quality issues can be discovered and fixed promptly, reducing manual work and the possibility of errors.

07 Feedback and improvement mechanism

If developers do not receive timely feedback on code quality and opportunities for improvement, they may not be aware of their problems and fail to improve their coding.

img

**▶︎Code quality assessment and feedback: **Establish a code quality assessment and feedback mechanism to regularly evaluate developers' code and provide timely feedback. Static code analysis tools, code reviews, and other methods can be used to evaluate code quality and provide developers with improvement suggestions and guidance.

**▶︎Learning and training opportunities: **Provide learning and training opportunities to help developers improve their coding skills. Internal training, technology sharing sessions and other activities can be organized to allow developers to learn and share best practices and experiences.

**▶︎Mentor system: **Establish a mentor system to provide guidance and support to developers. Experienced developers can serve as mentors, collaborating and communicating with novice developers to help them improve their coding skills.

**▶︎Code review and teamwork: **Establish a mechanism for code review and teamwork. Through code review and team discussions, developers can learn and improve from each other. Regular code review meetings can be held to allow developers to share their code and receive reviews and suggestions from other developers.

**▶︎Provide Challenges and Opportunities: **Provide developers with challenges and opportunities to participate in complex and challenging projects. By participating in projects like this, developers can learn and grow and improve their coding skills.

08 Personal implementation cases

It was the second company I joined after graduation, and I took over the "Shit Mountain Code" of my departed colleague. There was only one comment on the entire project, "Buddha bless you, there will never be bugs." There is no standard in the code, and the variables are all named aabb. My boss asked me to give a schedule as soon as possible. The project is going online. I thought to myself, "I'll run away quickly!", and I said bluntly: "There is no standard for this project as a whole. He Maybe you can’t even understand it, and I can’t even understand it.” Later, I reluctantly went online, but there were many problems and my performance was a mess. I was thinking about how to develop code and locate problems efficiently? And implemented it quickly in this project I am working on.

img

▶︎ "The code is like a mountain of shit". It is impossible for me to fix the specification problems bit by bit. Is there any suitable tool that can remind you where there are more problems? After I used multiple tools, I found that CheckStyle is the best one I have ever used. Code specification checking tool, which uses sun's specifications. (Later, with the help of other colleagues, we jointly worked out a version of the company's own standards).

▶︎Slowly afterwards, the quality of my positioning of problems and code development became higher and higher, and my performance also improved a lot. In some sharing meetings, I put forward my own suggestions, and the leaders recognized these results, and finally established the "Code "Standardization Group" has established some normative systems:

Developers review each other's code, and the main line can only be merged after no less than two people have reviewed it. People who ask questions can be rewarded. Those who "develop problematic code" will be punished (enforcement starts after two months). You can also ask questions about other projects (Background: The company is smaller, and the projects are more numerous and complex. The rewards for this are relatively large, and it takes up more of your personal time. The choice is all up to you, and there are no hard requirements). Mentor system: If the newly hired employees they lead have excellent code quality or good performance, the mentors will be rewarded. Sharing session: Developers will take turns to share and find some open source code or classic cases to interpret.

After about a year of iteration, the low-quality code gradually disappeared. When I reviewed the process later, I found that there was some luck. I met a good leader and a group of excellent colleagues. Of course, it was also inseparable from my own efforts. If I had not thought about improving my code standards to quickly If you don't solve the problem properly, the leaders will not see the importance of code standards, let alone promote the construction of team code standards.

Finally, I want to tell you that when we see these "shit mountains of code", we should secretly laugh, congratulate ourselves for achieving high performance first, and then push the team to formulate code specifications and effective measures based on the actual situation and the above analysis. Put it into practice and implement it concretely. Hope everyone can be seen.

-End-

Original author|Kong Chuihang

img

Guess you like

Origin blog.csdn.net/CODING_devops/article/details/132857961