The world is going through a trying phase and COVID-19 has affected us all.
The pandemic has forced many businesses to stop working, a lot of people have lost their jobs and everyone has been restricted to working from home.
Remote working has kept the work alive at least for the developer community but it also comes with a lot of cons.
The biggest setback of working from home is that you can no longer interact with your teammate as frequently as it was when you are sitting just next to each other. This causes a lot of miscommunication, that ultimately leads to a lot of rework and sometimes extended working hours. You can no longer keep track of the work being done by your peers, which can sometimes lead to poor code quality, or untested code getting deployed.
At this point, you might be thinking that this is a small issue which can be resolved in a minutes time and the worry surrounding this is unnecessary. This is the main issue with developers across the world. We are used to fixing bugs and issues frequently and we avoid taking measures to prevent these minor issues from happening. As a result, we lose precious time in fixing minor issues which could have been saved at the very early stages.
Any savings ultimately leads to saving time.
- Karl Marks
And let’s face it, we always prefer to develop new features than fixing our own silly bugs.
That’s why I decided to note down some of the issues which happen frequently and can be avoided by following some basic guidelines which are already available across the internet.
I’ve listed some of the very basic (yet often skipped) day to day practices which we can follow to improve our work quality and write clean and bug-free codes below.
Explore your IDE
Most of the modern-day IDE’s like Visual Studio Code and IntelliJ IDEA etc provides a lot of cool yet helpful features which we generally miss/avoid because we never tried to explore something new.
Using Code Snippets with Visual Studio Code.
- Using Code Snippets
Suppose we need to create a service or a helper class to hold certain methods, and we need to do that very frequently and all of them follows a similar pattern. Hence you need to keep on writing everything again and again.
Also, we cannot rely on the framework’s CLI to generate boilerplates for us every time, taking Angular 8 as an example if you follow a custom project structure.
In these cases, we can make use of code snippets either as a plugin or writing one of our own and you can even publish it for others too.
Follow this to create your custom code snippets using VS Code if you haven’t don’t it yet.
- Using Shortcuts
Do you still use a cursor and mouse clicks to search a file in your project directory? Or do you still need to use a new terminal window to enter commands and to use git related operations? If it is yes, then you can easily avoid this old school habit now. Almost all the IDEs provide a set of shortcuts for you to save your time to perform those operations, in fact, you can create your own key combinations as well.
Some IDEs like IntelliJ provides us with the option to import shortcuts from other IDEs so that you can use utilise the power of their product with the shortcuts of your preference and get hands-on with the IDE. Isn’t that amazing?
- Using Linters & Formatters
When you are working in a team there is a big chance that you and your peer follow a different standard this can happen mostly because of the previous work or technology we have followed. In the software world, you cannot rely on just only technology need to be flexible enough to pick and grasp any new technology at any point in time. So if your hypothetical team has one member with prior Java experience and one with Python expertise clubbed together to develop software with NodeJS (that escalated quickly). This won’t affect the code’s performance but the standard which both the devs follow can make your code look very inconsistent.
And here code linter and formatter can help you standardise your code quality and make sure all the best practices are followed even after you are no longer working on that codebase.
ESHint & TSLint are some of the famous linters, which you can configure easily and it also allows you to create your own rules.
Similarly, you can Prettier to format your code written in VSC.
Utilising the Power of Git
Git is vast and mighty. I am specifically mentioning Git here, knowing the fact that the majority of the developers uses git as their primary version control system. But if you are using something else then also you can follow these guidelines to maintain your code in a better way.
- Proper commit messages
Most of the devs take commit message for granted. But think of a situation where you need to create changelogs for a particular release and we all know how painful it is to create such notes with a disturbed commit history or untagged codebase. Hence we should keep a note that every code that is pushed to your VCS has a proper and user-friendly message and every release is tagged.
- Keeping release branch separate
This is a very debatable subject but to make sure only tested and working code goes live we should maintain a separate release branch and avoid pushing codes directly to it, no matter if it hurts your ego.
- Make sure your local branches are in sync with the remote ones
In most of the cases, two or even more developers are using a specific branch while developing certain features, but we often forget to sync the local branch with the remote one which leads to codes getting overridden.
Hence we need to keep it in our practice to sync our local branch with the remote ones.
- Merge, Pull, Rebase or Cherry pick?
Guys this is the best time to improve our command on git system, Atlassian provides a very interactive doc to cover this topic if you are still not used to it then you should read a little more about it. Again, this will help you maintain and keep your git history clean.
- READ YOUR PEERS CODE
The best way to get learn some new things while working on a project and stay up to date of your project is to make sure you read your peers code whenever you get some time so even if they in their unavailability you can take the charge to continue on his work. Also learn to accept and take review comments in a positive way if it is made to improve your code. There is no shame in learning anything new.
Again the way of writing a piece of code can vary from one person to another, but what matters the most is your code should be not only machine-friendly but also user friendly. Following are few points which can be used to make your code user friendly.
- Adding Docs and Comments
Writing a piece of code is not a big thing, to be honest, but if your code is not easily readable, people will avoid using it and it will be of no use at the end. We need to keep this mind that our code needs to be reusable and extensible enough to be easily used by other developers in future.
Documenting your code is essential to make it easier for other devs to understand your work quickly and save time.
If your code involved some research, or if you have taken reference from some online forum like StackOverflow etc, then attach the link of that paper, solution as well in the doc/comment, that way you can make sure it will be made available to everyone and they’ll get to learn something new.
- Writing test cases
Yes, I know. Why should you “A Developer” should do something for which your employer had hired a tester. So let me clear your thoughts about why unit tests are important and should be written by a developer.
Suppose you need to have a tightly coupled code, and you need to introduce an update or maybe a new feature in one of them.
How can you make sure that the one single change which you did won’t affect other modules? Especially for those days when we need to keep pushing frequent changes.
We have serval libraries available for almost the programming languages which can be used to write code level test cases which can again be either unit, integration or functional.
Some good testing frameworks which I have used includes JUnit, Mockito, Spock for Java/Groovy and Jest, Enzyme for Frontend.
- Prefer adding migration scripts to update your database
No matter how small an issue is, if it requires a change in the database, do not do it manually. Always make sure changes in the DB has been made only using migration script so that in future you can trace down when a particular change was done, and also if a script fails, then the fallback script should automatically rollback the changes.
- Follow official coding standards made available by the creators or use third party code, and make sure your code is DRY and Maintainable.
These are some add-ons from my end, which are again optional but can be handy at certain times.
- Automate your repetitive work as much as you can
We do need to follow a set of rules which are often repetitive, and time taking if performed one by one. Also, a huge chance of missing out a step can cause an issue. One of the best example we can take at this moment is the deployment and release process. No matter if we are managing our own servers or using modern-day serverless techniques, deployment and releasing needs to be done with proper care no matter how many times you have done it in the past.
If you have knowledge of any scripting language you can easily write a script to do these tasks for you. I personally prefer writing a bash script to take care of my automation process. Some possible use-cases can be:
1. Deploying code to your server.
2. Taking database backups on a regular basis.
3. Generating a signed APK.
4. Updating your SSL certificates
5. Invalidating Cache at regular periods etc.
- Read documentations whenever you have time, and stay updated with the changelogs of the technology which you are using.
- Using productivity management tools
These are my personal favourite tools which I frequently use to manage my daily work.
1. Todoist: To keep track of my daily work, and reminders.
2. Trello: Keep track of known bugs and product roadmaps.
3. Toggl: To keep track of the time I took to complete some work.
And that’s all, although I have a lot to share but concluding it for now.
If you have some thoughts or feel I have missed anything. Then I have created one Github repo to hold all possible best practices at one place.
It is open source so feel free to contribute and let the community grow.
Hope you enjoyed this blog and will extract a lot of good practices from this lengthy blog post.
Happy Coding, Stay Safe and Keep washing your hands. :)