Theory vs. Practice in coding

September 9, 2008 – 1:45 pm Tags:

When working on a project, I sometimes find myself stuck - thinking about some implementation detail, such as how to tell my admin-module which other modules are installed in my CMS (but that’s another story) - and being stuck, unable to get anything done, just thinking of the problem at hand, because I want to find the best possible way to solve it…

A theoretical problem

The problems that get me stuck like this are always basically just some theoretical problems… How to arrange some directories and files in a reasonable manner, how to make some classes talk with each other, how to implement some complex feature.

Most of them don’t have a definite answer. You could arrange dirs and files in many ways that could make sense, and in the coding problems there’s always many ways to approach it.

While it helps to plan ahead, I just try to find the most optimal solution, and it isn’t always possible right away, and I end up getting stuck.

A practical solution

So what’s the best way to get out of an endless loop? Do something about it!

First, it may help to write down some notes. What does the feature you’re thinking about need to do? How to do it (the alternatives)? Then, it may also be helpful to draw some simple diagrams. Maybe a flowchart of the pieces and how they interact.

While these may seem pointless, they will help you organize your thoughts.

When you have some kind of an idea about what you need to do, do it. Even if the solution is not perfect, or doesn’t do all the things you want it to do, do it.

After you have some working code, you can then look at it and start implementing the things it doesn’t do yet. It’s much easier to add into existing code than just think about the whole thing.

You may have to modify the original code to account for the new features, but so what? You should have unit tests that you can use to be sure your new code doesn’t break the interface! You also should have your code in source control - then you can always go back to the old code if the new one doesn’t work out.

I think this is where it boils down: I try to anticipate what I want the code to do, and make room for all of it at once, which just sometimes doesn’t work out when I can’t come up with a clear picture of it. That’s when you have to just go in and start writing something, and change it in the progress. Don’t forget to have some kind of a goal in mind, though - otherwise you can easily get feature creep.

Share this:
  • Digg
  • del.icio.us
  • Facebook
  • Google
  • description
  • E-mail this story to a friend!
  • LinkedIn
  • Pownce
  • Reddit
  • StumbleUpon
  • Technorati

RSS feed Subscribe to my RSS feed

  1. 3 Responses to “Theory vs. Practice in coding”

  2. You have raised a good point.

    I too have faced similar situation. The approach I have taken to solve this is:
    1. Good to do it the prefect theoretical way. But getting things done is on priority.
    2. Spend some time to research about the implementation details of the design and architecture. But never so much your development gets halted.
    3. Enhancements is the key. Start small if it consumes too much time to write a new feature or follow a design pattern. Go back to where you started often and keep enhancing it.

    By Sudheer on Sep 9, 2008

  3. This post hits really close to home for me…

    I too am developing a CMS and I constantly find myself thinking and re-thinking over a particular method of implementation to the point of absurdity. Perhaps it’s some sort of OCD in me, but I just want to get it perfect on the first pass. I often have to force myself to just pick a direction and stick with it. I can always backtrack and re-implement something if the need arises.

    By Mike G. on Sep 11, 2008

  4. I thought I was the only one! What a relief :)

    By Joe Devon on Jul 4, 2009

Post a Comment