Top Newbie Programming Mistakes
Learn from other people’s mistakes in programming now so you don’t make them
Some mistakes which most newbies and even some experienced folks (like me) make while writing code and how you can avoid them.
0. Putting everything into one file
This is the most common mistake you would see a lot of programmers making, writing all their code in one Class/file.
One of the major reasons behind this that we learn most of the coding through video tutorials where most of the authors intention is to explain you the concept/logic and not really around how to structure your code.
Hence, learn to separate out your code into various classes, and move those classes into different files/projects to give a better structure to your project.
1. Not / Manually formatting code
I have seen many people not giving enough emphasis on formatting their code by leaving out blank lines between different logical parts, not intending nested code blocks etc.
While others manually spend their times Tabbing/Spacing left and right, and sometimes leaving way too many blank lines in code for no reason.
Most of the IDEs nowadays comes with auto-formatting tools at your disposal which you can use format your code in a standard way, make sure you enable them and assign friendly shortcuts to always keep your code well-formatted.
2. Not knowing your tools
Just adding to the above point, know what are the plugins/shortcuts you can use to supercharge your development and save yourself those seconds of time of manually triggering certain action in your IDE.
Try to know what tools your senior devs/other devs in the community use to be more efficient.
Try to automate a lot of your work where you can, you are a programmer!
For example, when you are done writing your code, you might be spending a significant amount of time building the packaged app and deploying it manually to store/servers.
Why not explore CICD tools which can save you hours of time during your project life-span? So all you do is to push your code to Git and then you know that it will be automatically be shipped to your users.
3. Leaving comments, commenting the code unnecessarily.
- As beginner developers, we tend to leave a lot of comments with the intention to explain the code to the future selves.
- Many times we are just afraid to delete a block of code so we just comment it out thinking we will use it in the future.
Both of these practices are wrong and you should try to minimize the number of comments you leave in your code.
No comments would be the bests case scenario, but you may ask then how would you explain your complex code to somebody who might be reading it in the future?
The answer would be not to write complex code which needs comments to explain it. Code is like a joke, if you have to explain it, it’s not good enough.
I would highly encourage you to check out this story if you want to know more about this point.
4. Too many logs
Leaving too many log/print statements in your code. I understand as beginners to understand the flow of the program we used to add log statements, but leaving them in your project’s codebase is a big no-no.
Secondly, try to anticipate the program flow yourself first and then run it, if something goes wrong to try to exercise your mind by doing a dry run and then add only a limited number of log statements and see if you were right or not.
This little exercise will help you develop more confidence in yourself and your critical thinking rather than just blindly following the logs to pinpoint issues.
As always, remember to delete/disable the logs before you push your code to production. Maybe explore a better logging library for your project?
5. Thinking only for the short term
Many times I have seen myself/other developers making this mistake. We sometimes write code just to meet the short term deadlines.
For example, if there are 10 yellow buttons in your app in different places, many newbies would just assign each one of them the hex colour for yellow and it would just work.
But later, when changes come in to make those buttons Blue instead of Yellow, the devs would then open all those 10 different locations in code and make the changes.
The point being, make sure your code is always easy to change with minimum efforts in the long run. Ask yourself if a change like that would come, how would you want to make if effective across your project in less time.
That’s also another good way to exercise critical thinking before writing code.
6. Running the code after every line of code
This is what will make you very inefficient as a developer. For many developers, in the beginning, we are in a habit of running our code frequently to make sure everything is working as expected as we write more code.
But that is not a good practice as you are not critically thinking about the flow of your code. Hence, try to dry run the flow of your logic in your brain while you are coding and then just run the code at certain intervals to validate your expectations.
7. Copy-pasting code, which you don’t understand.
All jokes aside, we programmers can’t afford to have code in production which we don’t really understand. Hence, whenever you are implementing a feature by copy-pasting the code from some website make sure you do give your time to understand it.
Maybe build a small POC first where you try to change the code to see how it responds to those changes and then you add it to your codebase.
Also, it's a great practice if you can have test cases written before you actually add the foreign code to your repository.
8. Not Knowing/Applying the right Data Structures
We all learn about Data Structures in our Computer Science course but I have many people not being able to identify the scenarios, in their codebase, where they can apply a map instead of a list to actually fetch a record in constant time.
Applying the right data structure can actually make your life/code a lot easier and bring better performance to your app/system which is always appreciated.
9. Not knowing the basic ‘Clean Code’ practices
This is something your co-workers/team-mates will appreciate a lot, the sooner you learn and apply some basic clean code principles to your code the better off you will be in your career.
I would highly encourage you to read the book “Clean Code principles by Robert C. Martin”.
You can also check out this story to learn more about Clean Code.
10. Large Unorganised Commits
Just like the code, your git commits should also be atomic to one feature that you worked on. Your commits should be adding/fixing/improving only a particular part of your project instead of everything all over the place.
This can happen because you might be making your commits in large intervals and that's why they may seem all over the place. Better make your commits more frequent so that they cover a smaller portion of changes in code.
11. Not Knowing/Applying the right Design Patterns
As beginners, we might not be able to implement the right architecture to our app and that is why we have Design Patterns which give you a standard framework that you can follow to give your app an industry-known architecture.
If you haven't learned about Design patterns yet, I would highly encourage you to do so, they would make you a better programmer.
Once you get comfortable and can evaluate the pros and cons of each architecture as per your app needs, maybe you can create and validate your own patterns like a pro.
12. Ignoring the Value of Testing
I think the amount of emphasis a programmer gives to writing test cases can be the biggest differentiator between a pro and a newbie.
Writing test cases is one of the most important investments that you can make for your project.
Writing tests give you an automated test suite to validate your project’s integrity when you would be making changes in your code over time.
Check out this story to learn more about testing and its importance.
13. Pushing non-relevant resources/data to git
As beginners when we learn about git, we tend to push almost all the files in our project to the remote git but that isn’t the best practice as we might be pushing certain project files which need not be pushed.
There can be certain files containing sensitive information about your credentials/API keys etc which again are not to be pushed to git.
So make sure you learn about the .gitingore file and also about environment variables.
I feel this is a great tool to generate your .gitingore files.
Those are some of the top things I would suggest beginners to avoid. What are your thoughts? Share your experiences and views. I would love to hear from you in the responses.
Thanks for reading ✌️