Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Often when I'm writing code to do a certain thing, I'm faced with either writing my own or using someone else's code. Assume here that this "thing" is something that I've never done before and am interested in learning how it's done.

Which would you say is better from a learning perspective: try writing your own solution; or looking at code by someone else? I've always written my own code if I have an idea on how to do it, but resorted to looking at someone else's when I don't have a clue. I believe that the best is probably a combination of both: make your own attempt and then look at how someone else did.

share|improve this question

closed as off-topic by durron597, gnat, GlenH7, Snowman, MichaelT May 13 '15 at 0:34

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking career or education advice are off topic on Programmers. They are only meaningful to the asker and do not generate lasting value for the broader programming community. Furthermore, in most cases, any answer is going to be a subjective opinion that may not take into account all the nuances of a (your) particular circumstance." – durron597, gnat, GlenH7, Snowman, Community
If this question can be reworded to fit the rules in the help center, please edit the question.

up vote 11 down vote accepted

First try to write your own. Then look at someone else's solution.

share|improve this answer
+1: Every developer should know that it's a lot harder if the answers aren't 'at the back of the book'. – Steve Evers Oct 27 '10 at 0:09
Also, ask for suggestions as soon as you have some starting idea, as well as after finished writing your first version. – rwong Oct 27 '10 at 5:16
First doing it yourself makes it clear in your mind 1) what you need and 2) what you should look for. We are very careful about letting foreign code in as it usually do something else than you need, but I just love the Google Guava library. – user1249 Oct 27 '10 at 6:15

If I really want to learn how to do X and someone's got a sample online, going through the sample really speeds up how quickly I can write it myself. Stepping through their code gives you one possible starting place on where the code can end up. I may end up with my own code that is no where near the example, but the example got me to that decision.

If the sample is gold code, then I may incorporate it into what I'm doing, but 9 times out of 10 the sample is not quite what I was looking for. In those cases I'll use what I learned with the sample and build my own.

share|improve this answer
+1 for hack a sample first... having a working sample of something I have no point of reference is vastly better than trying to get the IDEA while simultaneously figuring out all the little gotchas – Bill Oct 26 '10 at 22:52
@Bill - exactly my point! – Walter Oct 26 '10 at 22:58
I always try to start this way even though I always end up trashing the example before I am done. I almost never find examples with the right amount of flexibility, but seeing it work hardcoded, or stripping down a over-engineered version still helps me get the idea faster than trying to get there from the manuals most times. – Bill Oct 26 '10 at 23:14

Depends on the size of the required solution and the community feedback to any existing solution.

Useing web dev as an example, I can write a forum but wouldn't bother, just use a respected well known solution, almost anything smaller write myself.

share|improve this answer

Something closely related that I just realised today....

Things that I learn by writing my own program for a real life solution to something stick with me a lot more than doing samples/tutorial/exercises just for the sake of learning.

Walking through a tutorial or sample of something new is good as a basic learning exercise, but if I then walk away from it and have to apply it three weeks later (without looking at that technology at all since), I'll tend to have to Google things, revisit, look up, etc, a lot more than if I did a real program in it. It's only when I actually create something from scratch for myself in a given programming language or technology that it really sticks, and that I internalize the knowledge.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.