A few days ago, Richard and I were talking about code to read. I think that you can learn a lot as a programmer by simply reading the code of others, in much the same way writers improve their craft by reading the works of their peers. So the obvious question, then, is what to read? There is obviously a lot of shit code out there, and if you decide to read some bad code with the intent of honing your own skills, it may very well have the opposite effect.
So below are some of my thoughts on code that is worth reading, broken up by language. I have restricted this to languages we use here at Cyber Sprocket, but I urge everyone to contribute anything useful they can think of, regardless of whether or not it’s written in a language we use.
If you want to learn some advanced Python, like how to use meta classes in a real-world situation, then look at the code for Django. Specifically the code for
django.db.models.ModelBase. It can really show you the differences between things like
__init__() for creating classes. Keep in mind that Django uses Python 2, and there are notable differences in Python 3. Right now I don’t know of a killer app in Python 3 that I could recommend to you.
Grab the code for PHPUnit (http://www.phpunit.de) and check it out. It is a fantastic example of well-structure PHP code. The gritty details of the style are not the best, which is to say that it breaks a number of our internal standards. But the logic of PHPUnit is very sound. And on top of that, it really makes good use of PHP’s object system by taking full advantage of things like standard library interfaces (e.g. `Countable`).
And besides, how many PHP applications do you see use type hinting in function declarations? Really? PHPUnit is great through-and-through. Also—we should use PHPUnit for unit testing our PHP applications, in my opinion. But that’s another discussion for some other time, like a standards meeting.