About the author

Steven Harmansteven harman :: makes sweet software with computers!

For recent posts and more about me, scroll to the bottom.

Subscribe

  • Subscribe to my feed. via RSS
  • Subscribe via email via email

News

Badges

  • Subtext Project
  • Support Subtext

Reading Code is Key to Writing Good Code

As humans we seem to have an innate desire for structure in our lives. Structure permeates through our societies; it’s found within our families, education systems, governments, etc. I suppose it’s no surprise then that we also seek to force structure upon the work that we, as software developers, do.

The problem is the work we do isn’t structured. It is not deterministic. There is no grand blue print, process, nor methodology that we can follow to pay dirt.

We live in a chaotic and complex world that is itself continuously changing and adapting.

Software product development is a creative activity taking place in the midst of that complex and adaptive world. So doesn’t it make sense that we, as software developers, might benefit from admitting that we are indeed doing creative, unstructured, adaptive work? I sure think so!

Looking outward for inspiration

I’ve recently been looking outward to other creative professions and trades for inspiration and insights into how they work. One thing I’ve realized is that those folks spend an immense amount of time studying and seeking inspiration from the work of others both within and outside their own field.

For example, a musician doesn’t just sit in his garage all day, banging out albums. He listens to and is influenced by the music of many other musicians. An author doesn’t simply site down and write manuscript after manuscript. She spends countless hours reading the classics, studying the words, flow, and style of other authors. The same thing goes for painters, actors, architects, etc. And all of these people are constantly immersing them selves in works outside their area; musicians reading Hemingway, singer/song writers studying Salvador Dali, painters listening to Mozart, cats and dogs living together…

How arrogant of we programmers then to think that we won’t, or don’t, benefit from reading code written by – gasp – someone else!

Read, learn, and be inspired

read!In my experience we spend a great deal more time reading code than actually writing it. Whether it be the code you wrote just a few minutes ago or something you’ve inherited and are now maintaining, you’re reading it. Of course, that’s only considering the motive of reading code because you’re currently working with.

The greatest motivator for reading code is the opportunity it provides for learning and serving as a source of inspiration. Reading code exposes you to techniques, view points, styles, idioms, and algorithms that you may not have otherwise come across.

In my own career it was by reading code written in Ruby that I first started to develop an appreciation for beauty and aesthetics in code. It also opened me to new ways of thinking about problems and exposed many pains and frictions with the techniques I had been using to that point.

Where to start?

I realize it’s probably obvious, but I’m going to say it anyhow – a great way to start reading other’s code is to pull down an Open Source project and dive in. Of course, that’s not to say that all Open Source code bases are necessarily examples of great code… so you might also want to leverage your network to find examples. Or, use your Google-fu to see what others are reading. Or maybe check out:

kick it on DotNetKicks.com

What others are saying.

# re: Reading Code is Key to Writing Good Code
Gravatar Paul Beckford
Nov 18, 2009
Hi Steve,

We've known that software development is basically an artisan craft for a very long while. The problem is though, this isn't the answer the people in "control" want to hear.

Fred Brooks was amongst the first to make the point that software development is a non-deterministic problem. His famous "Uber Programmer" who is up to ten times more effective then the average programmer makes the point.

A fun read is the report of the 1968 Nato Conference on "Software Engineering". It is where the term "Software Engineering" was coined. The participants at the Conference such as Dijkstra weren't sure that Software development was "Engineering" at all. Yet everyone wanted practices that were more deterministic so they did there best :)

http://homepages.cs.ncl.ac.uk/brian.randell/NATO/

It's worth a read, they said pretty much the same as yourself in between the lines, but they were asked for deterministic practices so they gave it there best guess.

It's taken 40 years for someone to come out and put in print what we've all know intuitively for a long while, and what the Nato Conference attendees knew deep down too. Software Development isn't Engineering:

www.computer.org/.../rW_SO_Viewpoints.pdf

Despite this, some in the Lean camp are still trying to pretend that we can use an industrial metaphor to produce software. Why? Because just like in the 1960's that's what the Management classes want to hear :)
# re: Reading Code is Key to Writing Good Code
Gravatar Tim
Nov 19, 2009
This is very similar to the message that Dave Hoover and Paul Pagel delivered at one of the SCNA sessions in Chicago. They showed some sample art from Picasso as he was recreating the classics before he did his own thing. Uncle Bob brought up similar points, why not read the software "classics" before starting something? The source is out there for Rails, or nHibernate, or Spring...go read it.
# re: Reading Code is Key to Writing Good Code
Gravatar labilbe
Nov 28, 2009
I like to watch http://www.dimecasts.net/
Short video casts (10-15 minutes), but worth it!
# re: Reading Code is Key to Writing Good Code
Gravatar Chris Fulstow
Dec 02, 2009
Great article, agree completely. Examples are a bit dated now, but here are a few other places to find source code to read:

3poundmass.wordpress.com/.../reading-other-peop...
# re: Reading Code is Key to Writing Good Code
Gravatar Vitaly
Dec 15, 2009
If to treat the code as a the speech, reading is the efficient practice to get involved in native speaking stream. Trying to understand the code one applies for dictionaries, tutorials and other additional information.

Suppose, reading code with mistakes or even LOLcode is also useful to become a professional.
# re: Reading Code is Key to Writing Good Code
Gravatar Binu
Jan 26, 2010
Nice article, Thanks for the info. :)
#  re: Reading Code is Key to Writing Good Code
Gravatar rakeback
Jan 31, 2010
I agree that reading code is vitally important to become a good coder. When I first started learning, I remember downloading a bunch of simple source codes and messing around with them. Once you have an understanding of all the syntax and the basics of the language, I think that the best way to learn to code is by looking at examples and doing trial and error on it to find out how it works.

What do you have to say?

Title*
Name*
Email (never displayed)
(will show your gravatar)
Url
Comment*  
Please add 6 and 7 and type the answer here: