Adding D support to Clang format

max haughton maxhaton at gmail.com
Sat Apr 29 22:06:00 UTC 2023


On Saturday, 29 April 2023 at 21:27:51 UTC, Johan wrote:
> On Saturday, 29 April 2023 at 21:07:28 UTC, max haughton wrote:
>> On Saturday, 29 April 2023 at 19:08:14 UTC, Zachary Yedidia 
>> wrote:
>>> It would also be great to have import sorting.
>>
>> Why is import sorting useful in practice? Anything more than 
>> ~3 top level imports for me is a pretty big red flag for me - 
>> D has local imports, use them.
>
> I think these kind of discussions should be kept to a minimum: 
> a formatter should not force a specific formatting taste on the 
> user, and instead provide options such that the user can tailor 
> it to taste.

In this case I think the question only makes sense if you are 
writing suboptimal code e.g. some files in dmd currently have 
almost 100 lines of `import`s at the top.

> I would also appreciate import sorting (with option to separate 
> stdlib imports from user libraries), including sorting symbols 
> of specific imports.
> Another wish is grouping all UDAs either before/after the 
> function.
> If I think longer, I'm sure I have other wishes that clash with 
> someone else's taste, like you had 
> (https://github.com/snazzy-d/sdc/issues/231) ;-)
> Hence options options options!
I guess, but this felt inconsistent rather than merely not to 
taste. For the most part I genuinely don't care how the code is 
actually formatted as long as it feels space efficient (using 
sdfmt has made me hate Allman braces, other than that not that 
much to report) and isn't going to trip my eyes up.

At a scale larger than 1 person formatting isn't really about 
aesthetics anyway, it's about uniformity (both for tools and 
people). As long as it isn't completely brain-damaged I'm not 
that bothered about the format itself.

At the level of a team of programmers, consider - as we all have 
done, and will do as long as there are programmers, and a bit 
longer after that as long as people remember what digital 
computers are - debates about how exactly code should be 
formatted: In using a relatively inflexible formatter you mostly 
eliminate the politics and distraction of these debates whereas 
in having to decide you run the risk of just moving the 
distraction around. YMMV.

Following on from the above, if someone wants to implement more 
options in sdfmt (other than it being up to Amaury) I don't see 
much of a problem but I just think people miss why (and when) 
formatters are a good idea.


More information about the Digitalmars-d mailing list