Is there a recommended max line length for source code in Julia? I know it is up to personal preference to a large extent, but I am wondering if there is a reasonable default.
The page on documentation recommends 92, but that’s for docstrings.
JuliaPraxis/Spacing does not give a specific number, just recommends
Prefer to split a long line after =, , ||, &&. or (.
This page by John Myles White recommends 80.
CONTRIBUTING.md recommends 92.
Running the following snippet
## count line lengths
dir = "$JULIA_HOME/$(Base.DATAROOTDIR)/julia/base"
dict = Dict{Int,Int}()
for (root, _, files) = walkdir(dir)
for file in files
filename = joinpath(root, file)
_, ext = splitext(filename)
if ext == ".jl"
for line in readlines(filename)
len = length(line)
dict[len] = get(dict, len, 0) + 1
end
end
end
end
sort(collect(filter((l, _) -> 80 ≤ l ≤ 120, dict)), by = first)
suggests that 92 is not that strictly adhered to: after 92, the frequency drops to about 2/3, something like
88=>473
89=>541
90=>494
91=>450
92=>416
93=>274
94=>241
95=>240
96=>231
97=>185
98=>186
99=>148
100=>188