Does anyone else struggle with problem solving?

Started by
22 comments, last by MrJoshL 11 years, 4 months ago

Do you have the free time to enroll in a Data Structures or Algorithms class at a local college? Once you know what all the tools in the tool-box do, its easier to pick the right ones to solve problems.


I plan to go to a University here soon, I just need to see if they'd have the right classes.
Advertisement
I find this a problem common among beginners. If I give you code, you can understand the process and what the code does. But if I tell you to write a brand new code from scratch, you are stuck right from the beginning. Did I run into this when I first started? I don't remember. But I see this all the time.

The era of the Internet today makes it easy to copy and download code snippets, which encourages lazy thinking. You see this all the time on blogs. People would comment "Code doesn't work! HELP! HOW DO I FIX!?!?". And this is coming from using a simple code how to convert a file to a string object, for example. I'm not pointing out that the code doesn't work, but I'm pointing out the sheer laziness in people that they expect things to fall on their lap and work. When things not operating the way they expected, they don't bother to find the solution themselves.

It only comes from experience, and it has to be the right experience. Always write code from scratch. It's okay to look at code from web, but only as a reference, not meant to be copied directly to your code. 90% of the time that code won't be compatible to your code anyway. Never, ever, copy-paste and use code you get from web, conferences, CDs, or anywhere else. It's okay to use prepackaged libraries (like STL, SDL, Ogre, 3rd party libraries), the ones that you don't have to look at their code to use it.

How can a writer be a writer, if all he does is copy someone else's work? Programming the same way.

I find this a problem common among beginners. If I give you code, you can understand the process and what the code does. But if I tell you to write a brand new code from scratch, you are stuck right from the beginning. Did I run into this when I first started? I don't remember. But I see this all the time.

The era of the Internet today makes it easy to copy and download code snippets, which encourages lazy thinking. You see this all the time on blogs. People would comment "Code doesn't work! HELP! HOW DO I FIX!?!?". And this is coming from using a simple code how to convert a file to a string object, for example. I'm not pointing out that the code doesn't work, but I'm pointing out the sheer laziness in people that they expect things to fall on their lap and work. When things not operating the way they expected, they don't bother to find the solution themselves.

It only comes from experience, and it has to be the right experience. Always write code from scratch. It's okay to look at code from web, but only as a reference, not meant to be copied directly to your code. 90% of the time that code won't be compatible to your code anyway. Never, ever, copy-paste and use code you get from web, conferences, CDs, or anywhere else. It's okay to use prepackaged libraries (like STL, SDL, Ogre, 3rd party libraries), the ones that you don't have to look at their code to use it.

How can a writer be a writer, if all he does is copy someone else's work? Programming the same way.


That's a main problem of mine.

For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.
You just have to break up a problem into smaller chunks. Go find a sheet of graph paper and get it out. Start drawing a flowchart of your game loop and its variables, start planning out your program. It really helps sometimes, and gets you motivated.

C dominates the world of linear procedural computing, which won't advance. The future lies in MASSIVE parallelism.


That's a main problem of mine.

For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.


Then forbid yourself from looking at anyone else's code until you've completed your own. It's just like playing a game. You can play with a strategy guide your first time through, but you're just cheating yourself out of the accomplishment. Finish it once yourself and then look at the guide to see what you missed.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.


Then forbid yourself from looking at anyone else's code until you've completed your own. It's just like playing a game. You can play with a strategy guide your first time through, but you're just cheating yourself out of the accomplishment. Finish it once yourself and then look at the guide to see what you missed.


^ This

When I was a beginner I did this too. I constantly looked at others code and thought "But this guy does it this way, isn't that a better solution..?" Well, maybe it is a better solution, but it's not your solution. As I realized that, I also realized how ugly my own code was, but it didn't matter, as long as I was the one who came up with the solution. The ugliness of the code goes away with practice. I'm not saying you shouldn't look at other peoples code, only that it's bad for your problem solving skills to do so.

[quote name='Bill Fountaine' timestamp='1354216665' post='5005410']
I struggle to figure out HOW to solve it, like what variables, etc are needed.


I find this common lament kinda odd. I never have run into this. I never really have problems thinking about how a syntax element might be used to solve problems... Granted, what I come up with (especially starting out) isn't always the best or most practical solution for things but it's a solution.

I dunno... did I just play with too many Lego's as a child?
[/quote]
I think the problem is more in how do I express the solution I came up with, and that is a problem when you start programming, as you are learning how to program and how to express this problem at the same time.

If the problem is just how do I express a solution in my language Mathematical equations like Greatest Common Divisor, finding the zero points for quadratic equations and stuff like that is great to figure out how to express this in a language. The reason behind this is that maths already split these up into steps for you and you only have to express those in your language.
Working out the solutions for these equations and learning the algorithms involved on the other hand is a great way to learn how to divide problems in to more manageable chunks I found.


That's a main problem of mine.

For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.

It's not a problem to take code you find on the internet and use it, you just have to play with it until you actually understand what it is doing. From reading source code you get the major gist of how it is doing it's job, however what you usually don't get is what is the problem that this code is solving. When you start modifying it and it breaks and you start debugging why it is breaking that is where the understanding of the algorithm comes in, because at that point your are forced to go through the same thought path as the original author. How soon that understanding of the code kicks in is experience and your familiarity with the problem area. Once you start working this is the most useful skill you can have, "read and understand(debug) other peoples code". It is very seldom that you get to work on writing an application from scratch when you work for somebody.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, theHunter, theHunter: Primal, Mad Max, Watch Dogs: Legion



For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.


If you can't think of a solution for a tic-tac-toe game, then maybe it's too much of a challenge for you. Step back, and start something much simpler, like a number guessing game, text-based adventure, dice rolls. I have no idea how many useless/random programs I have written back in my GW/QBASIC days: draw random lines, circles, rectangles, compound interest calculators, address books, fake shell, etc.

It's a good thing that you are doing this because you want to learn. Keep this attitude, and never stop writing code.

For example, the Tic Tac Toe game, I keep trying to do it the exact way that the other guy does it, and I get stuck, and constantly refer back to his code to see what I am doing wrong. Not to mention whenever I try doing it by myself, I constantly think about that persons code. So I can never try it myself.


What I learned, and I think everyone learns, organically just by going through the process of programming without any professors, is that to improve your ability to problem solve, you must be able to focus on specific problems without thinking about all the 600 other problems you'll have to solve before you're done. To do that, you need to plan out what you will program before you ever program. The first time I did that, it gave me a huge boost in productivity, and it was a lot easier to focus on specific problems rather than be distracted by the fact that I don't know what's next or why. If you sit and write it all out, you have your own notes to refer to, not anyone else's code.

It should be super high-level, too. Like:

Tic Tac Toe:
- UI:
- There will be a main menu, and you enter a number to choose an option:
--0 is Exit
--1 is New Game

etc, etc, etc.

Notice there that I'm not talking about any code. I'm just describing the game or program or whatever. You start with concepts, at the highest level possible, and then you work your way down. You do this because working from the highest to the lowest level of design means you decide that a certain thing is necessary before you decide how you implement it. Working from the bottom up would be the opposite: You'd be coding functions that do things, but you don't know why you need them to do that yet. That means later you're almost definitely going to change those functions.

Aside from that, I think you should quit on tic tac toe. Forget it. You're gonna keep looking at the other guy's code, and you're probably tired of it by now. Do something you only have a small idea how to implement. Are you familiar with dynamic arrays yet? Make a "Database" where users will specify the amount of entries they need to make, and then create a dynamic array of that size. It can be an array of objects that the user fills out the data members of, and then the user can delete, move or change things around in the database, which means you'll have to manage the memory, make new resized arrays, and play around with different C++ features. Don't worry about actually saving the data. But if you're interested, you could use fstream, or if you're on unix you could use I/O redirection, and that'd be something else to learn too. But the point is to just do stuff that takes thought and taxes your knowledge of the concepts of programming and the specific language you're using.

Other ideas: Hangman, a calculator with factorial, square roots and powers, rock paper scissors, a text adventure (if you like writing, too). A personality quiz? An IQ test? When I was first starting, I tried to come up with ideas for iPhone apps that I could implement little prototypes of in a console program, sort of like proofs of concept. This was great because I honestly believed in the idea, planning to actually make them real, usable applications, but I was also realistic about the current scope, limiting it to console programming and simple user input/output.
Right

What can you guys recommend in terms of a good learning resource, preferably one that isn't outdated?

I've seen people say that cplusplus.com is horrible learning resource. I've also heard people say that C++ Primer is a good book.
The C++ tutorials from thenewboston seem decent as well.

I know there is a million tutorials out there. I just want something that doesn't leave any information out that I need to learn/know.

This topic is closed to new replies.

Advertisement