Writing good code is a habit that comes from mixing several approaches and changing practices by learning from your own experiences. And mostly its about thinking psemistic. There is no happy programmer because there are infinity ways to break your code, all you need to look for is to cover all the pit falls by following best practices.
This is th crucial part because you have time to think before starting any real coding and it becomes impossible to change the modules if you start in a wrong direction. So, its always better to think a lot before starting. Think end-to-end implementation no matter how small or bit it is. Here is what I do,
- Gather all requirements from client regarding the work you need to do.
- Prepare requirement as a story to understand better. Don't go to next step until you understand the requirement.
- Get domain knowledge to understand the requirement and plan development in better way.
- Think of development and server platform: Choose the best fit for the task to be done and be biased when coosing one. Never use what you know or you like, that could e a poor choince in the future.
- Thnik of software packages or modules: Choose what is needed for the work and choose good ones but not those with questionable future because it will become though to scale up or maintain.
- Prepare mitigation plan: Anything from database to payment gateway may go as discontinued or will release new version by making the old one obslete. You need to plan based on the software, modules and packages you choose to develop with.
- Refuse to do poorly designed system unless you get freedom to do it right.
- Most importantly, Reject unrealistic timelines: Unlealistic timelines will go bad in several ways as you may need to deliver unfinished or untested or buggy code. Finally it will ruin your reputation and relation with client.
- First rule of thumb is to never trust what you get as input: Always valiade data you get as much as possible even if it seems useless. Not only data you get as input, even the data user request for is to be validated thoroughly. Most applications gets hacked because of poor validations.
- Never use coding techniques you want to learn and show off. Use whats needed and relevant. For example, my friend was writing all application logic in stored procedure and argued with me that it gives excellent performance boost and he had to write all that again in c# when we wanted to log all code changes.
- Write code as simple and readable as possible, this makes it easy to revise and review at a later stage. And you may be praised by developers who continue development after you.
- Don't reinvent the wheel, use available software modules, packages.
- Always write test cases and those will give you headsup in case of any breaking code changes before your test team identifies.
- Last and most important one is to test what you do, test in each and every possible way you can think of to break and hack your app. Trust me this will ake your app rock solid in terms of security.
- Review your code for speed, stability, security, and usability.
- Monitor application performance.
- Monitor Server performance if you have to.
- Do rolling releases if you can.
- Revisit old code periodically and see what you would've done differently.
Let me know how do you achieve quality programming?