views:

2454

answers:

9

We learn programming by writing programs and learning from other programs. Which open source code repositories/programs you suggest for learning/improving programming? While citing reference please also mention the thing you liked about it.

+3  A: 

It depends upon your interests, but I had worked with the Quake III codebase, and that was fairly well-written and nice to work with. It is written in C.

Jim Buck
+7  A: 

I would recommend Scott Hanselman's weekly source code articles, he does exactly what your proposing, that is read more source code to get better. It's worth the read.

Daniel Pollard
+2  A: 

You'll find lots of examples. But has Jim Buck said, it depends on your interests. I've learned a metric s-- ton of "stuff" from the SharpDevelop source.

hometoast
+1  A: 

If anyone has a copy of Code Reading by Diomidis Spinellis, what open-source projects does he write about there?


@Avinash: If you want to learn more about programming in general, I would recommend both Code Reading and Code Quality by Spinellis. They have code samples from various projects, all FOSS, I believe, so you can not only read about them, but go and get the version discussed in the book and the latest version to read more code from them and learn.


Thomas Owens
+2  A: 

The Linux kernel is a very good way to learn.

I know it may be difficult to dive into because of the multi-architectural structure and the large amount of code but there's some very good article to go slowly inside, like this one from Tim Jones.

I've learned a lot by looking at a specific subject, like the FAT driver implementation and filesystems abstraction.

paulgreg
+5  A: 

I can recommend Simon Tatham's puzzle collection. It's a series of puzzle games (minesweeper, sudoku, fifteen) available for Windows, OS X and Linux (and as java applets). The architecture is quite simple: there's a front-end interface with three implementations (one per platform), a back-end interface with one implementation per game (I've given three examples) and a mid-end that makes them talk together, do serialization and other neat stuff.

Basically, it's good OOP. Written in C. It's easy to contribute to (I implemented the Filling and Range games) since it's well documented, and it's easy to read.

Jonas Kölker
+1  A: 

I thoroughly recommend Code Complete 2nd Edition (ISBN: 0735619670) written by Steve McConnell. For the most part, it uses C++ as its lingua franca, however it has occasional mentions of Visual Basic code. In fact, this book was actually used throughout my college's computer science department for advocating good coding practices. And, to be frank, after reading this book, my coding skills and productivity improved by leaps and bounds.

Marlon
I think the question specifically asks about open source projects. I don't think mention about a book qualifies as an answer.
ragu.pattabi
"We learn programming by writing programs and learning from other programs." While I did not directly answer the question by responding with a specific example of an OSS project, it does supplement the above statement. If it assists Avinash (or anyone else for that matter) in their pursuit for coding glory, then yes, this answer is relevant and hence, it qualifies as an answer...
Marlon
+2  A: 

Relatively small, yet with enough complexity to be able to learn from, my vote goes to:

Apache's Log4Net logging framework.

It's source code is very readable, and "cross-platform" [compilable on: .NET 1.0, 1.1, 2.0, CF, MONO...], thus being valuable for lesson in "cross-platform" C# development...

Jox
A: 

One of the best pieces I've found of clear and concise source code is the jQuery source. Whether you like Javascript or not, it makes a great case against advocates of "code being the documentation".

There's lots of comments but it's not ascii artwork and you can see clear reasoning going - the comments make you know exactly what is trying to be achieved.

An example (full source):

(function(){

var 
    // Will speed up references to window, and allows munging its name.
    window = this,
    // Will speed up references to undefined, and allows munging its name.
    undefined,
    // Map over jQuery in case of overwrite
    _jQuery = window.jQuery,
    // Map over the $ in case of overwrite
    _$ = window.$,

    jQuery = window.jQuery = window.$ = function( selector, context ) {
        // The jQuery object is actually just the init constructor 'enhanced'
        return new jQuery.fn.init( selector, context );
    },

    // A simple way to check for HTML strings or ID strings
    // (both of which we optimize for)
    quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#([\w-]+)$/,
    // Is it a simple selector
    isSimple = /^.[^:#\[\.,]*$/;

jQuery.fn = jQuery.prototype = {
    init: function( selector, context ) {
        // Make sure that a selection was provided
        selector = selector || document;

        // Handle $(DOMElement)
        if ( selector.nodeType ) {
            this[0] = selector;
            this.length = 1;
            this.context = selector;
            return this;
        }
        // Handle HTML strings
        if ( typeof selector === "string" ) {
            // Are we dealing with HTML string or an ID?
            var match = quickExpr.exec( selector );

            // Verify a match, and that no context was specified for #id
            if ( match && (match[1] || !context) ) {

                // HANDLE: $(html) -> $(array)
                if ( match[1] )
                    selector = jQuery.clean( [ match[1] ], context );

                // HANDLE: $("#id")
                else {
                    var elem = document.getElementById( match[3] );

                    // Handle the case where IE and Opera return items
                    // by name instead of ID
                    if ( elem && elem.id != match[3] )
                        return jQuery().find( selector );

...
Chris S
Most comments could have been avoided. "code being the documentation" is not about littering the code with comments, really. Martin fowler enlightened me when I read that comments are code smells.
ragu.pattabi