Stream: ideas

Topic: Roc fmt should add double space before comment


view this post on Zulip Aurélien Geron (Sep 03 2026 at 09:38):

The formatter only leaves one space before a comment. I find this visually hard to parse, for example:

mass = Tons(50) # this is the mass of the thing
mass_in_kilograms =
    match mass {
        Kilos(kilos) => kilos # just plain kilos
        Tons(tons) => tons * 1000 # oh wow we have tons now
        Kilotons(kilotons) => kilotons * 1_000_000 # and kilotons, that's nuts
    }

Contrast that with double-space:

mass = Tons(50)  # this is the mass of the thing
mass_in_kilograms =
    match mass {
        Kilos(kilos) => kilos  # just plain kilos
        Tons(tons) => tons * 1000  # oh wow we have tons now
        Kilotons(kilotons) => kilotons * 1_000_000  # and kilotons, that's nuts
    }

view this post on Zulip Aurélien Geron (Sep 03 2026 at 10:24):

For what it's worth, several other languages use double spaces before comments after code:

view this post on Zulip Aurélien Geron (Sep 09 2026 at 23:21):

Just submitted PR #11262 to have two spaces (instead of one) before inline comments.

view this post on Zulip Richard Feldman (Sep 10 2026 at 00:07):

I dunno about this one...I don't think any other formatters do that, do they?

view this post on Zulip Richard Feldman (Sep 10 2026 at 00:08):

I understand the argument, but I can very easily anticipate complaints in the other direction :smile:

view this post on Zulip Aurélien Geron (Sep 10 2026 at 00:26):

Yes, a bunch of formatters do that:

Edit: looks like the default is 1 except for Python and Meson. It's interesting that style guides recommend 2 spaces but the formatters don't do it by default.

view this post on Zulip Aurélien Geron (Sep 10 2026 at 00:28):

And a bunch of style guides recommend it (see the list I posted above)

view this post on Zulip Aurélien Geron (Sep 10 2026 at 00:32):

I guess we could make it configurable, but my understanding is that roc fmt is opinionated, so we have to choose. I find it much cleaner, visually, but it might just be a matter of taste. Perhaps we could have a little vote just to see if most people agree that double-space is easier to read?

view this post on Zulip Aurélien Geron (Sep 10 2026 at 00:34):

Here's Python's style guide on (at least) two spaces for inline comments:

image.png

Interestingly, they also recommend using inline comments sparingly.

view this post on Zulip Aurélien Geron (Sep 10 2026 at 00:47):

/poll How many spaces do you prefer before inline comments?
One space exactly
Two spaces exactly
At least one space
At least two spaces
Other (comment)

view this post on Zulip Luke Boswell (Sep 10 2026 at 00:56):

Wouldn't a tab \t be more correct here?

view this post on Zulip Luke Boswell (Sep 10 2026 at 03:11):

One idea to help with this that Joshua was doing back with the development of the formatter ...

Download heaps of Roc files from known up to date projects using a python script.

Implement the new formatter rule, run it over all the docs and assess the impact.

I think he name his script (it grew a lot of capabilites and did lot of things) Roc Osprey or something... after a seagoing bird that can cover great distances :grinning_face_with_smiling_eyes:


Last updated: Sep 24 2026 at 15:59 UTC