Thinking like a programer

Thinking like a programer
0

#1

Hey, everyone. So after a few months of work on this and other projects, I’ve hit on the root of my problem with coding and I’m not quite sure how to fix it. I feel like I have a good grasp of the basic principles, but is the problem-solving aspects that tie me up. I struggle with, when giving a coding problem, how to apply what I know to solve that problem.

I realize this is a problem of how I think about things, but I refuse to give up as I’m sure I can teach myself to think like a programmer, for lack of a better term. I was wondering if anyone had any advice for getting into the right mindset as I believe that is my biggest problem right now


#2

It’s called Computational Thinking

Here’s a wiki for more information

A good technique will be to break down a large task/problem/project into smaller and smaller tasks or steps, and solved in a way where a computer can follow the individual steps.

Having familiarity with data structures will also be helpful, iteration and looping, conditional loops is also good.

Having familiarity with what commands/functions you have at your disposal in the programming language of your choice is also useful. In your free time, browse the language reference manual of your language, just to see what’s available for use. Scan them, read a brief explanation about each, and go to the next. Now, when it’s time to solve a problem, you eventually will remember your chosen language has a ready-made command or function that may help you or you can use. Then you can google it, or go back to the language reference manual to read more details on how to use the command/function.


#3

hi eric, this is what you can do whenever you get coding problem :

1. Understand the problem completely before attempting to solve it
many newbie camper like to code directly after read task’s explanation without ever looking at input test, only to find their answer unable to fulfill one of input test requirement

2. Solve the problem manually, use sample to check your solution
divide your answer into several manual step, say you want to do “find the longest work” task.
this is what you need to do :

  1. split input string
  2. find a way to save the current longest word
  3. use “for” to compare every word’s length with the current longest word, if word’s length > current longest, replace it

Give it a try with “The quick brown fox jumped over the lazy dog”. “Jumped” will replace previous longest word and can’t be replaced by later word because none of them have more letter.

3. Make pseudo code as a guide
Let’s move to java script and start making some comment, it really helps in the future, especially if you want to use this code as reference for yourself and for another people that might use it. Based on previous example, this is what your pseudo code would look like :

//1. split string into array

//2. make number variable to save current longest word,

//3. loop through word to find longest word

//4. return longest word variable

4. Make the real code
Say you don’t how to do 3rd, that won’t stress you much because that’s only 1/4 of your later program. even if you need to google some answer, you know exactly what are you looking for.
This is also where experience matter.If it’s not working, use sample input to check which step didn’t give intended result

5. Optimize your code
Step 1, 2, and 4 is pretty simple, no need to improve it. For step 3 you can try with Math.max().


This step seem unnecessary for earlier challenge, but trust me, it saved me lot of time in medium challenge

nothing more frustating than fail a challenge because you misread the description


#4

fwiw - here’s what I wrote in a similar thread recently


#5

Algorithm challenges is the short answer. You just have to put in the hours. A problem might take you a few hours or even a few days of teeth-grinding, cursing, forehead-pounding, wtfing lunacy. But getting a working answer gives you a real kick. If you can get through the FCC algorithm challenges, I’d say you don’t have a problem.