Often software developers are involved in research and development where they get enough time to learn new technologies and align with the best practices and the standards defined in the official documentation.
On the other hand, most software developers are in a situation where the delivery of the code is more important than the quality of code. Yes, you heard this right.
These are the situations when a software developer like me or even you will end up making blunders either due to a lack of knowledge of the underlying code or the requirement.
With my experience as a software engineer, I have made plenty of mistakes and have seen other developers making mistakes leading to a huge problem. Just to make you realize how big of a problem a software bug can create, here is an incident that happened due to a software bug — Airbus issues software bug alert after fatal plane crash according to The Guardian report.
I have identified the top 3 mistakes that a software developer does when writing a code —
1. Stop Copying Code Blindly
Google helps us all in its own way. Software developers often come across issues in their code or look up solutions online from various sources like — StackOverflow, official documentation of library/package, npm docs, etc.
Sometimes even I realize it is better to take code already available and make it work. This is where a software developer tends to make a mistake. Here are few things that can happen if one is copying code directly —
- Copied code requires all the necessary edits to actually make it work. If missed doing so, it can fail the process terribly when running the code.
- Many developers don’t even realize the risk of copyright. The code being copied might have copyrights and the owners can easily claim royalty or even file a lawsuit.
- The last outcome that can happen is, copied code may work in one environment and fails in another. Since it is copied, it will become hard to find the right solution.
Here is something I suggest you follow when taking any piece of code from online sources —
Always look for copyright/license text. There are types of licenses that will allow you to use the code but with some restrictions, hence act accordingly.
Make sure the source is legit. This means it is possible the source from which you are taking code might have taken from other sources and again can cause licensing troubles. Try to visit the official pages for most of your code references, that wait will be much safer.
2. Stop Using Exception Handling Everywhere
Most of the time I see new developers using generic exceptions almost everywhere. This again is not required. Here is when you should use exceptions —
- When a piece of code invokes an outside API call, Use a generic exception or the exception that is documented in the API docs.
- Use generic exception only when it can cause serious issues like terminating a script/process.
- Use exception handling when debugging your code.
You can reduce the number of exception handling by doing one simple thing — Identifying permanent errors and fixing them in your codebase, hence not requiring to add any exception handling for that piece of code.
3. Test Your Code In Multiple Stages
I have seen many times when a code break is mainly because it was tested in one environment but not in the target environment. For example, a software developer writing code and testing in a development environment and not testing in Production/Non-Production environments.
Yes, this is a very serious issue. How can a software developer for sure that the code works? The only way is to ensure this is to run it in the target environment and check if any discrepancies are observed.
An ideal way to ensure this is avoided is — Create multiple environments other than development environments. Individual environments will be tested by a separated group of members. For example, there can be three environments-
- Development — Software developers will code and unit test the software
- Non-Production/Test Environments — A team of testers will perform tests based on acceptance criteria defined by the actual users
- Production — A team from the User end will perform tests and provide feedback.
Once the code is tested in all these environments with flying colors, only then a software developer’s code is ensured as OK.
More About The Author😄
I am a full-time software engineer with 4+ years of experience in Python, AWS, and many more technologies. I have started writing recently as it helps me to read more. I am looking forward to sharing technical knowledge and my life experiences with people out there.
Register Here for my Programming Weekly newsletter where I share interesting tutorials, python libraries, aws , and tools, etc.