This is an archive of the discontinued LLVM Phabricator instance.

ClangFormat - Add one space in inline empty function that can be wrapped on a single line.
AbandonedPublic

Authored by Abpostelnicu on Sep 18 2017, 8:27 AM.

Details

Reviewers
djasper
klimek
Summary

At Mozilla out coding style tells that short inline member functions that can be wrapped on a single line should have an empty space between the bracelets, like in this example:

class MyClass
{ 
  MyClass() { }
}

The documentation for this behaviour can be found here.
The purpose of this space is to add this option to clang-format through the variable: AddSpaceInEmptyInlineFunction.

Diff Detail

Event Timeline

Abpostelnicu created this revision.Sep 18 2017, 8:27 AM
Abpostelnicu edited the summary of this revision. (Show Details)
Abpostelnicu added a reviewer: djasper.
klimek edited edge metadata.Sep 25 2017, 5:10 AM

Can you point out where that's spelled out in the style guide? I can't find a reference to it (searching for "{}" or "{ }" doesn't provide any hits).
I'm slightly opposed to this, given that so far I haven't heard a convincing argument why this makes any difference to readability.

Abpostelnicu added a comment.EditedSep 25 2017, 5:16 AM

Can you point out where that's spelled out in the style guide? I can't find a reference to it (searching for "{}" or "{ }" doesn't provide any hits).
I'm slightly opposed to this, given that so far I haven't heard a convincing argument why this makes any difference to readability.

I see your point, it's not stetted effectively on the coding style page, but if you look in the coding style you will find this:

// Tiny constructors and destructors can be written on a single line.
MyClass() { ... }

Which translates to the fact that you need an empty space in the empty inline functions. Also we have this bug on this matter. I know that this modification should seem a bit strange but this is the way how most of our code is written in the presented situations.

Also doing a grep in our online repository:
https://dxr.mozilla.org/mozilla-central/search?q=%22%7B+%7D&redirect=false

You can see that the incidence of this behaviour is huge. I know the grep produces also noise but still the occurrence is this scenario is huge.

Also doing a grep in our online repository:
https://dxr.mozilla.org/mozilla-central/search?q=%22%7B+%7D&redirect=false

You can see that the incidence of this behaviour is huge. I know the grep produces also noise but still the occurrence is this scenario is huge.

I also see lots of code that uses {}? Thus, it seems like the code base is not very strict, and going either way enforced with clang-format will be nicer?
https://dxr.mozilla.org/mozilla-central/search?q=%22+%7B%7D&redirect=true

I also see lots of code that uses {}? Thus, it seems like the code base is not very strict, and going either way enforced with clang-format will be nicer?
https://dxr.mozilla.org/mozilla-central/search?q=%22+%7B%7D&redirect=true

Indeed, this is why we are working on enforcing that.
This patch is one of the last change to match exactly our coding style. This is why Andi wrote it.

If you could accept it, it would be great. If you won't, please let us know to see what we can do on our side. Thanks!

djasper edited edge metadata.Oct 12 2017, 12:35 AM

I believe that this extra option is not worth its cost in terms of maintainability and (more importantly) discoverability of options. You say that the behavior is documented in your coding style, but it is not (probably for the same reason). There isn't even a single example of this, I think. As such, I don't think we should go forward with adding this option.

I also see lots of code that uses {}? Thus, it seems like the code base is not very strict, and going either way enforced with clang-format will be nicer?
https://dxr.mozilla.org/mozilla-central/search?q=%22+%7B%7D&redirect=true

Indeed, this is why we are working on enforcing that.
This patch is one of the last change to match exactly our coding style. This is why Andi wrote it.

If you could accept it, it would be great. If you won't, please let us know to see what we can do on our side. Thanks!

I'm with Daniel. It looks like there's more code using {} than { } (although I don't know how much noise those searches have), so why not make {} your style rule and enforce that? Style guides are living entities :)

We recently found out the default behaviour of formatting {} changes from {} in clang 8.0 to { } in clang 10.0+. Could someone revive this changeset and kindly review it? We would really like to have a way to specify no space in empty braces.

@mhq199657 we (Mozilla/Firefox) moved to the Google Coding style. So, we are less interested by this change now.

Therefore, we are probably not going to spend time on this as @klimek and @djasper both said no :)

We recently found out the default behaviour of formatting {} changes from {} in clang 8.0 to { } in clang 10.0+. Could someone revive this changeset and kindly review it? We would really like to have a way to specify no space in empty braces.

I just experienced the same. If the general agreement is that {} is preferred over { }, why did clang 10.0+ change to { }? Is this a bug? Is this documented anywhere?
Rather than reviving the request for an option that leads to a single space, it seems to me that what we all want is for clang-format to output {} again, right?

Abpostelnicu abandoned this revision.Apr 12 2021, 3:44 AM