Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I've tried a few times to look at the source code for various things from github or other sites, in javascript, C#, PHP, etc. I'm never able to understand the programs as a whole though. I can sort of piece together what a specific snippet of code does, but I quickly lose the context of what I'm looking at and how it fits in.

I want to be able to improve, but everything I've tried learning from so far has been too big. Where can I find well-written, but not very complex source code to look at?

edit: Sorry, to be more specific, I'm hoping for javascript/php/C#.

share|improve this question
4  
Problem is that you need a certain amount of non-simpleness for your program to do something actually useful. Perhaps you should try building something useful first to get some more experience and then have a go again? –  user1249 Mar 11 '12 at 23:18
    
You have to use it and really want to use it for a while to really learn it. –  Job Mar 12 '12 at 0:10
    
Have you tried, dunno, books and manuals? They come with examples. –  ZJR Mar 12 '12 at 1:37
    
Read the jQuery source: code.jquery.com/jquery-latest.js It's very easy to read and well written. –  mash Apr 10 '12 at 21:57

5 Answers 5

up vote 4 down vote accepted

The issue that you are facing is very real. You are always told to look at real word examples and then you find out that real word is ... not always a good example. You have a lot of code to go through, not all of which is at the same level or is good learning material, for various possible reasons.

Having said that, it depends on the kind of languages/projects you are interested. You could focus on a particular aspect and instead of studying the whole program focus on the single aspect. This is very similar to debugging: you have a large codebase and you are focused on debugging a particular crash in a particular situation: you have to be able to find your way through the layers of code until you reach the bug and (possibly) fix it.

So maybe you could look at a Open Source program that you use everyday and ask yourself "I wonder how they managed to do that"...then go and find out. Try to leave out the details which are not relevant and to isolate the functionality that you care for. If this doesn't work so well, maybe you just need to try again, or maybe the real world example was not so good to start with.

Now, to answer your explicit question one would need to know exactly what languages you know or want to learn. For instance, if C is among these, you should read (or re-read) Kernigan and Ritchie and do the exercise and then study the implementation of the actual unix commands which they have taught. For me, one of the largest body of sw that I studied almost 20 years ago was that of DikuMUD but that is not necessarily the best example I can think of (for sure it was fun!)

share|improve this answer

Looking for other code to read might be the wrong way of going about it. Most applications start off simple but become more complex as they progress, requiring you to know the business logic surrounding it or simply the quirks and preferences of an individual programmer.

A better way to learn might be to participate in a peer review system (not sure if one exists). I've only just started using github, but the fork system seems ideal for this. You post a simple project, ask for comments, well-meaning developers can then fork and send you a pull request. This would give you a diff of how they would have done it and, hopefully, comments about why.

I'm not sure that answers your direct question, but would hopefully be a way of learning.

share|improve this answer

How about looking at your own

Honestly, I learned that the best code to look at is your own code. Find your largest project. Pick it out piece-by-piece and find even the simplest things that can make your code shorter, faster, and better.

Then add on to it and follow the same steps.

Eventually, you really won't be able to find anything because you will be writing the best code you can.

If you want to look at code to learn new functions/methods and other things that you still don't know, then I would recommend doing the following:

  1. Find the official documentation on the language you choose.
  2. Choose a new function that you've never used.
  3. Write a bunch of code with what you've learned, and find ways to make it better.
  4. Repeat 1-3.

This is how I grew the most as a programmer. Just look at your own code.

share|improve this answer
    
If you look at your own old code you can just laugh about it because you'll go on and get better but your code will stay as bad as is was when you've written it. –  mash Apr 10 '12 at 22:01

You could do these:

  • google for what specific thing you want to do using any programming language. This will show you more than one way of doing the same thing, each possibly with a comment about what is good and bad about that method

  • Solve the problem best you can using what you know. Post it at a place like code review here on SE and ask if your code can be written in a better way to do the same work

There will come a time when you'd asking fewer questions and giving more answers. That will mark the completion of the first step of your journey to improvement.

share|improve this answer

I guess that what you should be looking at is books, and high quality blogs. Concentrate on problem solving, try to understand the concepts and why they were used. And try to use them in your code as you read.

Real world applications are almost always too big to understand, and have multiple, often incompatible styles mixed. And most often than not, have some fundamental problems as well.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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