Comments Violate DRY

Was talking to a colleague, friend and mentor Troy Bourgeois and in the course of the conversation he said something that struck me. He said writing code comments is just another form of repeating yourself.

I’ve been thinking about this all night. Just like copied code is a symptom of not getting the abstraction right, commenting is a symptom of not getting the code right. Code is supposed to communicate its intent. If it doesn't, then you comment in order to do so.

The real question here is why I feel like I have to add a disclaimer every time I say commenting is a smell? Whether it’s in front of college students, professionals or colleagues. I truly believe that the desire to write a comment is a sign that your code doesn’t communicate effectively, but I guess I fear that people will not strive to write code that doesn’t need comments and rather just omit them.

As Uncle Bob said:
It's not about _omitting_ comments, it's about making them unnecessary.

No one is trained to do it

In reference to:

The key here is that we are all at a loss in this field. As far as professional software development goes, no one is trained to do it via our education... not even the CS people, so we need to be constantly searching for professional practices that have been proven in the field to work and evaluate them for inclusion in our own work.

Now that doesn't mean once you've found something that works you are done and can coast until retirement. This industry is still quite young and as professionals in it, during these formative times, we must keep our ear to the ground and our eyes to the horizon because even the professional practices that work fine for *us* at the *moment* may not be the best possible as new methods and techniques are tried and evaluated every day across the globe.

We are professionals in an exciting field at an exciting, and notably unregulated, time. With that comes a lot of freedom and therefore a lot of responsibility that we must impose upon ourselves. Even now, clients can't tell the difference between good development and bad development until it is way too late so we cannot wait for the market to drive us to find better techniques, because it can't. *We* must drive ourselves. But in much the same way we have difficulty differentiating between high skilled and low skilled developers until the product falls, crashing down around us. And, truly, even then we have difficulty determining the fault because of the overwhelming number of variables involved in the project. Iterative methodologies are our *current* attempt to overcome this problem by pushing awareness that before only came at the end, up to the beginning. Giving us the chance to evaluate, adjust, correct and improve.

We must be constantly practicing and training ourselves in new methodologies for "the pursuit of unattainable perfection". 100 years from now, software developers will only be able to dream of the freedom-to-achieve that we have today in this field. Much like we view the wild west, I’d imagine.

We have a chance today to be really great and we must put forth the effort to reach and take it ourselves. For when the day comes that client’s can tell the difference between good and bad development, you do not want to be caught napping.

McConnell: Software Engineering, Not Computer Science

Chapter 4: Software Engineering, Not Computer Science
A scientist builds in order to learn; an engineer learns in order to build.
— Fred Brooks



The chapter linked above challenged some beliefs that I hold to very tightly, but it also brought clarity and confirmation to notions that I’ve deduced myself and held for a long time. It’s a long article, but worth it. I won’t soon forget the House/Shed Comparison I expect.

As with everything I’ve read from McConnell his terminology can be vague and, therefore interpreted in vastly different ways by different people. For me, in the House/Shed Comparison, I consider McConnell to be referring to ‘Engineering’ as application design, not construction. So if one were to say: “Look‘a here buddy, I’m just constructing a shed, therefore I don’t need to implement SOLID principles, write patterned code, or create unit tests…” I will call BS. Because it’s not in the integrity of construction he is saying an insulated shed is over-engineered, but rather in its bloated feature set. Both the house and the shed need a solid foundation, square frames, and twice-measured lengths i.e. quality construction. It’s in the unnecessary amenity of insulation for the shed that McConnell finds over-engineering.

For those who think McConnell’s reference to “code-and-fix” means iterative development, I direct you to this definition: http://en.wikipedia.org/wiki/Code_and_fix.

But alas, to the point… ;)
Regardless of my interpretation, I’m curious to know yours.




Excerpts (for the ‘TLDR’-ers):
[…]
Engineering vs. Science
With only about 40 percent of software developers holding computer science degrees and practically none holding degrees in software engineering, we shouldn’t be surprised to find people confused about the difference between software engineering and computer science. […] Scientists learn what is true, how to test hypotheses, and how to extend knowledge in their field. Engineers learn what is true, what is useful, and how to apply well-understood knowledge to solve practical problems. Scientists must keep up to date with the latest research. Engineers must be familiar with knowledge that has already proven to be reliable and effective. […] An undergraduate science education prepares students to continue their studies. An undergraduate engineering education prepares students to enter the workforce immediately after completing their studies.
[…]
This puts computer science students into a technological no-man’s land. They are called scientists, but they are performing job functions that are traditionally performed by engineers, without the benefit of engineering training. The effect is roughly the same as it would be if you assigned a physics Ph.D. to design electrical equipment for commercial sale. […] We would expect the equipment designed by the physics Ph.D. to work, but perhaps to lack some of the robustness that would make it usable or safe outside a laboratory.
[…]
[workers educated as computer scientists] focus narrowly and deeply on minor considerations to the exclusion of other factors that are more important. They might spend two days hand-tuning a sorting algorithm instead of two hours using a code library or copying a suitable algorithm from a book.
[…]
The lack of professional development isn’t solely the software developer’s failure. The software world has become a victim of its own success. The software job market has been growing faster than the educational infrastructure needed to support it, and so more than half the people holding software development jobs have been educated in subjects other than software.
[…]
When a building is designed, the construction materials must suit the building’s purpose. I can build a large equipment shed to store farming vehicles from thin, uninsulated sheet metal. I wouldn’t build a house the same way. But even though the house is sturdier and warmer, we wouldn’t refer to the shed as being inferior to the house in any way. The shed has been designed appropriately for its intended purpose. If it had been built the same way as a house, we might even criticize it for being “over-engineered”—a judgment that the designers wasted resources in building it and that it actually isn’t well engineered.
[…]
Today’s pervasive reliance on code-and-fix development—and the cost and schedule overruns that go with it—is not the result of a software engineering calculation, but of too little education and training in software engineering practices.