clang-format inconsistent behavior

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

clang-format inconsistent behavior

Romanenkov Kirill via cfe-dev

Hi All,

 

I have found an inconsistent behavior in clang-format. When I format the attached desired.c with the attached .clang-format file (using Clang 4.0 on Windows) I get format_me.c.

 

I think that the assignment should be consistent, either break the line for all assignments or none of them. Is there an option I have missed or is this behavior intended/not configurable? And if not configurable would we be interested in such a switch?

 

Regards,

Fabian


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

desired.c (2K) Download Attachment
format_me.c (2K) Download Attachment
ATT98132.clang-format (3K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: clang-format inconsistent behavior

Romanenkov Kirill via cfe-dev
Not sure whether I'm unable to use my mail program correctly, but I don't get a diff between desired.c and format_me.c.

Generally, we've thought about trying to make clang-format be more consistent across subsequent statements, but
a) that's a lot of effort, as clang-format fundamentally works on each statement separately
b) basically all instances (outside of braced lists, which have special support) we've seen have been due to code duplication, where the right answer is to refactor the code so the structure is simpler

For example, in your code, I would pull out a wrapper function that takes all the common parameters in a struct, and potentially the other parameters as structs, too. That way, the calls would become reasonably short.

On Mon, Feb 13, 2017 at 5:35 PM FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) via cfe-dev <[hidden email]> wrote:

Hi All,

 

I have found an inconsistent behavior in clang-format. When I format the attached desired.c with the attached .clang-format file (using Clang 4.0 on Windows) I get format_me.c.

 

I think that the assignment should be consistent, either break the line for all assignments or none of them. Is there an option I have missed or is this behavior intended/not configurable? And if not configurable would we be interested in such a switch?

 

Regards,

Fabian

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
Reply | Threaded
Open this post in threaded view
|

Re: clang-format inconsistent behavior

Romanenkov Kirill via cfe-dev

No sorry the error is on my side. I accidentally copied the same file twice. Find the correct files attached to this mail.

 

I do agree that the interface to the function calls can be improved, but (as you probably know) that is not always possible. I do have two weeks of spare time. Do you think it’s reasonable to implement a switch to specify this behavior as well?

 

Also do you think it’s possible to achieve this in two weeks? Sounds like this change/adding this option might be complex or even impossible?

 

Regards,

Fabian

 

 

From: Manuel Klimek [mailto:[hidden email]]
Sent: Dienstag, 14. Februar 2017 12:24
To: FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) <[hidden email]>; [hidden email]
Subject: Re: [cfe-dev] clang-format inconsistent behavior

 

Not sure whether I'm unable to use my mail program correctly, but I don't get a diff between desired.c and format_me.c.

 

Generally, we've thought about trying to make clang-format be more consistent across subsequent statements, but

a) that's a lot of effort, as clang-format fundamentally works on each statement separately

b) basically all instances (outside of braced lists, which have special support) we've seen have been due to code duplication, where the right answer is to refactor the code so the structure is simpler

 

For example, in your code, I would pull out a wrapper function that takes all the common parameters in a struct, and potentially the other parameters as structs, too. That way, the calls would become reasonably short.

 

On Mon, Feb 13, 2017 at 5:35 PM FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) via cfe-dev <[hidden email]> wrote:

Hi All,

 

I have found an inconsistent behavior in clang-format. When I format the attached desired.c with the attached .clang-format file (using Clang 4.0 on Windows) I get format_me.c.

 

I think that the assignment should be consistent, either break the line for all assignments or none of them. Is there an option I have missed or is this behavior intended/not configurable? And if not configurable would we be interested in such a switch?

 

Regards,

Fabian

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

format_me.c (2K) Download Attachment
desired.c (2K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: clang-format inconsistent behavior

Romanenkov Kirill via cfe-dev
On Wed, Feb 15, 2017 at 10:02 AM FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) <[hidden email]> wrote:

No sorry the error is on my side. I accidentally copied the same file twice. Find the correct files attached to this mail.

 

I do agree that the interface to the function calls can be improved, but (as you probably know) that is not always possible. I do have two weeks of spare time. Do you think it’s reasonable to implement a switch to specify this behavior as well?

 

Also do you think it’s possible to achieve this in two weeks? Sounds like this change/adding this option might be complex or even impossible?


I don't think two weeks will be enough to come up with a solution that gets consensus; if not due to the work required, the latency alone will prevent this (I'd expect this to go through multiple possible architectural revisions)
 

 

Regards,

Fabian

 

 

From: Manuel Klimek [mailto:[hidden email]]
Sent: Dienstag, 14. Februar 2017 12:24
To: FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) <[hidden email]>; [hidden email]
Subject: Re: [cfe-dev] clang-format inconsistent behavior

 

Not sure whether I'm unable to use my mail program correctly, but I don't get a diff between desired.c and format_me.c.

 

Generally, we've thought about trying to make clang-format be more consistent across subsequent statements, but

a) that's a lot of effort, as clang-format fundamentally works on each statement separately

b) basically all instances (outside of braced lists, which have special support) we've seen have been due to code duplication, where the right answer is to refactor the code so the structure is simpler

 

For example, in your code, I would pull out a wrapper function that takes all the common parameters in a struct, and potentially the other parameters as structs, too. That way, the calls would become reasonably short.

 

On Mon, Feb 13, 2017 at 5:35 PM FIXED-TERM Kammel Fabian (ETAS-PSC/EPE) via cfe-dev <[hidden email]> wrote:

Hi All,

 

I have found an inconsistent behavior in clang-format. When I format the attached desired.c with the attached .clang-format file (using Clang 4.0 on Windows) I get format_me.c.

 

I think that the assignment should be consistent, either break the line for all assignments or none of them. Is there an option I have missed or is this behavior intended/not configurable? And if not configurable would we be interested in such a switch?

 

Regards,

Fabian

_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev


_______________________________________________
cfe-dev mailing list
[hidden email]
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev