Thinking as a software engineer

Writing the code is one of our daily jobs as a software engineers. We even can do that on some kind of autopilot (let me know if you have never done that 😏) — we read the user story on our board, open our IDE, we try to remember if we did something like that before, if so, we copy the code, otherwise we look on stackoverflow, copy from there and then we try to adjust the code accordingly. This is not necessarily good or bad, for example, you almost never want to implement custom encryption or other parts in security.
In my opinion it becomes dangerous when transformed into a habit and becomes a daily working routine. That’s one of the main reasons for these ‘smelly’ code pieces to appear, in my opinion, when stackoverflow driven development dominates.

As a result, quite often you can read the code, but barely can understand or worse — suddenly you realise that your node.js server starts to give 503 responses on just 100 simultaneous users load 😰 The trickiest part with this kind of problems is that they appear at runtime under specific conditions and are very difficult to track and eliminate.
So, how do we fight this? Let me list a few practices which help me daily:
- Split the solution of the problem into the logical steps. This will give you a more clear understanding on the approach and will help to handle the details.
- Try to apply Test Driven Development approach when writing the code. If you start with the test first, it requires a clear vision and understanding of the future functionality, simply because you can’t write a test for something you don’t understand. Another benefit is that your code is written with a testability in mind, which greatly impacts the future maintenance.
- Try to keep in mind S.O.L.I.D. principles, no matter on which side(backend/frontend) you are writing the code — dependencies and single responsibility are everywhere! :)
- When writing the code try to ask yourself following questions:
- Is this the most simple way to implement that? (keep it simple stupid principle);
- Is the functionality i’ve just added absolutely necessary? (you aren’t gonna need it principle)
- Do I understand how this code runs?
- Use optimisation and performance increasing technics whenever possible, use caching. This is very important and should be always in mind when developing. Recently i had a case when just usage of Reduxjs/reselect library in necessary places decreased page loading time for 2 seconds.
I can guarantee that usage of these best practices will greatly increase the quality of your code not just in terms of readability and maintenance, but also performance. Your fellow developers will like you more because your code will explain itself, will be easy to support and work with. Life will shine in a completely different colours.😆
GL & HF