Whitespace is a code smell

Do you space out your code so there are line breaks between the pieces of logic? Whydo you think this isnecessary? Typically this is done to separate chunks of logic so that they can be easily distinguished. If it is a complicated enough chunk, then it may even make sense to put a comment at the top of the chunk. At this point, the Agile police will jump on you and tell you to turn your comment intoa method name and perform an Extract Method refactoring. This is great practice (fellow Agile police member here!) and it makes a lot of sense since it abstracts the concept and makes the code more self describing.

But let's thinkback to those line breaks again … if it needed the line breaks, then there is code smell. If your code needs whitespace in the method to make it cleaner to read then it is probably doing too much. Of course, this is very subjective and easy to argue (heck – our team can't fully agree on this either!) but think carefully the next time you find yourself adding extra whitespace to your code and think:

  • Is this code as simple as it should be?
  • Does this logic all belong here or could it be broken out into other methods/classes?

Jonathan Cogley is the CEO and founder of Thycotic Software, a .NET consulting company and ISV in Washington DC. Our product, Secret Server is an enterprise password management system for teams to secure their passwords. Where do you keep your passwords or do you use the samepassword everywhere?

  1. jayson knight
    March 23, 2007 at 4:16 pm

    I disagree with this assertion. I personally put a linebreak between logical sections of code for aesthetic reasons only, as well as a comment or 2. Anything that makes code easier to read can’t just assumingly be called a code smell, and that’s a good way to start a holy war amongst developers :-).

    Readability is paramount.

  2. John Walker
    March 23, 2007 at 4:17 pm

    Ahh…another coding holy war about to break out πŸ™‚

    Seriously, I don’t really buy into the fact that spacing out your code means something is potentially wrong with it or it could be simpler. I think it’s more of a style issue.

    My coding partner tends to space things out quite a bit, but I tend to shrink my code down with minimal line-breaks. At the end of the day, I don’t think it really matters, but maybe that’s just me. Interesting post for sure.

  3. Jonathan Cogley
    March 23, 2007 at 7:13 pm

    You have to love a holy war about whitespace! πŸ™‚

    The key point in my post is just to think about why you want whitespace in your code when you are adding it. Is the method too long, too complicated or doing too much? Maybe not and everything is fine.

    Several members on our team disagree with me on this point too but I think it is interesting to strive for no whitespace and still have readable code that is very specific in function.

    Thanks for posting guys! πŸ™‚

  4. Luke Breuer
    March 29, 2007 at 6:33 pm

    Isn’t this discussion useless without actual code examples?

  5. http://
    April 3, 2007 at 5:48 am

    I hacked my fonts so that the spacing between characters, words, and lines is zero pixels and my largest character is only 3 pixels wide and 5 pixels high. I also don’t use Enter.

  6. http://
    May 29, 2007 at 2:26 pm

    Do you use blank rows between your one line methods, or do you just use extract class when this happens? πŸ™‚

  7. Nickolas
    August 18, 2007 at 12:32 am

    Interesting…

  8. Konstantinos
    August 25, 2007 at 12:23 am

    Nice…

  9. Apostolis
    August 28, 2007 at 3:38 pm

    Cool.

  10. Stratis
    August 31, 2007 at 10:57 am

    Sorry 😦

  11. Marinos
    September 3, 2007 at 11:50 pm

    Nice!

  1. No trackbacks yet.

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: