Jump to page: 1 29  
Page
Thread overview
Integrated code formatter
Jan 17
forkit
Jan 17
forkit
Jan 17
forkit
Jan 17
forkit
Jan 18
forkit
Jan 18
forkit
Jan 18
forkit
Jan 18
forkit
Jan 18
forkit
Jan 19
M.M.
Jan 18
jmh530
Jan 19
jmh530
Jan 19
forkit
Jan 19
forkit
Jan 19
forkit
Jan 19
forkit
Jan 20
Ben Jones
Jan 19
forkit
Jan 18
bachmeier
Jan 18
forkit
Jan 19
forkit
Jan 19
matheus
Jan 19
matheus
Jan 19
matheus
Jan 19
forkit
Jan 19
matheus
Jan 17
Johan
Jan 18
deadalnix
Jan 18
deadalnix
Jan 18
user1234
Jan 18
deadalnix
Jan 18
user1234
Jan 18
user1234
Jan 18
deadalnix
Jan 18
Rumbu
Jan 17
forkit
Jan 18
deadalnix
Jan 19
Johan
January 17
So I use clang-format extensively...like all the time.

It makes such a difference, I can't imagine programming without it anymore.

But D doesn't have something integrated like this.

I am aware of dfmt.. but even on it's github page it says "dfmt is beta quality."

I wonder if it isn't time a code formatter for D became a more integrated product, into the release itself, so that people like me can actually rely on it to work as expected, and also, so that the formatter's needs were considered whenever making changes to D.

Or is D code now so variable and complex, that no formatter can reliably format it?

January 17
On Mon, Jan 17, 2022 at 09:46:08PM +0000, forkit via Digitalmars-d wrote:
> So I use clang-format extensively...like all the time.
> 
> It makes such a difference, I can't imagine programming without it anymore.
> 
> But D doesn't have something integrated like this.
> 
> I am aware of dfmt.. but even on it's github page it says "dfmt is beta quality."

So?  You can still use it.


> I wonder if it isn't time a code formatter for D became a more integrated product, into the release itself, so that people like me can actually rely on it to work as expected, and also, so that the formatter's needs were considered whenever making changes to D.
> 
> Or is D code now so variable and complex, that no formatter can reliably format it?

Code formatting is an art, not a science. There are many cases where I would NOT want an automatic formatter to mess with my code because it would make it less readable.

For example, here's a snippet of an actual unittest in one of my projects:

    auto expected = [
        [  1,  1,  Sqrt2, 1 ],
        [  1, -1,  Sqrt2, 1 ],
        [ -1,  1,  Sqrt2, 1 ],
        [ -1, -1,  Sqrt2, 1 ],

        [          1,  (1+Sqrt2),  0, 1 ],
        [          1, -(1+Sqrt2),  0, 1 ],
        [         -1,  (1+Sqrt2),  0, 1 ],
        [         -1, -(1+Sqrt2),  0, 1 ],
        [  (1+Sqrt2),          1,  0, 1 ],
        [  (1+Sqrt2),         -1,  0, 1 ],
        [ -(1+Sqrt2),          1,  0, 1 ],
        [ -(1+Sqrt2),         -1,  0, 1 ],
    ];

I would NOT want an auto code formatter to go, "hey, you have all those ugly redundant spaces, let's compress them to a single space!", or "hey, you can fit more array elements per line in your outer array, let's save some space!" -- because that would destroy the visual symmetry that actually makes this code readable.  If this were formatted the more usual way, it would become much less readable because its large-scale structure would be obscured.

But in other instances, I *would* want my arrays to be formatted more compactly.  No automatic formatter can reliably guess when to format it one way vs. another in such cases, and I'd prefer to just do it myself (and not have the computer screw things up afterwards).

(Yes I know some code formatters have tags to suppress automatic formatting, etc., but seriously, why do I need to explicitly ask the computer not to do something I didn't want it to do in the first place?)

//

That said, if an automatic formatter works for you, why not give dfmt a spin?  Don't be intimidated by the "beta" label (what does that even mean anyway); try it out and see if it's really as bad as you imagine it to be.  You might be pleasantly surprised.


T

-- 
If I were two-faced, would I be wearing this one? -- Abraham Lincoln
January 17
On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
>
> That said, if an automatic formatter works for you, why not give dfmt a spin?  Don't be intimidated by the "beta" label (what does that even mean anyway); try it out and see if it's really as bad as you imagine it to be.  You might be pleasantly surprised.
>
>
> T

I think it's because I'm experiencing 'the let-down' effect...

the most recent one being: -profile=gc  (which isn't even 'beta').


January 17
On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
>
> (Yes I know some code formatters have tags to suppress automatic formatting, etc., but seriously, why do I need to explicitly ask the computer not to do something I didn't want it to do in the first place?)

The way I use clang-format (default with the sublime plugin by llvm) is that it only reformats your selection or current line, and sometimes one extra line of context around it.
clang-format is indeed something I very much miss for D. Precisely this "only reformat this small fragment" functionality is extremely time saving.
Also in code review, you can simply comment "clang-format" and all is clear. No more discussions about formatting :)

-Johan


January 17
On Mon, Jan 17, 2022 at 10:27:54PM +0000, forkit via Digitalmars-d wrote:
> On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
> > 
> > That said, if an automatic formatter works for you, why not give dfmt a spin?  Don't be intimidated by the "beta" label (what does that even mean anyway); try it out and see if it's really as bad as you imagine it to be.  You might be pleasantly surprised.
[...]
> I think it's because I'm experiencing 'the let-down' effect...
> 
> the most recent one being: -profile=gc  (which isn't even 'beta').

Yeah, I'd trust @nogc more than -profile=gc, tbh.


T

-- 
Insanity is doing the same thing over and over again and expecting different results.
January 17
On Monday, 17 January 2022 at 22:27:54 UTC, forkit wrote:
> On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
>>
>> That said, if an automatic formatter works for you, why not give dfmt a spin?  Don't be intimidated by the "beta" label (what does that even mean anyway); try it out and see if it's really as bad as you imagine it to be.  You might be pleasantly surprised.
>>
>>
>> T
>
> I think it's because I'm experiencing 'the let-down' effect...
>
> the most recent one being: -profile=gc  (which isn't even 'beta').

Bug Reports?
January 17
On Mon, Jan 17, 2022 at 10:33:02PM +0000, Johan via Digitalmars-d wrote:
> On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
> > 
> > (Yes I know some code formatters have tags to suppress automatic formatting, etc., but seriously, why do I need to explicitly ask the computer not to do something I didn't want it to do in the first place?)
> 
> The way I use clang-format (default with the sublime plugin by llvm) is that it only reformats your selection or current line, and sometimes one extra line of context around it.

Ah, well that would be nice indeed. ;-)


> clang-format is indeed something I very much miss for D. Precisely this "only reformat this small fragment" functionality is extremely time saving.

Does dfmt not do this?


> Also in code review, you can simply comment "clang-format" and all is clear.  No more discussions about formatting :)
[...]

Point.  I remember when I used to be more active on the Phobos PR queue, a sad amount of time was spent over formatting issues (the right amount ought to be zero. :-D).


T

-- 
Genius may have its limitations, but stupidity is not thus handicapped. -- Elbert Hubbard
January 17
On Monday, 17 January 2022 at 22:37:06 UTC, max haughton wrote:
> On Monday, 17 January 2022 at 22:27:54 UTC, forkit wrote:
>> On Monday, 17 January 2022 at 22:19:51 UTC, H. S. Teoh wrote:
>>>
>>> That said, if an automatic formatter works for you, why not give dfmt a spin?  Don't be intimidated by the "beta" label (what does that even mean anyway); try it out and see if it's really as bad as you imagine it to be.  You might be pleasantly surprised.
>>>
>>>
>>> T
>>
>> I think it's because I'm experiencing 'the let-down' effect...
>>
>> the most recent one being: -profile=gc  (which isn't even 'beta').
>
> Bug Reports?

Mmmm...so they can sit there for the next 7 years? (like the existing ones).

January 17
On Mon, Jan 17, 2022 at 11:04:08PM +0000, forkit via Digitalmars-d wrote:
> On Monday, 17 January 2022 at 22:37:06 UTC, max haughton wrote:
> > On Monday, 17 January 2022 at 22:27:54 UTC, forkit wrote:
[...]
> > > the most recent one being: -profile=gc  (which isn't even 'beta').
> > 
> > Bug Reports?
> 
> Mmmm...so they can sit there for the next 7 years? (like the existing
> ones).

C'mon, it's not that bad. The ones that sit for a long time are usually the ones that are harder to deal with / controversial in some way.

Besides, not filing them means the bugs will remain for ∞ years, which is a lot worse than 7 years. ;-)


T

-- 
Just because you survived after you did it, doesn't mean it wasn't stupid!
January 17
On Monday, 17 January 2022 at 23:10:13 UTC, H. S. Teoh wrote:
>
> C'mon, it's not that bad. The ones that sit for a long time are usually the ones that are harder to deal with / controversial in some way.
>
> Besides, not filing them means the bugs will remain for ∞ years, which is a lot worse than 7 years. ;-)
>
>
> T

'just file a bug' is certainly the easiest response.. I get it.  ;-)

Also, if existing bugs have been discussed and found to be complex or time-consuming, or difficult in one way or another, fine.... I get that too.

But to have bugs sit their for 7 years, not discussed, not addressed in any way.. then.. from where does one get the motivation to file a new bug?

In such situations, it's actually a lot easier, and even makes more sense, to just not use that feature ;-)
« First   ‹ Prev
1 2 3 4 5 6 7 8 9