As a programmer, how can I become better at thinking logically?

Practice makes perfect.

anyone can become a programmer…the real catch is…

it is incredibly mind boggling and frustrating to start with. When this happens the thing that seperates the wheat from the chaff is, the wheat is still motivated to struggle on through …..wheras the chaff lose interest..

programming is a bit like a rubicks cube….those kids that can do it in 10 seconds flat…probably spend a few hours a day just playing with the thing..they are a bit obsessed with the cube ..this obsession leads to them putting in hours and hours and days and years of practice and eventually they can do it in 10 seconds some liter

anyone can become a programmer…the real catch is…

it is incredibly mind boggling and frustrating to start with. When this happens the thing that seperates the wheat from the chaff is, the wheat is still motivated to struggle on through …..wheras the chaff lose interest..

programming is a bit like a rubicks cube….those kids that can do it in 10 seconds flat…probably spend a few hours a day just playing with the thing..they are a bit obsessed with the cube ..this obsession leads to them putting in hours and hours and days and years of practice and eventually they can do it in 10 seconds some literally with their eyes shut…

but they have practiced and practiced.

then you get your mediocre programmers…those are hte kids that also loved the cube but were not obsessed with it ..but could motivate themselves to learn a few rubick algorithms every so often…until they finally cracked the cube…they can do it in a minute or so…and impress most of society who cant do it.

then you get your poor programmers…they wanted to do the cube but after practicing for a few days maybe weeks….eventually found out they would rather spend their time doing something else…and they maybe even learned how to do the cube but they never practiced and did it without help or a video…it was fun for a while ..but not really their idea of everlasting fun…they probably tell themselves and others ..they just cant get it …the reality is they cant be bothered it is just not that interesting to them..give them an xbox and they may be red hot and play all night ..give them an instrument and they may love it and be obsessed or a good book or biology chemistry..if they are obsessed then they will be good…

bottom line ..all are as capable of doing the rubick cube ..just like all are capable of programming…but when the going gets tough, will you have the patience to sit down and battle and battle and remain motivated …are they that interested .

if so they will become good programmers…if not they will maybe even get a job as a programmer,but will always be watching the clock and find their days tedious and complicated, because they really have no interest any more.

Computers do exactly what they’re told. The issue is that they will ONLY do what you tell them to. Thinking logically, especially in terms of programming, basically refers to the ability to be able to keep track of all of the different things you need to tell a computer in order for it to do what you truly want to do.

Say you’re telling somebody how to make a peanut butter & jelly sandwich. How in-depth would you go in your explanation? Some people might offer a super simple answer - “Just put peanut butter and jelly on bread”. But there’s a lot of assumptions made in that statement - you’re as

Computers do exactly what they’re told. The issue is that they will ONLY do what you tell them to. Thinking logically, especially in terms of programming, basically refers to the ability to be able to keep track of all of the different things you need to tell a computer in order for it to do what you truly want to do.

Say you’re telling somebody how to make a peanut butter & jelly sandwich. How in-depth would you go in your explanation? Some people might offer a super simple answer - “Just put peanut butter and jelly on bread”. But there’s a lot of assumptions made in that statement - you’re assuming that the person you’re telling how to make the sandwich knows how to spread peanut butter and jelly, that they have the appropriate silverware, and that they are going to put it on a plate. Give this same explanation to a computer, and you’ll probably end up with a jar of peanut butter on top of a jar of jelly on top of a loaf of bread. Humans can extrapolate from assumptions - computers can’t. “Thinking logically” is the process you do to remove those assumptions.

For a computer build a peanut butter & jelly sandwich, think about how you would walk a literal toddler through it.

  1. Get a knife from the drawer.
  2. Place on counter
  3. Get the peanut butter from the pantry.
  4. Place the peanut butter on the counter next to the knife.
  5. Get the jelly from the fridge.
  6. Place the jelly on the counter next to the peanut butter
  7. Get the loaf of bread from the pantry
  8. Place the loaf of bread on the counter next to the jelly
  9. Get a plate from the cabinet
  10. Place the plate next to the loaf of bread
  11. Open the bag of the loaf of bread
  12. Take 2 slices of bread
  13. Place the bread slices on the plate.
  14. Close the bag of bread.
  15. Place the bag of bread back in the pantry
  16. Open the peanut butter jar
  17. Take the knife
  18. Use the knife to scoop 2 tbsp of peanut butter out of the jar.
  19. Place the peanut butter that is on the knife onto one of the slices of bread that is currently on the plate, and spread evenly using the knife.
  20. Drop the knife on the counter
  21. Close the peanut butter jar
  22. Place the jar back in the pantry
  23. Open the jelly jar
  24. Take the knife
  25. Use the knife to scoop 2 tbsp of jelly out of the jar
  26. Place the jelly on top of the peanut butter that is on top of the single piece of bread.
  27. Spread evenly using the knife.
  28. Place the knife in the sink
  29. Place the other slice of bread on top of the first slice, on top of the jelly.

Thinking logically also involves taking those instructions, and seeing where you can optimize it. For example, if you keep bread and peanut butter in the pantry, then you can skip step 7 and 8, and grab the bread when you grab the peanut butter.

There’s a lot more to logical thinking - there are entire philosophy classes dedicated to it. But the most basic example is having the ability to logically iterate through each step necessary to complete a process, whether it’s the steps necessary to take in a file and check each line to see if it says “I like PB&J”, or making an actual PB&J

In order to do so try to solve maths question which you are unable to solve, it doesn’t matter even if you solve it in 3, 4 hours, it will increase your ability of thinking. Because you see you know the concept you just need to know how to use those concepts to solve that question, i.e. you are learning how to logically implement those concepts.

The same thing is with writing the algorithms. To do something there are many algorithms, but out of them only one would be the best, but you see how can you say that, that algorithm is the best, i give you a small example,

suppose you are given a task t

In order to do so try to solve maths question which you are unable to solve, it doesn’t matter even if you solve it in 3, 4 hours, it will increase your ability of thinking. Because you see you know the concept you just need to know how to use those concepts to solve that question, i.e. you are learning how to logically implement those concepts.

The same thing is with writing the algorithms. To do something there are many algorithms, but out of them only one would be the best, but you see how can you say that, that algorithm is the best, i give you a small example,

suppose you are given a task to get the information about a man, that were he was (who is either at his office or at his home) on October 16, 2016, so one way is to go and ask that man or we can logically reason that,

1) he is either at his office or at his home,

2) October 16 , 2016 was Sunday.

3) all offices remain close on Sunday,

So if October 16 was Sunday and his office was closed so he wasn’t at his office and from statement 1 we now say that he was at his home

so Tell me which way is better?

So you see using second way of doing your task doesn’t needs you to go to that man.

If you realize through this example i want to say that algorithms can be made better by using logic, through logic you can minimize the number of comparisons, you can reduce the time of calculations and so on because at some point of time you will realize that if this thing happens then that thing will never happens and if that thing never happens you don’t need to verify it again and again and you can then remove those verification statements( if statements ).

Other thing which is equally important is to know about the different features that a particular language is providing, because you know you can tighten a screw using your hand or a screw driver , which is better? Because some language provides very beautiful ways to do a certain job.

After knowing all these things remember, don’t settle writing only one algorithm for solving a problem, write at-least 5–10 different algorithms for the same.

Also you need to know about the Debugging techniques, which is necessary because through them you can get to know about the reasons that why your algorithm didn’t worked or you can compare different algorithm step by step, you can get to know which step is taking a lot of time and also you need to think about its alternative.

Do you know that, in these days 3D games there are a lots of calculations done per frame( have you ever seen a game giving a lot of frame drops?) so as to give you a real sense of physics. In such case you never want any of your calculations to take time, you need an algorithms which is fast, so that there is no frame drop.

Keep patience with an open mind you will definitely start writing better algorithms.

I think most programmers cannot share their thinking styles with non-programmers — as evidenced by the many “Just try harder” answers here. :D

The key to programming is to think as if you’re building a house. The problem with this is, most of today’s population doesn’t know how to build a house.

And instead of purchasing the bricks, you’re making them from minerals you dig out of the ground, one by one. After you’ve poured out thousands of bricks, you have to let them harden for a week. Then you have to use more cement and cement them into place for your house. You have to keep in mind the desig

I think most programmers cannot share their thinking styles with non-programmers — as evidenced by the many “Just try harder” answers here. :D

The key to programming is to think as if you’re building a house. The problem with this is, most of today’s population doesn’t know how to build a house.

And instead of purchasing the bricks, you’re making them from minerals you dig out of the ground, one by one. After you’ve poured out thousands of bricks, you have to let them harden for a week. Then you have to use more cement and cement them into place for your house. You have to keep in mind the design you want, and plan the brick laying accordingly.

Programming is much the same way. When you were pouring the bricks, you weren’t thinking of the house plans. You were thinking about how to make the best bricks possible. When programming, you don’t need to think of the entire program while working on a single function. Instead, make your functions, THEN lay them together to form the planned way you want your software to look. You have to have a vision of how your software should work at this point, just as you have a vision of how your house is going to look after the bricks harden and need to be laid down.

At any time, you can change your design plan because you’ll have the tools you need at this point. First focus on what tools you need. Then bend them to your very will.

Why can’t you solve a problem quickly despite working for 5 years as a programmer?

Probably because your work has little or nothing to do with developing skills required to solve the kind of problems you are trying to solve now.

Why can’t I write code in Perl despite doing competitive programming for multiple years and now working as a programmer for half a year already?

Because I never ever needed that knowledge and that skill. Same for you.

Why do others come with solutions quicker?

Because they have skills and knowledge you don’t have, and they got them from some direct or indirect practice and

Why can’t you solve a problem quickly despite working for 5 years as a programmer?

Probably because your work has little or nothing to do with developing skills required to solve the kind of problems you are trying to solve now.

Why can’t I write code in Perl despite doing competitive programming for multiple years and now working as a programmer for half a year already?

Because I never ever needed that knowledge and that skill. Same for you.

Why do others come with solutions quicker?

Because they have skills and knowledge you don’t have, and they got them from some direct or indirect practice and learning. Maybe they had to solve similar problems during their studies, maybe their work more often requires them to solve problems you are talking about (or problems which require similar knowledge and skills), maybe they enjoy solving challenging problems on their free time, maybe they make these problems easier by applying tricks and techniques you don’t know.

How can you improve it?

By deliberately practicing skills needed to do well on solving such problems. You may look online on how to improve at solving some specific kind of puzzles, you may start with simply practicing these puzzles on your free time, you may look for a job which is more challenging (or is challenging in a way you want it to be challenging).

Sorry, no secret magic here.

A2A

Let me try to explain with simple example— Task is to find student whose rank is first and last in class. Before you write code, follow these steps. These will help you in resolving your problem.

  • Understand what you want to do carefully and define correct problem definition.

we can define our problem as “Find Max and Min Marks from list”

  • Break down main task into smaller tasks

Task looks easier when you devide it into smaller tasks. Here, You can break down it as--

  1. Read all student’s names and marks.
  2. Sort Students by marks in descending order
  3. Print name of student with first rank as first record f

A2A

Let me try to explain with simple example— Task is to find student whose rank is first and last in class. Before you write code, follow these steps. These will help you in resolving your problem.

  • Understand what you want to do carefully and define correct problem definition.

we can define our problem as “Find Max and Min Marks from list”

  • Break down main task into smaller tasks

Task looks easier when you devide it into smaller tasks. Here, You can break down it as--

  1. Read all student’s names and marks.
  2. Sort Students by marks in descending order
  3. Print name of student with first rank as first record from list
  4. Print name of student with last rank as last record from list

Go further and break down these task again into smaller tasks.

For Ex: Read all student’s names and marks can be break down as follow:

  1. Define data-structure or variables to hold all student’s names and marks.
  2. Define input method for reading data.
  3. Get input and validate.
  4. Add input to defined database (variable or database)
  • Always look for alternative.

There is always another way to do it. Before you proceed, check if there is any alternative way of solving problem and select simplest and easiest alternative.

For example in our case, we can solve it other way as follow :

1) Read student’s name and marks

2) Save it into database.

3) Fetch student with Max value of mark from database using database query, print as first rank

4)Fetch student with min value of mark from database using database query, print as last rank

  • Analyze

re-think on what you have decided and consider all possibilities to ensure 100% correctness.

Now, as you have list of small task, star coding. Start with simplest task.

Apply above for any programm you want write. If you still find it difficult, For few days, forget about programming and start solving logical puzzles. once you feel you are comfortable with it, come back to programming.

Luminous Learning

Starter Puzzles

Once you feel more than comfortable with solving these puzzles, come back to programming and try to follow these instructions.

Above All-- as mentioned in every answer to this question- Practice!! Any technique will not work without practice.

Solve mathematical problems. This can be a good source : Brilliant | Excel in math and science.

Another website is this: HackerRank

Try out different languages.

Strive to do the basics very well. Continue doing it until “basic” leads you to think that “finding the number of paths in an hypergraphe using each node once” is trivial.

Don’t fear vocabulary. Admit you don’t know and Google it / look it up.

Know how you think, study or at least consume material about psychology.

This is a good starter : List of cognitive biases

This can be fun : piaget tasks - YouTube

Here is some good things to relax & lea

Solve mathematical problems. This can be a good source : Brilliant | Excel in math and science.

Another website is this: HackerRank

Try out different languages.

Strive to do the basics very well. Continue doing it until “basic” leads you to think that “finding the number of paths in an hypergraphe using each node once” is trivial.

Don’t fear vocabulary. Admit you don’t know and Google it / look it up.

Know how you think, study or at least consume material about psychology.

This is a good starter : List of cognitive biases

This can be fun : piaget tasks - YouTube

Here is some good things to relax & learn :

These are in French, maybe you will find the equivalent in English or your native language:

Oh, and by no means discard a topic too easy for you or that you already know.

Lot of people can add together 15 and 17 but don’t understand this:

xi+yi=(xi+yi)∑xi+∑yi=∑(xi+yi)

Though they will do :

10+10+5+7=20+12=3310+10+5+7=20+12=33

The process is really dead simple.

And least but last, don’t “force” it. Enjoy and don’t bother to retain. You will be exposed enough to naturally hold it. It will last far longer and your comprehension will be far better.

On mobile, I play few games:

On PC, I play these:

I can give you a 100% guarantee that if you become good at these, then you will be a far better developer :-)

I learned BPMN and UML 2 and still learn bits too.


If you repeat the same thing over and over, your brain will rewire to be more efficient at doing a specific task. This may lead to some deformations of your reality.

If you do various tasks, your brain will mostly keep its plasticity. What will be more efficient is the intrinsic properties of problem solving. You will become better at finding patterns, avoiding common pitfalls (biases), being critic.

And yes, watching a Youtube video can be as beneficial than stretching your brain in any of the game above.

Be exposed to new stuff regularly.

Some people will find me crazy, but most of them wouldn’t be able to complete or play efficiently at game shown above.

To give you an idea, I can complete this : from Simon Tatham's Portable Puzzle Collection in few seconds. And that one in one minute : from Simon Tatham's Portable Puzzle Collection etc.


What I learned from these games is to apply correctly the scientific method. When I have to hunt a bug, I do exactly the same thing than when I discover a map in Factorio etc. I look at what I have, how I can eliminate the components until the segment under test is so small I can run it in my head ! Then I do what I call “cold” debugging. Once it’s done, I write the unit test to reproduce the bug, then I correct it.
(Well, sometimes I skip the unit testing writing phase, but let’s keep it secret!)

To come back at the beginning of the answer, program in C, Java, Assembly, APL, PHP, Perl, Javascript, Haskell, Kotlin, Elm, … snups ! Even Labview if you can.

At some point, you will realize that what count are idiomes and not languages per se. And how to go from one idiome to another.

But hey, we all started by “loops” and “alternation” :-p

There are two general approaches to this- Top-down and bottom-up design. Both of these involve breaking the problem into parts.

For top-down, you start with your general problem, defined by what the input and output are. Let's call the problem X. Then, you break the problem into smaller problems A, B, and C, so that the input to X in the input to A, the output to A is the input to B, the output to B is the input to C, and the output of C is the output of X (the chain doesn't have to be 3 long- it can be as short as 2 or as long as you want).

A, B, and C don't need to be trivial problems; they ju

There are two general approaches to this- Top-down and bottom-up design. Both of these involve breaking the problem into parts.

For top-down, you start with your general problem, defined by what the input and output are. Let's call the problem X. Then, you break the problem into smaller problems A, B, and C, so that the input to X in the input to A, the output to A is the input to B, the output to B is the input to C, and the output of C is the output of X (the chain doesn't have to be 3 long- it can be as short as 2 or as long as you want).

A, B, and C don't need to be trivial problems; they just need to be problems you could more easily solve than X. If you get stuck on one of them, repeat the breakdown for that problem. Keep going until you have solved the entire problem.

The other approach is Bottom-up. For this one, you have a problem X and you solve problem A, where A and X have the same input and A is smaller. Your problem should then become smaller with the output to A, as opposed to the raw original input.

So there you have it. You basically turn one massive problem into smaller, more manageable problems. Finally, always test your solutions to sub-problems. If you don't, you will create at least one bug without noticing and it will be hard to find when the project is done.

You can improve your logical skills by:

  • Try to divide a problem into smaller individuals parts that you can solve too easily. Continue solving those smaller problems. And see how they fit as a whole. This technique is called Divide and Conquer.
  • Note down all the information you have in a notepad, and try to analyze a relationship out of those variables.
  • Try to link all the missing pieces to a problem by jolting down all the relevant points on a notepad. Try working your way from there by figuring how can you find those missing pieces to a problem.
  • Try to have a high level bird’s eye view of the pr

You can improve your logical skills by:

  • Try to divide a problem into smaller individuals parts that you can solve too easily. Continue solving those smaller problems. And see how they fit as a whole. This technique is called Divide and Conquer.
  • Note down all the information you have in a notepad, and try to analyze a relationship out of those variables.
  • Try to link all the missing pieces to a problem by jolting down all the relevant points on a notepad. Try working your way from there by figuring how can you find those missing pieces to a problem.
  • Try to have a high level bird’s eye view of the problem at hand, try to figure out the problem where you are at.

Lastly, developing logic is analogous to solving puzzles and riddles. You excel at them by solving more and more.

As someone else mentioned in their answer, it's systematically.

I'm going to explain a different aspect of it compared to other answers...

Yes, but don't worry, no one knows how to do it at first.

It's something that will come to you after starting programming, probably around time when you've been practicing for quite awhile.

Is it hard? Yes at first, but soon you'll love it.

How can I fast forward this process?
Well... I had a French teacher who always said "
carry a dictionary in your pocket, a small one, so when you see an object, say a bus, you can look it up in French"

I'm going to say th

As someone else mentioned in their answer, it's systematically.

I'm going to explain a different aspect of it compared to other answers...

Yes, but don't worry, no one knows how to do it at first.

It's something that will come to you after starting programming, probably around time when you've been practicing for quite awhile.

Is it hard? Yes at first, but soon you'll love it.

How can I fast forward this process?
Well... I had a French teacher who always said "
carry a dictionary in your pocket, a small one, so when you see an object, say a bus, you can look it up in French"

I'm going to say the same to you. When you see something, think about how you can model it using an object oriented programming language or when you do some calculations try coding (or imagining it at least) that calculation. Also automate things around your computer, develop your own note taking app, make an add-on for Firefox that you need and... you knowthe rest of the story :)

Happy CCoding! :)