Stream: ideas

Topic: More compact record builder formatting


view this post on Zulip Sam Mohr (Jun 15 2024 at 00:19):

It feels like the record builder syntax is overly willing to add line breaks when creating complex records. I would like to format the following more compactly:

builtData =
    Builder.start {
        childData: <-
            Builder.child \child ->
                Builder.start {
                    abc: <- Builder.data child.abc,
                    xyz: <- Builder.data child.xyz,
                }
                |> Builder.finish,
    }
    |> Builder.finish

Ideally, this would be allowed by the formatter:

builtData =
    Builder.start {
        childData: <- Builder.child \child ->
            Builder.start {
                abc: <- Builder.data child.abc,
                xyz: <- Builder.data child.xyz,
            }
            |> Builder.finish,
    }
    |> Builder.finish

However, the formatter currently forces the first option. I think there's not a loss of readability, and it also doesn't cost as much in horizontal space. Does anyone disagree? If not, I can make a GitHub issue.

view this post on Zulip Brendan Hansknecht (Jun 15 2024 at 03:03):

<- and -> on the same line is a bit strange...but overall, I agree. More compact is better.

view this post on Zulip Anton (Jun 15 2024 at 09:57):

I do significantly prefer the current style, for me it's effortless to see what goes in childData in the first code snippet and it's not for the second one. People disliking arrows in different directions on the same line has come up several times.

view this post on Zulip Sam Mohr (Jun 15 2024 at 09:59):

The arrows in different directions argument makes sense to me. I think it's consistent and readable, the main thing I'm feeling is a worry that consumers of these builder API's will be less wont to use them since they're more and more verbose

view this post on Zulip Anton (Jun 15 2024 at 10:08):

To solve the verbosity; In snippets where Builder occurs many times, it may be best to go with an alias like Bdr or even B. I think Builder is also highlighted with our syntax highlighting and not just on zulip? From a UX perspective, Builder also stands out a lot on every line, but it is far from the most important word in the line of code.

view this post on Zulip Sam Mohr (Jun 15 2024 at 10:16):

Yeah, I made it longer to make my pseudo-example

view this post on Zulip Sam Mohr (Jun 15 2024 at 10:20):

So long as we don't plan on having a line length limit, I don't think the current issue will lead to formatting issues with really nested builders

view this post on Zulip Sam Mohr (Jun 15 2024 at 10:20):

So it's probably fine

view this post on Zulip Richard Feldman (Jun 16 2024 at 14:30):

Sam Mohr said:

So long as we don't plan on having a line length limit

we already do have a line length limit :sweat_smile:

view this post on Zulip Richard Feldman (Jun 16 2024 at 14:30):

in the future it'll probably be ~65K bytes

view this post on Zulip Richard Feldman (Jun 16 2024 at 14:30):

(per line)


Last updated: Jun 16 2026 at 16:19 UTC