This is an archive of the discontinued LLVM Phabricator instance.

[clang-format][NFC] Prefer pass by reference
ClosedPublic

Authored by HazardyKnusperkeks on Dec 3 2021, 11:49 AM.

Diff Detail

Event Timeline

HazardyKnusperkeks requested review of this revision.Dec 3 2021, 11:49 AM
HazardyKnusperkeks created this revision.
Herald added a project: Restricted Project. · View Herald TranscriptDec 3 2021, 11:49 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

What do we usually do for output parameters?
I'm ok with both refs and pointers. It seems to me to be google-style thingy to pass by pointer.
It is indeed clearer at the caller site that the passed variable will be modified.
Are you worried about any performance penalty when using pointers? If so, adding nonnull attribute or sth like this may help.

FWLIW, I'm strongly in favor of "Pass out-parameters by pointer," for the reason Marek said (and the reason Google, Bloomberg, Facebook, Mongo, etc, do it) — it makes life easier for the reader of the calling code. Especially for e.g. addNextStateToQueue(Penalty, Node, /*NewLine=*/false, Count, Queue), I don't think it's at all obvious that this is going to modify the value of Count!
But this isn't my code and I don't know what LLVM's house style is.

No I don't think there is a performance penalty. I just don't like using pointers. I'm happy to drop this, if the Style says to use pointers. But from what I've seen in clang-format pointers are mostly used when it can be null, but there is a wild mix.

owenpan accepted this revision.Dec 3 2021, 7:02 PM

No I don't think there is a performance penalty. I just don't like using pointers. I'm happy to drop this, if the Style says to use pointers. But from what I've seen in clang-format pointers are mostly used when it can be null, but there is a wild mix.

I don't think LLVM Coding Standards specify it one way or the other, so it LGTM.

This revision is now accepted and ready to land.Dec 3 2021, 7:02 PM
This revision was automatically updated to reflect the committed changes.

This was not intended to be pushed, I forgot to move it out of the chunk. If we come to the conclusion that we want pointers I will revert this. If no one objects in the next say 3 days I will leave it so.

I share Arthur's point of view and I prefer the pointers. I don't see an advantage of this proposed change.
If only we had C#'s out...

I will revert.

This revision is now accepted and ready to land.Dec 5 2021, 3:32 AM