Program Efficiently, Not Carelessly
6 tips for refining your efficiency as a programmer
1. Pseudocode
You might be an experienced programmer, but you can probably admit you don’t do this.
Now you may ask: “What exactly is pseudocode?” Pseudocode is basically a plan for what you’ll work on in your program. It’s a tentative blueprint that explains every step you need to take in reaching some goal. Pseudocode should, in my opinion, always be written in plain English. I’ve seen people writing pseudocode that is practically nothing but actual code. That might work for some people, but it can get very confusing very fast.
Pseudocode lets you solve your problem with pre-written steps, which, first of all, makes the workload as well as the overall complexity look a lot less, and second, saves you time because you can now prioritize certain parts and leave some to work on another time.
2. Writing More Comments
People either do this to a minimal extent or not at all. This goes hand in hand with writing pseudocode. While pseudocode is the general blueprint for the big steps in the program, comments are the brief, in-depth explanations behind the individual lines of code.
If you want to understand what you did and not have to remember every step, then you’ll have to take a little extra time to explain why you wrote that line of code, why you created this class, a d why you have to use that function. How and why this is so important. You have to ask yourself these questions and answer them in the form of comments alongside your code.
This what programming is all about. Being able to write meaningful code that you can go back to, comprehend, and explain to yourself as well as others.
“Programs must be written for people to read, and only incidentally for machines to execute.”
— Harold Abelson
3. Debugging
Do you remember that tiny bug icon at the top corner of your shell? If not, you’re just like thousands of other programmers, including me only a few months ago, who are missing out on a breakthrough that has been around for longer than you can remember.
Debugging. It is just a term that describes scouring code and fixing bugs, or errors, from your code. However, we don’t have to do this while relying on only our human intellect. The debug button in your shell allows you to run your program interactively while watching each variable along with others parts of your code changing as the program runs. You’re essentially telling a computer to explain to you their thinking and reasoning behind the output provided.
Anytime you’re dealing with an error and have absolutely no idea why or how that error came up, the solution is debugging, specifically the debugging feature. You can see exactly what line your program went wrong in, and you can fix those errors much faster.
4. Run, Run, Run!
A grave mistake programmers make is when they write a huge amount of code under the impression that it will execute smoothly when they run it. If you do this, you’re only making things harder for yourself.
The more you test something, the less prone it is to errors, which leads to a higher overall efficiency rate. Run your program after every step. If you created a function, call the function and see if it actually works.
Please don’t wait till it’s too late to test your program. You don’t want your own creation confusing you. This will help you in the long run. Don’t carry these bad habits when you are doing full stack development.
5. Doing Frequent Exercises/Challenges
I can’t stress this enough. Doing short exercises here and there is key to refining your programming knowledge. These exercises give you chances to apply past-learned concepts to complex logic-based situations or to discover gaps in your knowledge.
For some free and addictive programming challenges, I recommend looking into Edabit. It has over 10,000 interactive programming challenges in 8 languages: Python, Java, JavaScript, Ruby, Swift, PHP, C++, and C# (No, I’m not being sponsored). It’s a great website for all ages and backgrounds. I highly recommend you sign up.
This is for beginners, so if you’re confident in your programming and problem-solving abilities, consider bing-solving leetcode questions.
6. Taking Breaks
This seems pretty intuitive. Unfortunately, many people ignore it. It’s simple. Take breaks. We all know how hard it is to leave your screen while in deep thought, but think about it like this. What’s more important: you’re sanity or getting something done? Go outside. Get some air. Take a short walk. Direct your attention to something else, something less important. Don’t tire yourself too much. You won’t work efficiently if you’re stressed, frustrated, tired, or anxious.
When you have gained some peace, put a smile on your face, and get back to work.
“I’m not a great programmer; I’m just a good programmer with great habits.”
— Kent Beck