InfoQ

News

Writing Maintainable Code

Posted by Hartmut Wilms on Jun 25, 2007 10:07 AM

Community
Java,
Agile,
.NET,
Ruby
Topics
Programming
Tags
Best Practices,
Documentation,
TDD

Sam Gentile, Oren Eini (aka Ayende), and Frans Bouma have an ongoing debate in the .NET community about how to write maintainable code, which several others have joined. The debate mainly focuses on the question, if Test-Driven-Development (TDD), O/R-Mappers (ORM), Model-View-Presenter/Controller (MVP/MVC), and other best-practices help to improve the maintainability of software.

Jdn started the debate with his thoughts on Maintainability, in which he expressed his concerns about how TDD, ORMs, and MVP/MVC might possibly hinder productivity and maintainability instead of boosting it:

One problem (well, it's really more than one).  I know for a fact that I am going to be handing this application off to other people.  I will not be maintaining it.  I know the people who I will be handing it off to, so I know their skill sets, I know generally how they like to code.

Oren Eini responded to this in his post "Maintainable, but for whom?". He agrees that it would be difficult (or even impossible) for developers unskilled in TDD, ORM, MVP/MVC to maintain a system build on theses practices and frameworks. But he thinks that keeping up bad practice in order to produce code that might be maintained by others is just a bad excuse:

Doing it the old way seams defeatist to me [...]. It is the old "we have always done it this way" approach. Sure, you can use a mule to plow a field, it works. But a tractor would do much better job, even though it require knowing how to drive first.

Sam Gentile joins the debate and agrees with Oren saying that teaching developers best practices, such as TDD, DDD, and ORM, pays off in "real world" projects, too. He summarizes the debate on his blog and responds to Frans Bourma's claim that "you can't live without proper solid documentation". According to Bouma TDD doesn't help to understand the inner workings of a software and that "there's likely a lack of in-depth design documents which illustrate WHY a piece of code was constructed that way and why for example alternative algorithm B and C were rejected. THAT is info which makes software more maintainable.". Sam Gentile responds:

there is more than unit tests. There is code developed in pairs that is highly refactored. When people talk about the code being maintainable and "extensible", it's not that we have plug-ins. Its evolving the INTERNAL implementation of the code continuously and constantly refactoring it to be simple and maintainable. I do contend that the code developed this way is more maintainable and possible of future growth without ripping everything apart and starting over. Let's put it this way: I can be away from our code base for a month and with the unit tests and the well factored code, i can find whats going on in minutes.

Frans Bouma takes the bait and counters that "it takes a lot of effort by a human to correctly parse code and fully understand what the code does. That's a mistake often made by the 'the code is the documentation'-camp". In his opinion "code can't replace your documentation: it only shows what the current implementation is, but not WHY alternatives aren't there, furthermore code is bad documentation: it doesn't show a human in the most easiest way how it works.". Oren Eini joins in again and states that he addresses this problem by "investing a lot of time coming up with intent revealing names and pushing all the infrastructure concerns down". He also responds to Bouma's argument that "documentation isn't a separate entity of the code written: it describes in a certain DSL (i.e human readable and understandable language) what the functionality is all about":

Documentation is not a DSL, and it is most certainly not understandable in many cases. Documentation can be ambiguous in the most insidious ways. The code is not another DSL, this assumes that the code and the documentation are somehow related, but the code is what actually run, so that is the authoritive  on any system.

Although the current debate very much resembles the old debate about "the code is the documentation", many new ideas and arguments have been produced that are worth pondering on. What do you think?

Related Sponsor

VersionOne is recognized by Agile practitioners as the leader in Agile project management tools. Companies such as Adobe, BBC, CNN, Dow, HP, IBM, Sony and 3M have turned to VersionOne to help deliver greater value to their customers.

2 comments

Reply

Writing unMaintainable Code by Iain Forsyth Posted Jun 25, 2007 10:58 AM
"The Code Is The Documentation" is simple reality. by Wayne Mack Posted Jun 29, 2007 9:18 AM
  1. Back to top

    Writing unMaintainable Code

    Jun 25, 2007 10:58 AM by Iain Forsyth

    and old chestnut, but still valid - and funny :-) http://thc.org/root/phun/unmaintain.html

  2. It is not up for debate. The reality is that developers will work with the source code. For programs of any significant length, the documentation, if it ever existed, is incomplete, incorrect, lost, or simply ignored. There is no justification for writing anything less than highly understandable source code. Software libraries seem to be an area where high levels of documentation seem to be expected, but I have discovered over the years that a sample program showing at least one way of using the library correctly is far more useful than pages of documentation that leave it up to me to cobble together a working sequence. Couple the sample program with a test stub for the library and I would be more than happy to give up the written manuals. Does reading unit tests require knowledge and experience? Yes, but no more than reading UML diagrams. The advantage is that the unit tests actually validate correct operation.

Exclusive Content

A Formal Performance Tuning Methodology: Wait-Based Tuning

Steven Haines talks about tackling web application performance tuning by proposing a method called wait-based tuning.

Shaw and Fowler About Forging a New Alliance

Shaw and Fowler talk about the need for a new relationship between the business department and the IT department. Studies have shown that projects mostly fail due to miscommunication between the two.

How to GET a Cup of Coffee

In this article, Jim Webber, Savas Parastatidis and Ian Robinson show how to drive an application's flow through the use of hypermedia in a RESTful application.

Archaeopteryx: A Ruby MIDI Generator

Eccentric artist turned overnight anti-celebrity, Giles Bowkett captures the heart and soul of RubyFringe as he demonstrates his revolutionary Archaeopteryx MIDI drum pattern generator.

Alexandru Popescu Discusses the InfoQ.com Site Architecture

InfoQ Chief Architect Alexandru Popescu discusses the InfoQ architecture, WebWork and DWR, Hibernate and JCR, Hibernate scalability, the new InfoQ video streaming system, and future plans for InfoQ.

LHC Grid: Data storage and analysis for the largest scientific instrument on the planet

higgs-event

The Worldwide Large Hadron Collider (LHC) Computing Grid provides data storage and analysis for the entire high energy physics community that will use the LHC.

Fostering Software Craftsmanship in a Corporate Setting

Scott talks about software craftsmanship represented by people responsible for their work, continuously learning, taking pride in their work, sharing knowledge and respecting professional standards.

Eric Nelson on Windows as a Web Platform

Eric Nelson explores Windows as a web platform using IIS 7.0 providing an architecture deep dive and striving to reduce the lines of code in web applications.