How To Improve Logic Building Skills In Programming?
I frequently see beginners asking questions in forums like 'how can I improve my logic building skills' or 'how to think logically or something like 'how to think like a programmer' and blah, blah. If you have similar questions in your mind then follow along.
We are going to talk about logic and thinking. So first, let’s see how Google defines logical thinking. I am copying the first line of a Google search for "logical thinking".
Logical thinking is a process of clearly moving from one related thought to another.
Clear enough. Push the definition to your stack, we will pop it back because this article is partially based on this definition. I am just trying to make it easy for myself to illustrate and easy for you to understand.
When I write code, I usually follow three ways.
- Use algorithm or someone else’s code [the easiest]
- Divide and conquer [the hardest]
- Try try again [depends on your luck and mental abilities]
The points above are self-explanatory and most of you might have got an idea about what am I going to talk about. To those who didn't get anything, I will say
'NO Worries'. Let's dive (not too deep) into all one by one.
1. Use Algorithms:
Do you know what an algorithm is? A very formal, non-comprehensive and static definition of algorithm is "it is a step by step process to solve a problem". Why did I mention it here? Because I want to tell you that the problem, you are struggling to find a solution for is already solved by someone if not many. The solution might be available in pseudo code or even in the language, you are using. Do not ever hesitate to steal the code or logic. Copy and paste. It will save you a lot of time. Super easy. Isn’t it?
Well, as far as I think this method has nothing to do with logical thinking or logic building skills and you might think the same. Then why we are discussing it here? Wait, we are missing something. Copying is just a piece of cake. The logical part is, where to paste the code into your code. Keep reading. The answer is coming ahead.
2. Divide and Conquer:
This is the hardest but the most effective method of building logic for a program. For your ease, I have divided it into further 5 steps. I myself use this method most of the time but I do not label the steps. I have just named these to make it easier for you to understand.
i. Understand the problemUnderstanding something quickly and thoroughly is an art. It depends upon your interest, your curiosity on knowing and learning, and the time since you have been in the field. None can come up with a solution without understanding the problem. This is the very first and essential step of problem-solving. Try to understand the problem as much as you can. The more you understand the problem, the deeper you will think about it and the less time it will take you to solve. How to better understand a problem? Read Herehttps://open.buffer.com/5-whys-process/
ii. Break it into partsThis part is likely to be hard for you if you didn’t do well in the previous phase (understanding the problem). It is necessary to look at the big picture before narrowing it down and down to very simple units. You need to use your deductive skills to figure out what you need to do. Remember, success in the first try is not guaranteed and if you succeeded, take it as a compliment. If you failed, don’t lose heart. Try again and again until you satisfy yourself enough. Once you know about the composition of joints, break them.
iii. Understand each partThe deeper you dig into a problem, the closer you will get to its solution. Understand each part individually and iterate step ii and iii until you are clear enough about the requirements.
iv. Solve each partThis is where you will need your determinism and logical thinking skills. But as compared to thinking about a really big problem, it is easier much easier to think on a little tiny part and you will feel it.
You should know where to write what. By writing, I meant writing code. I am thinking to make a cheat sheet for beginners which will help them in making if-then logic easily. Instead of scratching your head for hours and write your own logic there is another way available. That way is already discussed in 1st section. Borrow the code or algorithm. Pop the definition of thinking logically. See the backward and forward movement.
v. CombineFinally, If you are this stage, guess what? You are done. All you need is to glue the tiny solution together to get the final product. This step is the reverse of step 2.
3. Try Try Again:This method is based on brainstorming. The process is very simple. Apply each and every solution which come to your mind and test if it works.
Note: Don't forget to make a backup before testing because during the test anything which you might not expect may happen. For example, the app/editor can crash and more likely you will lose your changes.
It is good to make test cases and try one by one. Keep those which work and discard the rest. Do not worry about the quality of the code. Just try to make it work.
I personally use this method when I need to write code for something less valuable like school assignments or for debugging, where the quality of the code does not matter. However, you are free to refine the code up to any level you want.
Alright, we are done for today. I was just an intro. I will write in detail for each of the above topics. Believe me, programming is easier than you think but if you understand the trick. Happy Coding.