CodingPleasure

cultivate passion for everything else that goes on around programming

Do It Anyway

I recently heard an interesting quote from Ghandi:

Whatever you do will be insignificant, but it is very important that you do it.

Of course on a micro-scale, your actions might seem important and may have an influence on the near future. But on a macro-scale, your actions and everything you do as an individual, will not change a lot in the universe and will be just lost in time.

But then why should it be important to do something? Why should we even begin doing something, if we know for sure it will not be something that will change the world?

I will try to explain why by describing how this applies to software development. An average programmer doesn’t write that much code. Most of his time he is debugging, testing or reading. Writing new code might take about 10% of his time. Altering existing code might take even more than 10% of his time.

When a developer changes existing code, he has a goal: make the code do what it’s supposed to do. But this could be done in a quick & dirty way: just fix the code with a minimum amount of effort (because it will be just an insignificant change after all, isn’t it?).  Even if a quick fix does the job and the developer might even get appreciation from his not-so-clever-looking-into-code manager, this simply isn’t enough.

You, as a professional developer, should do the following additional tasks when fixing a bug or every time you look over existing code:

  • refactor: change code in such a way that it is easier to maintain and more understandable. Rewrite the code in a better, cleaner way, keeping the functionality intact. Refactor to patterns. Break dependencies. Every time you identify some part of the code which might be refactored and you think “it’s not worth the trouble” or “I don’t have time for this”, you should Refactor It Anyway.
  • rewrite: if you see some piece of code that may be written in a better, faster or shorter way, rewrite it. Even if it just saves you a line of code or spares you a local variable, you should Rewrite It Anyway.
  • rename: properly rename methods, variables, properties, classes, interfaces. Rename everything that doesn’t reveal its purpose at the very first moment you read it. If you see a variable named counter and you think “oh, I understand now what it counts” after reading some lines of code, you should rename it. Even if a variable is needed in just a line of code, you should Rename It Anyway.
  • comment: write comments whenever you write code that isn’t trivial. Always ask yourself: if someone else reads this code, will it be understandable? Comment methods, but also classes and interfaces. A method like GetSerialNumber() might not need a comment, but a SerialNumberDecryptor class might need one. Even if it takes you just a second to understand a piece of code, you should Comment It Anyway.
  • cleanup:be vigilant! Don’t leave ugly looking code behind you. Remove unused code, remove unused namespaces or unused variables, remove test files. Properly indent code. Make sure you respect coding conventions. Don’t live with broken windows. Even if you notice some misplaced spaces in some code, Cleanup It Anyway.

Everyone of this actions are insignificant compared to the whole project. But it’s important that you Do Them Anyway!

Advertisements

4 responses to “Do It Anyway

  1. obp March 16, 2011 at 01:24

    really nice post !

    One addon: you have just defined the mighty: the boy scout rule 🙂

    For more stuff : clean code

    • mcanti March 16, 2011 at 19:02

      Not everyone knows what rules boy scouts have 🙂
      Although I have read that post form unclebob before.

      Personally I think the rule from Pragmatic Programmer “Don’t live with broken windows” is easier to understand than the “boy scout rule”, because its based on a real theory and the side-effects of not applying the rule are more obvious:
      Consider a building with a few broken windows. If the windows are not repaired, the tendency is for vandals to break a few more windows.

  2. Michael March 16, 2011 at 11:25

    Hi Cantemir,
    nice post.
    Greetings from Freiburg, Michael.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: