www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Poll/discussion: dfmt option for single vs double indents for

reply Prajwal S N <snp dlang.org> writes:
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.
     ```d
     // 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.
     ```d
     // 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?
Dec 29 2023
next sibling parent "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
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.
Dec 29 2023
prev sibling next sibling parent reply JN <666total wp.pl> writes:
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.
     ```d
     // 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: ```d void foo(int a, char b, string c, int d, char e, string f) {} ``` PEP8 for Python also recommends such vertical alignment. Alternatively: ```d void foo( int a, char b, string c, int d, char e, string f) {} ```
Dec 30 2023
parent deadalnix <deadalnix gmail.com> writes:
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.
     ```d
     // 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: ```d void foo(int a, char b, string c, int d, char e, string f) {} ```
That is what sdfmt will do.
Dec 30 2023
prev sibling next sibling parent An Pham <home home.com> writes:
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.
     ```d
     // 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.
     ```d
     // 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
Jan 01
prev sibling parent reply Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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?
Jan 02
parent reply "Richard (Rikki) Andrew Cattermole" <richard cattermole.co.nz> writes:
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
Jan 02
parent Per =?UTF-8?B?Tm9yZGzDtnc=?= <per.nordlow gmail.com> writes:
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!
Jan 09