[racket-dev] style guide on blank lines

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Tue Mar 13 14:41:40 EDT 2012


released 


On Mar 13, 2012, at 2:10 PM, Matthias Felleisen wrote:

> 
> 
> Okay. I am adding 
> 
> Don't pollute your code with spaces at the end of lines. 
> 
> If you find yourself breaking long blocks of code with blank lines to aid
> readability, consider refactoring your program to introduce auxiliary
> functions so that you can shorten these long blocks of code. If nothing
> else helps, consider using (potentially) empty comment lines. 
> 
> 
> ;; --- 
> 
> As soon as I have my racket back, I'll type set and release. 
> 
> Thanks -- Matthias
> 
> 
> 
> 
> On Mar 13, 2012, at 1:54 PM, John Clements wrote:
> 
>> 
>> On Mar 13, 2012, at 8:37 AM, Matthias Felleisen wrote:
>> 
>>> 
>>> 1. I think the 'unnecessary' gives you some wiggle room here. 
>>> 
>>> 2. I occasionally leave a 'necessary' blank line in code but prefix it with ";;" to signal that I left it blank intentionally. 
>>> 
>>> 3. I would write the code below, and I would consider it fine w/o blank lines, though yes, I'd add purpose statements to the auxiliaries. 
>> 
>> Can I therefore suggest the following update to the style guide? :
>> 
>> 
>> 5.8 Spaces
>> 
>> Don't pollute your code with spaces at the end of lines.
>> 
>> If you find that your code requires blank lines in order to aid readability, consider refactoring your program to introduce auxiliary functions and shorten long blocks of code.
>> 
>> 
>>>> "5.8 Spaces
>>>> 
>>>> Don’t pollute your code with spaces at the end of lines and extraneous blank lines."
>>> 
>>> 
>>> ;; flag-teachpack-requires : syntax nat -> syntax
>>> ;; apply the 'stepper-skip-completely hint to all
>>> ;; teachpack requires.
>>> ;; -- it would be great to do this directly when the 
>>> ;; requires are added, but they're not yet syntax there,
>>> ;; and this seems like the easiest way to fix it.
>>> (define (flag-teachpack-requires stx num-teachpacks)
>>> (syntax-case stx ()
>>>  [(mod name lang bodies-stx ...)
>>>   (begin
>>>     (define bodies (syntax->list #'(bodies-stx ...)))
>>>     (*check-teachpacks bodies num-teachpacks)
>>>     (define-values (teachpack-requires remaining-bodies) (split-at bodies num-requires))
>>>     (*check-requires require-form? teachpack-requires)
>>>     ;; -- IN -- 
>>>     #'(mod name lang
>>>            #,@(flagged-requires stx teachpack-requires)
>>>            #, at remaining-bodies))]))
>>> 
>>> (define (*check-teachpacks bodies num-teachpacks)
>>> (when (< (length bodies) num-teachpacks)
>>>  (error 'flag-teachpack-requires
>>>         "internal error: expected bodies to include teachpack requires, got: ~e"
>>>         bodies)))
>>> 
>>> (define (*check-requires require-form? teachpack-requires)
>>> (unless (andmap require-form? teachpack-requires)
>>>  (error 'flag-teachpack-requires
>>>         "internal error: expected these to be teachpack requires: ~e"
>>>         teachpack-requires)))
>>> 
>>> (define (flagged-requires stx teachpack-requires)
>>> (for/list ([tp-rq (in-list teachpack-requires)])
>>>  (stepper-syntax-property stx 'stepper-ignore-completely #t)))
>>> 
>>> 
>>> 
>>> 
>>> On Mar 13, 2012, at 2:16 AM, John Clements wrote:
>>> 
>>>> The style guide has this to say about blank lines:
>>>> 
>>>> "5.8 Spaces
>>>> 
>>>> Don’t pollute your code with spaces at the end of lines and extraneous blank lines."
>>>> 
>>>> This comes out pretty strongly against "extraneous" blank lines. In writing the code below, though, it seems to me that the blank lines aid readability, and that the version without them (below) just looks scary. Opinions?
>>>> 
>>>> (To be fair, you really have to view the following in DrR, not in your e-mail program.)
>>>> 
>>>> First, with extraneous blank lines:
>>>> 
>>>> ;; flag-teachpack-requires : syntax nat -> syntax
>>>> ;; apply the 'stepper-skip-completely hint to all
>>>> ;; teachpack requires.
>>>> ;; -- it would be great to do this directly when the 
>>>> ;; requires are added, but they're not yet syntax there,
>>>> ;; and this seems like the easiest way to fix it.
>>>> (define (flag-teachpack-requires stx num-teachpacks)
>>>> (syntax-case stx ()
>>>> [(mod name lang bodies-stx ...)
>>>>  (begin
>>>> 
>>>>    (define bodies (syntax->list #'(bodies-stx ...)))
>>>> 
>>>>    (when (< (length bodies) num-teachpacks)
>>>>      (error 'flag-teachpack-requires
>>>>             "internal error: expected bodies to include teachpack requires, got: ~e"
>>>>             bodies))
>>>> 
>>>>    ;; these should be the teachpack requires:
>>>>    (define-values (teachpack-requires remaining-bodies)
>>>>      (split-at bodies num-requires))
>>>> 
>>>>    (unless (andmap require-form? teachpack-requires)
>>>>      (error 'flag-teachpack-requires
>>>>             "internal error: expected these to be teachpack requires: ~e"
>>>>             teachpack-requires))
>>>> 
>>>>    (define flagged-teachpack-requires
>>>>      (for/list ([tp-rq (in-list teachpack-requires)])
>>>>        (stepper-syntax-property stx 'stepper-ignore-completely #t)))
>>>> 
>>>>    #'(mod name lang
>>>>           #, at flagged-teachpack-requires
>>>>           #, at remaining-bodies))]))
>>>> 
>>>> 
>>>> Then, without them:
>>>> 
>>>> ;; flag-teachpack-requires : syntax nat -> syntax
>>>> ;; apply the 'stepper-skip-completely hint to all
>>>> ;; teachpack requires.
>>>> ;; -- it would be great to do this directly when the 
>>>> ;; requires are added, but they're not yet syntax there,
>>>> ;; and this seems like the easiest way to fix it.
>>>> (define (flag-teachpack-requires stx num-teachpacks)
>>>> (syntax-case stx ()
>>>> [(mod name lang bodies-stx ...)
>>>>  (begin       
>>>>    (define bodies (syntax->list #'(bodies-stx ...)))
>>>>    (when (< (length bodies) num-teachpacks)
>>>>      (error 'flag-teachpack-requires
>>>>             "internal error: expected bodies to include teachpack requires, got: ~e"
>>>>             bodies))
>>>>    ;; these should be the teachpack requires:
>>>>    (define-values (teachpack-requires remaining-bodies)
>>>>      (split-at bodies num-requires))
>>>>    (unless (andmap require-form? teachpack-requires)
>>>>      (error 'flag-teachpack-requires
>>>>             "internal error: expected these to be teachpack requires: ~e"
>>>>             teachpack-requires))
>>>>    (define flagged-teachpack-requires
>>>>      (for/list ([tp-rq (in-list teachpack-requires)])
>>>>        (stepper-syntax-property stx 'stepper-ignore-completely #t)))
>>>>    #'(mod name lang
>>>>           #, at flagged-teachpack-requires
>>>>           #, at remaining-bodies))]))_________________________
>>>> Racket Developers list:
>>>> http://lists.racket-lang.org/dev
>>> 
>> 
> 
> 
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev



Posted on the dev mailing list.