Thread overview
Poll/discussion: dfmt option for single vs double indents for multi-line code
Dec 30
JN
Dec 30
deadalnix
Jan 01
An Pham
December 29

Hi everyone,

As a part of SAOC 2023, I've been working on porting dfmt to use the AST from DMD instead of libdparse (you might have come across my weekly updates). There are a few passes in the original dfmt that seem to allow for a purely aesthetic formatting inconsistency, and I wanted some community opinion on whether these should be made available in dmdfmt, or whether it would be better to retire them.

  • dfmt_single_template_constraint_indent: If set to true, indents multi-line template constraints with a single tab. The default is false. E.g.
    // default
    void foo(T)()
            if (is(T == char) || is(T == dchar))
    // true
    void foo(T)()
        if (is(T == char) || is(T == dchar))
    
  • dfmt_single_indent: If set to true, indents multi-line function declarations with a single tab. The default is false. E.g.
    // default
    void foo(int a, char b, string c, int d,
            char e, string f) {}
    // true
    void foo(int a, char b, string c, int d,
        char e, string f) {}
    

IMO, code on the following line should ideally be indented by a single tab, irrespective of the context of the newline. This ensures formatting consistency across all types of expressions. With these options, it causes the reader to flip between single tab and double tab indents across different items like if/else/for/while and function declarations/template constraints, which is quite jarring.

What do you think about this? Would it be better to maintain a single standard for indentation and not allow configuration, or should a knob be provided at the cost of consistency?

December 29
On 29/12/2023 10:08 PM, Prajwal S N wrote:
> What do you think about this? Would it be better to maintain a single standard for indentation and not allow configuration, or should a knob be provided at the cost of consistency?

Keep it.

Let's not introduce behaviors which differs from the original dfmt.

It only introduces a wedge between old and new, which prevents adoption.
December 30

On Friday, 29 December 2023 at 09:08:33 UTC, Prajwal S N wrote:

>
  • dfmt_single_indent: If set to true, indents multi-line function declarations with a single tab. The default is false. E.g.
    // default
    void foo(int a, char b, string c, int d,
            char e, string f) {}
    // true
    void foo(int a, char b, string c, int d,
        char e, string f) {}
    

If it were my code, I'd format it like this:

void foo(int a, char b, string c, int d,
         char e, string f) {}

PEP8 for Python also recommends such vertical alignment. Alternatively:

void foo(
    int a, char b,
    string c, int d,
    char e, string f) {}
December 30

On Saturday, 30 December 2023 at 14:54:54 UTC, JN wrote:

>

On Friday, 29 December 2023 at 09:08:33 UTC, Prajwal S N wrote:

>
  • dfmt_single_indent: If set to true, indents multi-line function declarations with a single tab. The default is false. E.g.
    // default
    void foo(int a, char b, string c, int d,
            char e, string f) {}
    // true
    void foo(int a, char b, string c, int d,
        char e, string f) {}
    

If it were my code, I'd format it like this:

void foo(int a, char b, string c, int d,
         char e, string f) {}

That is what sdfmt will do.

January 01

On Friday, 29 December 2023 at 09:08:33 UTC, Prajwal S N wrote:

>

Hi everyone,

As a part of SAOC 2023, I've been working on porting dfmt to use the AST from DMD instead of libdparse (you might have come across my weekly updates). There are a few passes in the original dfmt that seem to allow for a purely aesthetic formatting inconsistency, and I wanted some community opinion on whether these should be made available in dmdfmt, or whether it would be better to retire them.

  • dfmt_single_template_constraint_indent: If set to true, indents multi-line template constraints with a single tab. The default is false. E.g.
    // default
    void foo(T)()
            if (is(T == char) || is(T == dchar))
    // true
    void foo(T)()
        if (is(T == char) || is(T == dchar))
    
  • dfmt_single_indent: If set to true, indents multi-line function declarations with a single tab. The default is false. E.g.
    // default
    void foo(int a, char b, string c, int d,
            char e, string f) {}
    // true
    void foo(int a, char b, string c, int d,
        char e, string f) {}
    
>

What do you think about this? Would it be better to maintain a single standard for indentation and not allow configuration, or should a knob be provided at the cost of consistency?

Why not using 'int' instead as type for number of tabs. For template restriction, I do not want any tab

January 03

On Friday, 29 December 2023 at 09:08:33 UTC, Prajwal S N wrote:

>

Hi everyone,

As a part of SAOC 2023, I've been working on porting dfmt to ...

Can you share a link to dmdfmt, please?

January 03
On 03/01/2024 8:01 PM, Per Nordlöw wrote:
> Can you share a link to dmdfmt, please?

https://github.com/dlang-community/dfmt/pull/589
January 10

On Wednesday, 3 January 2024 at 07:03:05 UTC, Richard (Rikki) Andrew Cattermole wrote:

>

On 03/01/2024 8:01 PM, Per Nordlöw wrote:

>

Can you share a link to dmdfmt, please?

https://github.com/dlang-community/dfmt/pull/589

Thanks!