views:

80

answers:

4

I find myself viewing the source code for OSS projects like Spring, Hibernate, Google Collections, Commons Collections and recently the JDK's concurrent utils (well the entire JDK actually).

I find myself learning quite a bit from seeing how such code is written -- without any sense as to whether I'm reading crap or not, but I take it that when I read something in Java Collections authored by Gafter/Bloch it's generally good.

So with this abundance of de facto "good code" in all spheres Python, Ruby etc. shouldn't this mean that the standard of code should be rising and that anyone can write good code or is it a question of you either have talent or not?

A: 

People with talent and good training write good code. People who read good code get more training. Thus, everyone can brush up their skills with crowdsourced peer review.

I'd say the most notable and distinctive impact is in helping people transition from script-hackers to genuine, bootstrapped programmers.

The average quality might rise to a limited degree, but it is mitigated by OSS's tendency to generate a lot of bad code along with the good.

Grayside
+1  A: 

You can learn just as much from reading poor code as you will from reading good code - as long as you realise that it's poor code and don't just copy its mistakes of course!

Indeed, a great way to learn is to read several different authors' takes on the same problem - you can often pick the best ad worst bits from several programmers and then write your own version that is better than all the others, because you can keep only the best from each approach. This is where Code Golf and programming competitions can be very useful, even if you don't take part in the competition itself.

Jason Williams
+2  A: 

Although reading the others' code may be helpful, it may also be devastating. If you have no feeling yet to tell good code and bad code apart, you may end up learning wrong things.

I thing following are the right steps to improve your skills:

  1. You first practice a lot
  2. You read others' code when needed
  3. You read some "philosophical" books that will tell you what is right and what is wrong. I mean books like "Pragmatic Programmer" or "Code Complete". You need however to have some practice behind to make it through them, otherwise they will bore you to sleep.

Regarding talent, yes, you need something within you, call it talent, inspiration, the right eye or.... The Tao of Programming.

Programmers that do not comprehend the Tao are always running out of time and space for their programs. Programmers that comprehend the Tao always have enough time and space to accomplish their goals.

How could it be otherwise?

Developer Art
+1  A: 

The broadest point I can make is: just read code, and ask yourself what you think of the various choices its authors made. If you start to get the sense that the code is crap, move elsewhere.

It also may help to consider how rigorously peer-reviewed the code in question was. Code that was just written by one person, no matter how good, is never going to be truly great code.

I can say from direct experience that the code in Google Collections is very, very rigorously reviewed. Written and reviewed by several of the finest Java developers I have ever known -- and me!

(By the way, nothing will improve your own coding more than finding great reviewers to check over what you yourself write!)

Kevin Bourrillion