views:

385

answers:

17

I have become pretty fluent in a few different languages now, but I seem to have a hard time actually figuring out the best way to go about solving particular problems. What are some ways to go about getting better at the actual problem solving of programming.

+1  A: 

By solving actual problems. Practice makes perfect.

If you have time to become fluent in multiple languages, my guess is that you haven't spent much time doing any actual work. If you have a job, it might be time for a new one. If you're still in school, do you have any interest in starting a project for yourself or contributing to one that you use regularly?

It might help to know what kinds of problems you're having difficulty solving.

Kevin
A: 
  1. Practice solving problems.

  2. Take an algorithms or discrete math course.

Nixuz
+9  A: 

Experience. Solving something completely new is hard. The best way to solve problems is to try and find a problem that you've solved before, and that is similar, and adapt you solution to the new problem. So until you have experience with many different kinds of problems, it's hard to solve new problems that you come across. Visiting sites like this and reading questions and theirs answers are a great way of learning how others solved problems that they encountered.

Kibbee
+4  A: 

Basically, "just do it". When you have to make a choice, just make any choice (except flipping a coin).

Once you have something that works, then sit back and scratch your head about what you did wrong and how to do it better.

If you have absolutely no clue how to do even that, just solve a part of the problem completely and move on.

I suggest checking out this book. They aren't the best kid on the block, though they want us to think they are...but they did well with Basecamp.

+1  A: 

Go find an open source or free project you can get excited about and contribute. I learned a lot by signing up to code for my favorite video game modification.

Wildebeest
+1  A: 

Experience.

Study really only goes so far. Find something fun and small. Do it.

Paul Nathan
+1  A: 

One way that seems to work for a lot of people is to pick use a book like Programming Challenges as a guide, and focus on solving problems of a particular type. For example if you're weak in an area like graph problems or dynamic programming, find a set of problems on an online judge and work through them. You'll start to recognize patterns and be able to classify problems.

vinc456
+1  A: 
  • Google for an answer. Chances are someone else has solved the same problem or a similar problem before.
  • Ask on SO. :)
  • Read some textbooks or online articles about design patterns.
  • Problems may have many solutions, some simpler and some more complicated. Don't get stuck thinking there is only one solution. Just go with the simplest solution that makes the most sense in the context of your application.
  • After years of experience you'll be able to think of your own solutions to most problems. :)
davogones
+1  A: 

Hi,

Study Algorithms!

Search and get a hold on as many examples, books on the subject programming or otherwise, etc.

Problem solving skills can also be improved by playing tactical games.

These made me Enjoy problem solving and become better (not necessarily good) at problem solving:

Chess and igo

Ric Tokyo
+2  A: 
  • Ask someone else. Someone in your office, on Twitter or SO, or even your wife. People with no technical knowledge often come up with simpler solutions.

If you must solve it on your own, try one of these others:

  • Do a quick search for another person or project which has tried to solve your problem. If they have a blog, documentation or source code, you might be able to learn from their implementation.

  • Come up with at least TWO solutions and pick the best one.

  • Pretend you have 15 minutes to solve the problem before the civilized world is destroyed by Nuclear War / Skynet / Permanent endless re-runs of Seinfeld, you might think of something much simpler which gets 99% of the work done.

too much php
A: 

Here some tools that I've used in the past to help me understand a particular problem and its solution. I don't always use them today, but they helped me to learn how to think about breaking down a problem and coming up with a solution.

  1. Class-Responsibility-Collaboration (CRC) cards One card per class, details the responsibility of the class and what other classes it collaborates with. Using cards you can layout your design for the solution and see where you have too much coupling or too much responsibility. They allow you to think about the design in a lightweight manner before committing to code.

  2. Use cases Either actual structured use cases that describe user interaction with the system or even briefer stories or story cards. I still use stories, though I capture them in a wiki instead. This allows you to capture the interaction with the system in an informal way. Stories are basically placeholders for conversations that you need to have with the customer about what is supposed to be done. Using the collected stories, you start getting a grasp on the overall intention of the code. You can also start seeing how things interact and what works with other things. This is really the beginning of design.

  3. UML Diagrams - particularly interaction diagrams For awhile I used these a lot. It really helped to see how things actually worked together under the hood. I will still diagram, informally, some complex interactions to make sure I don't miss anything important. Going through a lot of these really helped me to think about how my objects interacted and now it is sort of second nature to think in terms of interactions.

  4. Class diagrams -- a really high level view of the code. These allow you to see your code structurally, especially if you can break the diagram down into components or layers of architecture. Mostly I use these now to explain the code to other people when necessary. When starting out these provide a pretty good visualization, though, if you're struggling with the bird's-eye view of the code.

The best advice I can give you if you try these is to follow the "rules" until you really have a good grasp of what is going on. Once you feel like you have a better understanding of what they provide, you can use them or not, or modify how you use them to keep only what is helpful and let the other stuff go.

tvanfosson
+2  A: 
Jason
+1  A: 

I like this general method:

  1. List the possible solutions with their strengths and weaknesses
    (This will push you to briefly taste all of them)
  2. Chose the best one and make your design on it
    (If you find any heavy obstacle, reconsider other options)
  3. Implement

most importantly, on every step, learn

total
+1  A: 

The best way is probably to learn form a master if that's an option. Especially if you can find someone familiar with the problems your addressing.

Generally the more tools we have at hand the more options we have for tackling a problem. I agree that's important to always code and to always deliver something that works (however inelegant it is). But I think we need to increase our skills/knowledge in many directions:

  • Language skills (know your language(s) in depth)
  • Programming paradigms (Imperative, Object, Functional)
  • Framework knowledge
  • Algorithms
  • Patterns
  • Date-Structures
  • Methodologies (Agile, DDD, BDD, ?DD)
  • Tools
  • etc

You can get a lot of skill through on the job just-in-time-learning, but I usually have a pet subject at any time that I'm trying to get a deeper understanding of, typically this means getting the book and reading it cover to cover.

it depends
+3  A: 

When all you have is a hammer, everything begins to look like a nail.

So, make sure you're well versed in algorithms and data structures. When you study them, think hard about what sort of uses a particular algorithm is good for.

dicroce
@dicroce - I just loved the way you said it :-) ! gets my +1 (more if I had 'em)
Gollum
+1  A: 

Work your way through Project Euler, and look at other people's solutions to the problems. Almost every problem will have been solved in a way that wouldn't have occurred to you, and usually with greater efficiency.

+1  A: 

I think that there is a lot more than raw experience involved in becoming a good problem solver - because I've seen poor problem solvers with lots of experience.

Here are a few tips but you can find many more around the web.

  • Look at a number of problems and figure out what they have in common. The greater the generality with which you understand the solution to a problem, the more you can apply it to other problems.
  • Try to discover approaches which good problem solvers use to solve problem. But don't assume anyone has monopoly on problem solving
  • If you read Richard Feynman's books, you'll notice that he considers many different routes to get to his goal. Don't narrow your approach prematurely
  • Be positive. Assume that you can find the solution to anything. Your state of mind matters. Enjoying the process of problem solving makes it much easier
  • Don't beat your head against the wall. If you don't seem to be making progress with one approach, try another approach
  • Always be looking for more ways of solving problems and more insights into the process of problem solving itself
  • Be willing to work. It still can take a lot of effort solve some problems
  • The more different fields of study you know, the more viewpoints you have. I have a strong math background and I find it very useful for many problems. Physics, music or any different viewpoint might be useful
Joe Soul-bringer