|
Re: What is good code?
|
Posted: Mar 1, 2005 10:32 AM
|
|
Thanks for all the thoughtful comments. I just had one thing to add. I think maybe we've been talking past each other a bit when talking about quality, because we have different ideas of what quality means, so it is good to ask the question what does it mean.
I think there's an aspect of code/design quality that is universal, that cuts across all the projects you work on. Minimizing coupling, maximizing cohesion would fall in that universal category. I have a seminar I teach, most often with Bruce Eckel, in which I try and draw a picture of that universal quality. All of my examples are Java, and it is in many ways specific to Java. So maybe I should say it is universal Java quality. The handouts are here, and they would be my long answer to your question of what quality code looks like:
http://www.artima.com/javaseminars/JavaDesWkshp/index.html
The material is broken up into guidelines, like the organization of Effective C++ or Effective Java. The way I do this seminar is I present a guideline, support it a bit with examples, then open up the floor for discussion. I try to get people talking to each other, because I think that's where the best education comes from. I am trying to do the same thing here in these forums, and I usually learn something myself by following the discussion here.
My first guideline, Guideline Zero, says:
"Every guideline presented in this seminar should be ignored some of the time, including this one."
The reason that's true is because, as Ken Arnold put it, "All designs take place in context." The non-universal aspect of good design is that which depends on the context, the particular thing you're trying to solve. The best I can come up with here is that what seems to help most in both knowing what to design, and recognizing good design, is experience in that domain. As others have put it, if it solves today's problems and faciliates you in solving tomorrow's problem, it is a good design. The trouble with that definition is that although it may help me recognize good design, it doesn't really help me figure out how to create a good design. So although it isn't that satisfying, it is the best way I know how to describe quality at this point. And the best way I know how to get there is having domain experience.
Ken Arnold discussed this topic here:
http://www.artima.com/intv/perfect.html
|
|