I’m finding that attitude and intent make an important contribution to the code I write.

For example, though I currently use NUnit as my testing framework, and Rhino.Mocks for mocking, I’m not always using these to write tests or mocks.

Confused? Let me explain.

When I’m writing some library code for later use – a recent example is a dynamic UI framework – I usually start by writing consumer code, not library code. Adopting this perspective helps me to design the API in a way that is clean, clear and easy to understand – a perspicuous API, if you will.

As this consumer code is written, the requirements and specifications of the library will become clear – and these can be captured as NUnit tests. The key is to note that these are not so much tests as executable specifications. Though the methods are marked as [Test], they are actually much more of a [Specification].

The intention of the code (specification) is more important than the expression of the code (NUnit tests).

Another way that this manifests is how I answer the question “Is it Done?

In the past, I’ve worked with developers who regard a piece of code as “Done” when it compiles and the main flow executes correctly.

Through bitter experience, I’ve reached a different point. To me, code is “Done” when I reasonably expect that no defects will be found in testing, and when a maintenance developer (who might be me, in six months time) can pick up the codebase and work out what is what without too much difficulty.

Again, this is an example of attitude and intention at work – as a productively lazy developer, my intent is to write code that never needs revisiting, and to ensure that any revisit that does occur is as short as possible.

What intent and attitude do you bring to your code?

 

(This post inspired by Chad Myers’ “How do you know your code works?”)

Comments

blog comments powered by Disqus
Next Post
New Year, New Look  24 Jan 2009
Prior Post
Going to Oslo  17 Jan 2009
Related Posts
Browsers and WSL  31 Mar 2024
Factory methods and functions  05 Mar 2023
Using Constructors  27 Feb 2023
An Inconvenient API  18 Feb 2023
Method Archetypes  11 Sep 2022
A bash puzzle, solved  02 Jul 2022
A bash puzzle  25 Jun 2022
Improve your troubleshooting by aggregating errors  11 Jun 2022
Improve your troubleshooting by wrapping errors  28 May 2022
Keep your promises  14 May 2022
Archives
January 2009
2009