How to Easily Write Algorithms: My Tip for Beginners
The method I was using when I started programming.
I notice that many newbies say they have difficulty producing an algorithm to solve a given problem. And if we dig a little deeper into this problem, we realize that the cause of the problem is often not what we really think.
When a beginner starts to program, he learned many things from the beginning, such as algorithms, the first programming language, and various tools to produce, track, version, or debug code.
And generally, the learning of each of the parts is done individually, that is to say, that we learn the theory and put into practice what we learn individually without considering the rest as in most training.
And that is the whole problem because a beginner hardly masters what he has just learned. When he has to make everything he has learned individually work in perfect harmony, panic and destabilization assured, how to ask a beginner to be operational in mastering his entire ecosystem to make it work in perfect harmony. It’s impossible!
As a beginner, the reflex you will have is to practice what you have learned: an algorithm on paper that you will reread several times to optimize. Then, once it’s finalized and you think it’s good (no one to correct you, and as we say on paper, it always works), you will translate your paper algorithm into your programming language.
You find that your translation from paper to your language is quite tedious because it doesn’t work the way you want, and you have to go over it again to make it work. In short, it takes a long time to do, it’s a waste of time, and you will experience a great drop in motivation and enthusiasm. It’s guaranteed. Especially since you will try to apply everything you have learned as you are asked.
So how do you go about producing an algorithm easily and quickly when you are just starting without fully mastering your work environment?
Let me share with you the method I was using when I started programming. It’s simple and amazing but so effective for me because it’s about focusing on one thing at a time.
Take the first draft of your algorithm.
As I described above, the problem when a beginner is that you do not have the experience and mastery of your work environment and what you have learned in general. So you are too preoccupied with putting everything you learned into practice rather than with the problem to be solved in a totally unconscious way.
Consider first the substance and then the form of the problem. Concentrate only on the given problem, and don’t worry about what you are not yet familiar with.
Write your algorithm directly in your programming language as you think and feel. Let your imagination run wild and forget about good practices and wanting to make the most of your work environment!
The advantage of doing this step is that you will stay focused on solving your problem. You will only think of this to stay focused and use all your gray matter to write a functional algorithm quickly.
If you don’t feel comfortable producing your algorithm directly, you can outline it on paper as a guide, but I’m sure you will be able to do it directly in your programming language. Realize that once you’ve done that, the hardest part will be behind you.
Everything becomes clearer
Have you noticed that we tend to criticize and judge someone’s work very easily when we have it in front of us? That it’s easier to do it on something that exists rather than something that doesn’t?
We say to ourselves, but “why did he do things like this” or “I would rather have done it this way.” Some things literally jump out at us to pinpoint parts that don’t suit us, like real revelations.
This is where your first draft comes into play since it will constitute a basis for you to work. A basis on which you will be able to self-criticize and which many things will seem more obvious to you. The exercise will be easier for you since you will already be imbued with your problem because do not forget that you have just written your algorithm for the first time.
Reread your algorithm, and I’m sure you will find many things to improve or a lot of bugs that can be fixed.
You are entering the phase called refactoring. In this step, you will put everything you learned to good use, and you will refactor all the parts of your code that need it. Again, apply everything you know about best practices and use your work environment to help you.
To summarize
The method's goal is to do things in 2 steps when you do not control your entire work environment. The 1st step is to focus on the root of the problem and only that. The 2nd step is to focus on the form of the problem, putting all the knowledge you have acquired into practice by having a codebase in front of you.
This method is, for me, one of the most effective methods when you are a beginner because it helped me a lot when I was starting. Of course, it might not be right for you, but it’s worth a try, especially if you’re having difficulty designing an algorithm in a programming language.
It is obvious that when you will sooner or later become more comfortable with your work environment. And this method will not be of much use to you. But keep in mind that anyway, whether you are a beginner or not, no developer can produce an optimized algorithmic solution the first time without having to go through the refactoring box.
More content at plainenglish.io
