DEV Community

Budi Salah πŸ‹
Budi Salah πŸ‹

Posted on

How to improve my programing logic?

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?

Top comments (6)

Collapse
 
jhordan92 profile image
Jhordan

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.
Collapse
 
rinisimon profile image
Rini Simon

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.

Collapse
 
georgehanson profile image
George Hanson

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. codewars.com

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.

Collapse
 
budisalah profile image
Budi Salah πŸ‹ • Edited

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.
Thanks.

Collapse
 
mohnmu profile image
Mohn

This Video might help you

  • Identify the problem you are solving.
  • Understand the problem fully
  • Deeply explore potential solutions
Collapse
 
tammalee profile image
Tammy Lee

That video is excellent! Thank you so much for sharing. I'm going to encourage my team to watch it.