Space in empty lines

When I have an empty line in an indented block, should I

  1. remove spaces,
  2. have as many spaces as the indentation commands,
  3. not care?

(This came up while cooperating with someone, I do (1). It leads to a bunch of gratuitious changes in git unless normalization is applied before commits).

Examples:

function f1(a)
    b = a + 1

    # ^ line above has no spaces
    b
end
function f2(a)
    b = a + 1
    
    # ^ line above has 4 spaces
    b
end

Runic.jl apparently does (1), but I don’t see it documented.

I think the idea is that you want to avoid those spaces to 1. reduce code diffs 2. shrink the size of the files. All formatters I used remove those.

I do this automatically (VSCode does this for me automatically).

I thought Runic.jl did this as well during formatting, but it looks like it doesn’t by looking at the readme again (cc @fredrikekre if you wish to comment)

I also do 1 in Emacs, with (add-hook 'before-save-hook 'delete-trailing-whitespace nil t).

Good to know that it is the approach that makes sense to most people, I thought it was my quirk.

I also have that automatically in VS Code.

Every now and then I have a co-author, maybe in Julia code, maybe in TeX, not doing that. If it is just a few lines, I do commit that.
If that other person does not do that on purpose, this solves it. Before an “edit/commit war” starts, carefully look for a discussion. The one time I opened that discussion, the other person was simply not aware of the spaces – as like for your case in empty lines.

A lot of big projects demand there be no trailing whitespaces. The Julia repo itself does this through a quick CI check — by ensuring no trailing whitespace ever lands on master, it completely avoids the problem of the gratuitous git changes.

It can add one extra speed bump to contribution, but it’s an easy fix: encourage your collaborators to turn on their editor’s setting for this.

You can also automatically check this both locally and in CI with pre-commit. For example, BestieTemplate.jl will also set this up for you: BestieTemplate.jl/.pre-commit-config.yaml at main · JuliaBesties/BestieTemplate.jl · GitHub