Empty lines inside long code blocks

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Mark_Cangila
Posts: 32
Joined: Fri Mar 16, 2018 4:34 pm UTC

Empty lines inside long code blocks

Postby Mark_Cangila » Fri Jul 20, 2018 1:40 pm UTC

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.

User avatar
Soupspoon
You have done something you shouldn't. Or are about to.
Posts: 3577
Joined: Thu Jan 28, 2016 7:00 pm UTC
Location: 53-1

Re: Empty lines inside long code blocks

Postby Soupspoon » Fri Jul 20, 2018 2:09 pm UTC

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! ;)

User avatar
Xanthir
My HERO!!!
Posts: 5321
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Empty lines inside long code blocks

Postby Xanthir » Fri Jul 20, 2018 5:49 pm UTC

Agreed, blank lines separating out sections is great.

Alternately and often better: separate into pieces, then factor those pieces out into separate functions.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 9 guests