Page 1 of 1

Empty lines inside long code blocks

Posted: Fri Jul 20, 2018 1:40 pm UTC
by Mark_Cangila
I have a block of code 38 lines long, including comments. It does setup on files. Currently it is nearly unreadable, due to it being one block. Should I add a line of whitespace at places to separate them? For example sections that do different tasks.

Re: Empty lines inside long code blocks

Posted: Fri Jul 20, 2018 2:09 pm UTC
by Soupspoon
I tend to use 'paragraph breaks' between semi-monolithic code segments.

Code: Select all

sub SomethingPseudocodey(input1,input2) {
  // Sanity needed on all inputs!
  input1=Sanitise(input1);
  input2=Sanitise(input2);
 
  // Variius related combinatorials in this section
  combo=combine(input1,input2);
  differential=difference(input1,input2);
  allbut=difference(*everything,combo);
 
  // Sometimes you can reduce lines (if the language allows it and the statements stack sideways
  //  nicely without forming *too* long a line in the process)
  blahbah foo;  blahbah bar;
  meditate foo; meditate bar;
  // just because sometimes a 2D block visually debugs (and takes 'global' edits) better
 
  // Always handy to see this separate, if applicable
  return sirNotAppearingInThisFilm;
}


If you feel guilty about adding extra blank lines that do nothing, add extra blank lines that do something! ;)

Re: Empty lines inside long code blocks

Posted: Fri Jul 20, 2018 5:49 pm UTC
by Xanthir
Agreed, blank lines separating out sections is great.

Alternately and often better: separate into pieces, then factor those pieces out into separate functions.