# Max source line length

**URL:** https://discourse.julialang.org/t/max-source-line-length/4883
**Category:** General Usage
**Tags:** question
**Created:** [July 16, 2017, 2:49pm UTC](https://discourse.julialang.org/t/max-source-line-length/4883 "2017-07-16T14:49:01Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 16, 2017, 2:49pm UTC](https://discourse.julialang.org/t/max-source-line-length/4883/1 "2017-07-16T14:49:01Z")

</div>

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](https://docs.julialang.org/en/latest/manual/documentation/#Documentation-1) recommends 92, but that’s for docstrings.

[JuliaPraxis/Spacing](https://github.com/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](https://github.com/johnmyleswhite/Style.jl).

[CONTRIBUTING.md](https://github.com/JuliaLang/julia/blob/master/CONTRIBUTING.md#general-formatting-guidelines-for-julia-code-contributions) recommends 92.

Running the following snippet

```julia
## 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

```julia
 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

```

---

<div class="post-metadata">

### Author: ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)
#### Post date: [July 16, 2017, 3:07pm UTC](https://discourse.julialang.org/t/max-source-line-length/4883/2 "2017-07-16T15:07:24Z")

</div>

Since CONTRIBUTION says 92 I would go with that. However, until there is a well made julia source code formatter, things like line length will always be a best effort endeavor.

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 17, 2017, 8:32am UTC](https://discourse.julialang.org/t/max-source-line-length/4883/3 "2017-07-17T08:32:53Z")

</div>

Some further stats on line length distributions (just for fun, `(lower,upper)=>percentage`)):

```julia
# Base
 (0, 19)=>40.6  
 (20, 39)=>24.9 
 (40, 59)=>15.0 
 (60, 79)=>11.4 
 (80, 99)=>5.9  
 (100, 119)=>1.4
# packages on my system
 (0, 19)=>38.2  
 (20, 39)=>28.7 
 (40, 59)=>16.1 
 (60, 79)=>10.1 
 (80, 99)=>4.6  
 (100, 119)=>1.2
# base > 80
 (80, 89)=>46.2  
 (90, 99)=>25.8  
 (100, 109)=>11.4
 (110, 119)=>6.4 
 (120, 129)=>3.6 
 (130, 139)=>2.4 
 (140, 149)=>1.5 
# packages > 80
 (80, 89)=>47.4  
 (90, 99)=>18.1  
 (100, 109)=>10.9
 (110, 119)=>6.6 
 (120, 129)=>4.3 
 (130, 139)=>2.5 
 (140, 149)=>2.2 
 (150, 159)=>1.5 
 (160, 169)=>1.3 

```

Only frequencies above 1% are shown, so the above don’t sum to 100%. As expected, packages have more outliers.

I think that trying to break up lines above 80 chars, at most 92, is a reasonable style guide. Readability will be heavily affected by 160 character monster expressions.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [July 17, 2017, 8:53am UTC](https://discourse.julialang.org/t/max-source-line-length/4883/4 "2017-07-17T08:53:35Z")

</div>

btw: a side question: is there something in (any)/a style gide how to split/format expressions that are one line, but needs to be within the 92 limit? (btw2: as old-school terminal user (80x72) i’d actually see 80 as the defining limit).

---

<div class="post-metadata">

### Author: ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)
#### Post date: [July 17, 2017, 10:45am UTC](https://discourse.julialang.org/t/max-source-line-length/4883/5 "2017-07-17T10:45:33Z")

</div>

See [JuliaPraxis/Spacing/Splitting lines](https://github.com/JuliaPraxis/Spacing/blob/master/guides/VerticalSpacing.md#splitting-lines), which I linked above.

---

<div class="post-metadata">

### Author: ![lobingera](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lobingera/32/211_2.png) [@lobingera](https://discourse.julialang.org/u/lobingera)
#### Post date: [July 17, 2017, 10:53am UTC](https://discourse.julialang.org/t/max-source-line-length/4883/6 "2017-07-17T10:53:54Z")

</div>

yes, i wasn’t clear enough: Is there something else than at this link? It’s stating the obvious but leaves away how deep to indent.
