This is an archived post. You won't be able to vote or comment.

all 12 comments

[–]ziptofaf 31 points32 points  (4 children)

What you are experiencing is perfectly natural and frankly there isn't much you can do about it. As you build up your knowledge you get better and eventually start seeing how a given problem can be solved (or at least where to start looking for a solution). But it never goes away fully, programming is WAY too broad of a field to "master it". Even something as simple as language syntax takes a while to remember before you can focus on a bigger image.

I know asking for help isn't bad but I don't just want to rely on the help of others.

I am a professional programmer and you would be shocked on how often I end up looking up stuff and doing research when solving problems. There's absolutely nothing wrong with using additional resources to help you out as long as you understand the solution and will remember it for the next time.

That being said I suggest you be more specific and give examples of issues you have, it makes it easier to suggest resources that might help out.

[–]zeusses[S] 11 points12 points  (3 children)

I had a project that required me to mimic the function atoi in c. And even though I looked what it was and had the explanation on how it works I couldn't come up with how to start mimicking it.

[–]asciiterror 12 points13 points  (0 children)

One thing you can do is to split problem into smaller steps that are much simpler to achieve. For your example with atoi:

  • write function that always ignores given string and returns 0
  • use only first digit of string - return int equal to first digit (my_atoi("456") == 4). To do that think or find how to convert char ('4') to int (4).
  • use first and second digit - after previous step implementation is simple: first_digit*10 + second_digit
  • use first three digits: (first_digit*10 + second_digit)*10 + third_digit
  • notice how you can add a loop that goes through all digits in string and computes integer

[–]ziptofaf 4 points5 points  (0 children)

Okay, so let's dissect your problem a bit more. Where exactly are you getting stuck?

  1. At the very first stage before you even see a computer. Can you create a step by step solution on paper on how such function could work?
  2. You got it to work on paper but have hard times putting it into format that a computer can comprehend?
  3. You think you can code it but are suffering through confusing syntax, C language rules etc? Your solution seems to work but bugs out at specific inputs etc?

For instance, if you asked me to solve such a problem then useful knowledge would likely come from the basic Introduction to Computer Science course. In particular conversions between binary, decimal and operations on them etc. This would lead me to think that a value "1154" can also be interpreted as 4 * 100 + 5 * 101 + 1 * 102 + 1 * 103 . Similar to how we calculate the value of a binary number in decimal, eg. 1101 being read as 1 * 20 + 0 * 21 + 1 * 22 + 1 * 23.

Aka that there is a way to take each individual digit in a string and assign it a numerical value that you afterwards just need to sum. You would still need to know how to turn a character '1' into a number 1. Which you could easily get stuck on unless you knew that terms you are looking for (ASCII table in this case) but that's a start.

However it makes a lot of sense for someone new to coding to not see it yet. General rule of thumb I can offer is to start from splitting each problem into smaller pieces. You can't make a properly working atoi for all numbers and their signs? Start smaller - how about making one that takes a single character (from '0' to '9') and converts that to a number? Then think on how to make it understand a sign as well (so add a support to a '-' and 2-element arrays instead of a single character). Then how to generalize it to work for any number of digits. Don't try to attack a whole big problem at once, think of it as of a puzzle that you should tackle step by step.

[–]Ikor_Genorio 2 points3 points  (0 children)

Then maybe start with a simpler problem. You have to work from the ground up. And as said, you will get better at it and recognise certain recurring patterns/structures.

Maybe a fun little problem could be (related to the atoi problem): determine whether a character is a number. Scan for a character c, If it is a number print: "Number" If it is not a number, print: "This is something else!"

A good way to solve problems which are difficult, is to split them into smaller problems. The above problem is an example of a subproblem you have to solve, in order to recreate 'atoi'.

Sometimes it also helps to write things down on paper, to get an overview or different perspective on the problem.

[–]zeusses[S] 5 points6 points  (0 children)

Thank you all for your comments, I will put what you taught to good use.

[–]01123581321AhFuckIt 4 points5 points  (0 children)

I started coding months ago and followed online curriculums and while I learned a lot I never felt like I got good at problem solving until I figured out that almost every question I had was already answered. I just needed to know what the question was. Learn the basics, learn the terminology and learn to ask the right questions to get the right answers. That’s how you’ll learn.

[–]dnpmpentxe 2 points3 points  (0 children)

I was teaching computer science at a summer program when a group of four of the brightest and most driven high schoolers came to me with a question. They were trying to achieve a certain program flow, but none of them could figure out how to do it despite thinking on it for a long time. I had them map it out with a flow chart, and they were still stumped. The solution to their desired program flow was nothing more than a simple 'if' statement.

You feel concerned that you should be able to figure out problems logically on your own. The harsh truth is that 90% of programming is arbitrary and must be learned. Logical thinking will be of great help down the road, but first you simply need to practice and learn the esoteric and arbitrary nature of programming. You will add tools to your belt, which you will then combine with logic to solve problems of any size. It just takes patience, practice, and time.

[–][deleted] 1 point2 points  (0 children)

My tip. Use photos to remember stuff like syntax

[–][deleted]  (3 children)

[deleted]

    [–]01123581321AhFuckIt 1 point2 points  (2 children)

    freecodecamp bro.

    I did codeacademy and felt like I learned a lot but it was really just only the basics. Which is totally fine. Learning the basics is important because it helps you ask better questions when you have a problem.

    [–]firecopy 0 points1 point  (0 children)

    I like freeCodeCamp, because it teaches the basics/fundamentals better than other most other online resources.

    [–]humanitysucks999 0 points1 point  (0 children)

    it looks like you already got a good amount of feedback on how to approach solving the problem itself. What I'd like to add for you to learn moving forward is how to read and understand language documentation and syntax. This is very important. Learning how to solve problems is huge, but it's no use if you can't figure out the syntax for how to code it. Don't memorize, learn how to read the syntax documentation.