How to improve my programing logic?

github logo ・1 min read

Hello DEV community πŸ’–πŸ’–

I always wonder how I can improve my thinking and logic in programing? When I face a new challange I always freeze for a long time before I came up with the solution and start to code. I'm not thinking, I'm FREEZING. How to think and plan for my code?

twitter logo DISCUSS (4)
markdown guide

That is a hard question.
I personally believe that everyone has their own process. Perhaps freezing is yours, but the important part is not to get frustrated. You can do pseudocode exercises, listen to different kinds of music while you code, so that your mind gets a different rythm.
The tips I give you are:

  • Define the objective to achieve
  • Write the steps to get to that objective (In a piece of paper works for me) Until here, no code has been written.
  • Define what gets in your way to get to that objective (those should become your validations)
  • Now start coding straight to the objective. Completely ignore the validations or the "make pretty" parts, all of that can be last.

By writing it down.
Write your input and outputs first on a piece of paper.
then write down each step you need to do on the input to get the desired output (the part you can be very general or can go in detail). This has helped me not only do i understand the flow but also get to know if there are more effective ways or a different logic i can apply.

it may sound time consuming but its much better than just being clueless in the middle of coding, trust me its doesn't take a lot of time too.


The best advice I can give is to get more experience. As you solve more and more problems you'll find solutions that you will be able to re-apply in various situations.

I would give Codewars a go. It provides you with coding challenges that help you to improve your logical skills.

If you find them difficult to start with, don't panic it's fine. You can look at other peoples solutions and over time you will learn the patterns to look out for and it will become muscle memory.


Thank you all guys for your answers. @jhordan92 @rinisimon @georgehanson
Forgive me if I sound like a stupid right now but can anyone give me an example.
Let's take this example from Eloquent Javascript:

Quiz: Write a program that creates a string that represents an 8Γ—8 grid, using newline characters to separate lines. At each position of the grid there is either a space or a "#" character. The characters should form a chessboard. Passing this string to console.log should show something like this:

# # # #
 # # # #
# # # #
 # # # #
# # # #
 # # # #
# # # #
 # # # #

When you have a program that generates this pattern, define a binding size = 8 and change the program so that it works for any size, outputting a grid of the given width and height.

I want to know how you gonna planning for this code, How I'm gonna know how many variable I'm gonna use, What's is step #1 and so on.

Classic DEV Post from Feb 1 '18

Keeping the Footer at the Bottom with CSS-Grid

At some point in a project, one gets annoyed by the footer hovering right und...

Budi Salah πŸ‹ profile image
I'm a front-End Web Developer with 3 years experience who hopes one day to be great Javascript Developer, My love for this language is so deep and I hope to accomplish this soon. πŸ’–βœ¨