When you start out as a programmer, you can easily fall into the habit of following bad practices while programming.
As a programmer, you can't avoid mistakes and that's part of learning your programming lessons. You'll make many mistakes in your career - some unique, some common ones - and that's how you'll learn to avoid them in future.
But if you are a beginner, you'll likely make some mistakes more often than others. How do you avoid these common mistakes that many programmers do everyday?
To avoid any mistake, you've to become aware of it. And that's why I would like to share with you some common mistakes that many of us still do that keeps us from growing as a programmer.
But before I share that with you, you may want to know how do I know that these are mistakes and not the right methods?
There is a simple answer - I have done all of them at some point in my career. Some more often, while some only a few times. And I regretted doing them later.
But I didn't knew then that I was doing anything wrong by following such bad practices. Once I realized that I was doing the wrong thing I started avoiding them. And now my code is at least better than what I wrote before.
And you too can avoid doing such mistakes. Part of the solution is just to realize that what you're doing is wrong. I know that most programmers won't do anything wrong, if they knew right then that their actions can have a negative impact on their application and their professional growth.
Most of our wrong programming habits are due to our ignorance and nothing else.
To become a good programmer, we have to remove these ignorances one by one. And that's what good programming books try to show us.
Part of the reason that we do such mistakes is because they do get the work done. And isn't that what we are payed to do - make our programs run, and finish our day's work.
But to make something work is only part of your job. If your application is any good, you'll have to update it regularly, and fix any new bugs that may arise from time to time. And then the only thing that'll make your work easier is following good programming practices.
Also, while you can get away with such mistakes in small programs, you simply can't afford them when you make bigger applications.
If you still do them, your application may work and do the needful tasks. But it'll be buggy, full of unoptimized code, and hard to maintain. And even you'll find it difficult to understand the code, when you look at it after long time.
As programmers our job isn't just to make our applications work and let the users deal with the bugs. Our job is to make sure that there is no way users get undesired results even if they give it wrong input.
So to create high-quality applications, make sure you don't do these common mistakes while programming:
Copy-pasting code without understanding it
Often you'll find that the code you are looking for is already available in some other program. It's very tempting to copy the code entirely and use it as it is, without bothering to understand each and every line of it.
Sometimes, the code you are copying may be so large that you don't have time to understand it completely. If you copy any code this way, there is a risk of making your applications vulnerable and buggy.
While this may get the job done, but what if the code does some undesirable activities in the background. What if it slows down your application or does some malicious activity. For that you need to understand the code properly, or you need to be absolutely sure of the source from which you copied your code.
And if any bugs do arise later, you'll find it hard to understand the code as you didn't even write it. And you'll find it hard to trace out a bug and fix it, especially if you copy lots of code at different places in your program.
So be careful when you copy even a little piece of code. Make sure you understand it completely. If you have already used a piece of code before and are 100% sure about the way it runs, then it's safe to copy it. But otherwise be cautious.
Starting from scratch every time
This goes exactly opposite to what I said before but it's another mistake that many beginners do. You may think that it's best to start from scratch every time you create a new application. But that's a huge waste of resources - your time, energy, and mind - that can be better used elsewhere.
If something you need to do is already out there, use it and make your job easier. There is no need to reinvent the same basic concepts again and again.
You can use the same time to make your application more better in other aspects.
If an API, framework, or game engine eases your task, there is no reason you shouldn't use it. Your goal shouldn't be to show off how talented you are, and how you can do everything on your own without anyone's help. Your goal should be to make sure that your application works perfectly, and it takes as little resources as possible to create it.
This way you can do the same work in less time and save tens or even hundreds of hours. And as time is money, even if you work for yourself, you earn more for the same amount of time.
Searching google without trying yourself
Many times, by habit, as soon as you come across a new problem, you hit google and search for solutions. This isn't the way to become a good programmer. If you always search for solutions outside, without even trying once on your own, you'll never challenge your mind.
When you stop challenging your mind, you stop growing those programming skills inside you. To become good at any skill you have to solve new problems on your own. That applies to programming too.
Else you'll only create what's already there. You'll never create any original work. Is that something you want to do?
While it's smart to look for existing solutions, but if you blindly do it, your laziness will stop you from becoming a better programmer. Even if you do want to look for solutions, it's alright, but first at least spend some time and think upon the problem.
Maybe you can solve it on your own without wasting much time. Maybe you can solve it in a better way than what others have done. Maybe your solution is more accurate than the other ones.
You'll never know these if you don't try.
This is another mistake that I did earlier while developing applications. I can't tell you what a huge difference it makes when your application shows a hundred warnings and when it doesn't show even one - the most important being the ease with which you can recognize new problems.
Warnings are a sign that you are potentially trying to do something that may not work every time. Sometimes, these warnings aren't serious and it's safe to ignore them. But the real problem comes when you have a big application that shows hundreds of warnings, and something doesn't work right.
It becomes difficult to find the cause of that error. And you have to spend more time to analyze each warning and to find the root cause of the problem. Instead it's always better to resolve any warning issues at the start itself, as soon as they arise.
And usually you just need to use the right variables or functions to resolve most warnings. It doesn't take hours to do so; mostly a few minutes, if you remove them as soon as you come across them.
Try to remove any warnings as early as possible. A clean code not only looks good but works good too. Just remember the old saying - treat warnings as errors.
Making Quick fixes instead of Permanent ones
Yes. I am guilty of doing this one too. And I am not proud of it. So often, we just come up with a quick fix that's barely enough to solve the problem at hand.
And it works and makes the problem go away. But if you aren't careful it ends up coming back again and again in different ways.
Whenever you fix a problem, make sure that it doesn't break the system in any way. A fix should improve the overall working of a system, not make it slower or more bulkier.
Also, make a fix that'll solve the problem permanently. Think of long-term, not just short-term. Sometimes, due to our laziness or ignorance, we just want to do our work quickly, instead of spending more time on it. And that's why we write code that does the intended work, but might not work in all possible scenarios.
If you skip on doing your work now, you'll only have to work even more on that problem later.
Just knowing these above mistakes can help you in avoiding them. If you know what you're doing is wrong, most times you won't do it.
And to do a good job you should love what you do. If you don't like programming for some reason then you'll rarely take the extra steps that are needed to write good, maintainable programs.
And if you do intend to write such good programs then you need to change the way you look at programming.
Think of programming as an art and yourself as an artist. Then you'll never make this mistake of being lazy or careless.
Would a writer write incomplete article and publish it? Would a painter leave his painting incomplete and sell it? Would a singer just sing any useless words between his songs?
The same applies to programming. Don't write incomplete code that doesn't test all scenarios. Don't leave your application unfinished and ship it. Don't write useless code if you can do without it.
These are just some basic mistakes that we do, because we are tempted to do less work and do something else. But we can't go far with this approach. Sooner or later, you have to become responsible for your work and make sure that there is no flaw in your code.
The sooner you start practicing the right programming methods, the better it'll be for you and your users. Sometimes being a good programmer means just to make sure that you don't do the same mistakes that bad programmers do.
Thanks for reading this post. If you know anyone who unknowingly follows such programming practices please share this post with them and help them become a better programmer.