If every programmer wrote code over and over again, programming would drive many programmers crazy. So how to find fun in boring work, I think we should maintain passion and excitement for work, always learning attitude, but also need to master some practical and efficient programming skills, which is beneficial to improve the fun and efficiency of work. Today the author shares 25 practical programming tips with you in the hope that they can give developers more thought in their work and study.
1. Don’t write code without a plan: Think, research, plan, code, test, modify — nothing less;
2. Don’t over-plan before you write code. A little planning before diving into code is a good thing, but even that can backfire.
3. Don’t underestimate the importance of code quality. If you can focus on only one aspect of your code, it’s readability.
As a professional programmer, your responsibility is not to find a solution to the problem, but to find the simplest solution to the problem;
5. Give up. The moment you start to doubt a solution, consider throwing it out and rethinking the problem. No matter how much effort you’ve put into the solution. Take advantage of a version control system like GIT, which can help you separate and try out different solutions;
6. Google well. Unless you’re using cutting-edge technology, when you have a problem, chances are someone else has already had the same problem and found a solution. Save yourself some time by googling;
7. Encapsulate well. The basic idea is that you want your code to be highly cohesive and low coupled, which means keeping related code together (in a class) and reducing the interdependence between different classes.
8. Plan well, write requirements before writing code, and write as little code as possible for the solution currently being implemented;
9. Understand algorithms and use appropriate data structures;
10. Don’t write repetitive code, use configuration files, and don’t use unnecessary conditional statements and temporary variables.
11. Comment code, but don’t comment code that fools know.
12. Be sure to write tests well. If possible, you should begin to anticipate and design the situations that need to be tested and validated before you even start writing code to implement requirements. Test-driven Development (TDD) is not just some fancy hype, it actually has a positive impact on how you think about features and look for better designs.
13. Don’t assume that the code works correctly. Sometimes a bug in the code may not be obvious.
14. To be able to question existing code, as a beginner, always assume that code that you can’t read and isn’t documented is probably bad code. Use git blame to find the culprit!
15. Don’t obsess over best practices. I think “best practices” are actually harmful, implying that you don’t need to dig into it.
16. Don’t get obsessed with performance optimizations. If you’re optimizing code before you run it, chances are you’re optimizing code too early, and you’re spending too much time and effort optimizing code that isn’t necessary.
17. Aim for user experience and put yourself in the position of the end user. Professional developers should consider what users need and how to use a particular feature, and try to make it easy for users to discover and use, rather than trying to find the most convenient way to add the feature in the application, regardless of the discoverability and availability of the feature.
18. Pick the right tools for your development task. You can build a house with primitive tools and have a good time. You can also spend some time and money learning about advanced tools to build better houses faster. Tools are constantly evolving, and you should be willing to learn them and use them.
19. Understand the relationship between code problems and data problems. Even the smallest bug in a program can cause the data it manages to fall into an unpredictable state. Especially when all data validation is done entirely in this buggy program.
20. Don’t reinvent the wheel. Use existing wheels and open source libraries. Of course, don’t introduce an entire codebase just to use one or two functions, a classic example in JavaScript is the LoDash codebase;
21. Keep your code reviews in perspective. Treat every code review as a learning opportunity, welcome them, appreciate them, learn from them, and most importantly, thank your code reviewers when you learn from them;
22. Novice users often underestimate the power of a good version control system, and by good version control, I mean Git;
23. Do not overuse shared state, a novice might try to use timers to solve the race condition problem for shared variables, especially if they have to deal with a data lock. Don’t do it. Pay attention to it. Point it out in code reviews.
24. Face Error. Error is a good thing. Error means you are making progress, and it means you can make more progress by simply making subsequent changes. Professional programmers love errors. Novices hate Error;
25. Learn to rest. Everyone’s brain needs rest, and so does their body.
What language do you write in?
I write a Python!