Link Details

Link 69767 thumbnail
User 236575 avatar

By activa
via blog.activa.be
Published: Mar 10 2008 / 12:14

Using empty lines in source code may seem like a waste of precious screen space, but it's crucial to writing readable code.
  • 15
  • 9
  • 1693
  • 400

Comments

Add your comment
User 160542 avatar

Kirill Grouchnikov replied ago:

2 votes Vote down Vote up Reply

Lost me at the "correct placement of braces".

User 236575 avatar

activa replied ago:

0 votes Vote down Vote up Reply

That's just a matter of personal taste (although I also have an opinion about that :) But this is not exactly what this post is about.

User 209464 avatar

willcode4beer replied ago:

0 votes Vote down Vote up Reply

Everybody has an opion about that, thus Kirill's comment.

OTOH, if the writer actually made consistent use of curly braces, he wouldn't have to insert so many blank lines

User 201118 avatar

Lars Pohlmann replied ago:

1 votes Vote down Vote up Reply

When I have to go over code of my co-workers I often find myself inserting lots of empty lines (at the right places) to get a better overview.

User 233461 avatar

antych replied ago:

4 votes Vote down Vote up Reply

Blank lines should only be used to group code, not format it. I hate when people put them in almost every second line, allegedly to increase readability. It has the opposite effect, you need to scan more lines, or worse scroll more than one screen. You write readable code by keeping it clean, elegant and small. If you need to resort to many blank lines, you already failed.

User 236575 avatar

activa replied ago:

1 votes Vote down Vote up Reply

I agree, but what is regarded as a "group" of code? Some people think a method is a single group of code :-)

User 218789 avatar

eelmore replied ago:

2 votes Vote down Vote up Reply

If your code isn't readable without inserting empty lines (or worse, lines with only an opening brace { ), then it's probably not an issue of formatting--perhaps it's a sign that you need to refactor such a lengthy segment? It's quite distracting when there's so much useless whitespace that I need to scroll unnecessarily. It's also very distracting (and dare I say, UGLY) to have an opening brace on a line by itself--I don't know any gifted or disciplined developers that still use that style. On the other hand, I agree that some horizontal white space is a very good thing.

Add your comment


Html tags not supported. Reply is editable for 5 minutes. Use [code lang="java|ruby|sql|css|xml"][/code] to post code snippets.