What does a good programmer's code look like?

Alex P picture Alex P · Dec 14, 2008 · Viewed 70.2k times · Source

I am a hobbyist programmer (started with VBA to make excel quicker) and have been working with VB.NET / C#.NET and am trying to learn ADO.NET.

A facet of programming that has always frustrated me is what does 'good' look like? I am not a professional so have little to compare against. What makes a better programmer? Is it:

  • They have a better understanding of all the objects / classes / methods in a given language?
  • Their programs are more efficient?
  • The design of their programs are much better in terms of better documentation, good choice of names for functions etc.?

Put another way, if I were to look at the code of a professional programmer, what is the first thing that I would notice about their code relative to mine? For example, I read books like 'Professional ASP.NET' by Wrox press. Are the code examples in that book 'world class'? Is that the pinnacle? Would any top-gun programmer look at that code and think it was good code?

Answer

tvanfosson picture tvanfosson · Dec 14, 2008

The list below is not comprehensive, but these are the things that I thought of in considering your question.

  • Good code is well-organized. Data and operations in classes fit together. There aren't extraneous dependencies between classes. It does not look like "spaghetti."

  • Good code comments explain why things are done not what is done. The code itself explains what is done. The need for comments should be minimal.

  • Good code uses meaningful naming conventions for all but the most transient of objects. the name of something is informative about when and how to use the object.

  • Good code is well-tested. Tests serve as an executable specification of the code and examples of its use.

  • Good code is not "clever". It does things in straightforward, obvious ways.

  • Good code is developed in small, easy to read units of computation. These units are reused throughout the code.

I haven't read it yet, but the book I'm planning to read on this topic is Clean Code by Robert C. Martin.