Use ptr#NAME whenever the return value is stored#2645
Conversation
uklotzde
left a comment
There was a problem hiding this comment.
I disagree to replace all local, mutable references with pointers. That doesn't make any sense to me.
| if (!metadataSynchronized.isNull()) { | ||
| modified |= compareAndSet( | ||
| &m_record.refMetadataSynchronized(), | ||
| m_record.ptrMetadataSynchronized(), |
There was a problem hiding this comment.
This is the only application that I had in mind and that actually makes sense to me.
| mixxx::AlbumInfo& oldAlbumInfo = oldTrackMetadata.refAlbumInfo(); | ||
| oldAlbumInfo.setArtist("old album artist"); | ||
| oldAlbumInfo.setTitle("old album title"); | ||
| mixxx::TrackMetadata* pOldTrackMetadata = oldTrackRecord.ptrMetadata(); |
|
Regarding non const references, there are two mutually exclusive styles established: 1.) Google/Qt: "References can be confusing, as they have value syntax but pointer semantics." 2.) Cpp Core Guidelines: "This makes it clear to callers that the object is assumed to be modified" You find a lot of threads where developer argue for one or the other. Since we follow the Google style, I have changed the occurrences of non-const references to keep the reliability that fore instance a |
I never questioned the style to pass pointers instead of mutable references for out arguments. This is what the citations refer to. But where does the Google style guide refer to mutable references that are returned as results from simple, mutable accessor functions? |
This applies to any non-const reference variable independent if it was initialized as Funktion parameter or from a function return value. |
|
So if I decide to store the result of a QMap::iterator member function in a local variable with a descriptive name for documentation purposes and comprehension I have to apply the |
|
You mean |
Please let us keep those performance topics out of the discussion. They are completely irrelevant. I am referring to |
|
Yes, in that case. But I think this discussion is not relevant, because I have just skimmed through the Mixxx code and found no occourence where the return value of T& value() and friends is stored as a T&. I don't even find a place where we use value() and friends for an assignment like this This PR is just about improve the readability in the sense of the Google style: It was not my intention to discuss if this is sensible or not. |
|
I am not convinced. But in order to move one I will accept these changes. They will cause some rework and resolving merge conflicts on my side now. |
|
Oh, I am sorry. |
|
Some of the indents don't seem to be correct, but i will fix this when needed. |
This is a follow up from #2601, making use of the new function