PBP: 013 Chunking

The suggestion in this one was very simple, “Code in paragraphs.”  Deceptively simple, because it means different things to different people.

I agree with this sentiment.  Yet More Whitespace – I approve!  The problem becomes when you have to define what a paragraph is.

I very often am told, “You should code in paragraphs!” and have someone suggest I’ve split things down too far, and should glue these obviously related statements together into a visual block.  Of course, the next code reviewer told me it was an unreadable wall of text, and needed some blank lines…

You can’t win this one, because everyone will define them a little differently.  However, I think it’s a good goal to reach for, and helps make programs easier to read.

As I suggested that you might have a design problem if your functions need to be indented too deeply, I will also suggest there might be a design issue if your functions don’t ever have paragraphs.  A function that doesn’t do enough to require more than one statement might not need to be a function.  Especially if it’s the only method on an object.  (Haven’t seen that as much in Perl, but got it a lot in C++.)

When possible, I think a function should handle an entire task.  Sometimes that task is complex and needs to be broken down into smaller parts.  When functions are too small, I have a very hard time reading the program because I am not able to keep all the calls in my head long enough to remember where I am looking right now.

Leave a Reply