Wednesday, August 25, 2010

Who are you writing code for?

Currently, I have come to realize that I have a flawed methodology for how I write code. My main solace is that it appears to be a flaw shared by many of my peers. This flaw, simply put, is that I try and design all of my code with the belief that somebody else will try and use it in something they do.

The intent here is usually altruistic. I want to share somebody else the burden of having to implement a few ideas that I had in my head. Just as I will do a quick search for how others have accomplished something, so too do I hope that somebody might find what I have done in one of their quick searches.

I will confess this is not always the case. Sometimes, I just want to force others to do something the exact way that I am doing it. In the cases where somebody is trying to add to something I have done, I have little qualm with this thought. (Almost amusingly to my point, the person most likely restricted in how they can add functionality to my code will be myself.)

Of course, despite which of the reasons I am holding as to why I am trying to make something reusable, the reality is that I will be forcing whoever tries to implement my idea to do so in the exact same way that I did. Some of this will be through my own lack of understanding when it comes to API creation. Most will come to down to my simply not seeing how somebody else would want to reuse something.

This inability to see possible uses should be no surprise. The people that actually interact with my code more than anyone else will be the users of the system I am helping to write. While they will never see a line of code I have written, they will be quite familiar with what it accomplished. Worse, for me, is that they will likely have envisioned something subtly different than I did when they want to use the application.

It is a common enough event to have to take some customer feedback into consideration when building something for them. How could I possibly think I could design some code for other developers, with limited feedback from them?

Who then should I write for? It makes little sense to write the code simply for the end user. After all, they simply see what it does, not how it does it. They are far from concerned over whether or not I used enough patterns when I implemented their system. They probably don't even know the different languages and styles I have to choose from. Why should they?

I am tempted to say that code should be written strictly for myself. I am reading it more than anybody else. I am the one writing tests for it. I am likely the one that will have to track down bugs in it. So, if I wish to try and write everything using a declarative style because that is easier for me to understand the intent when I look at it later, then I think it makes sense to continue to use a declarative style.

I realize that many work in a team, however, so for you I have no real answers. I still believe that you yourself are the most likely person to revisit code that you wrote. Do it in a way that you feel is understandable, but get it done. Don't fret over how someone else will use it later. When the time comes, they will find a way to do so.

No comments: