--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CADF%2BPP7bQxVu_CnkYrM53FPqfWtNWnOCnzw93%3DNy_%3DisRDhmwQ%40mail.gmail.com.
--
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CADF%2BPP4%2BLmVYBpKFz4WFTLWO1wKFhyV3h8kNGM2YptXUrQSCUA%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANHK6RZd%2ByOiGywOLj-EnwvCdTzMsSVu82OQs-WuUbrhMzAQAg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABWS%2BBx%3DpQrCi3xnF5pTD%3DeDLoy1YKQTaVEDDWAvHgdUxqW5ag%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/b5e18d5b-711f-4e5f-bbbd-3cf7bfa3420e%40chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANHK6RbkXWL93WDoJ9JKxL9S-t-6ro_r8UzudsTYroqZ8nKvMw%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CA%2BN%2BEKZkW9h99ajKoEq3vThPpjr7pbgn65CqF8FgqpwQFmXYWg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CANHK6RZh_xyC-PymG0bBmiCU1-h6s%2BLqs_au%3D4qkN%3DrYKT7vmw%40mail.gmail.com.
BTW, what does our code style say ofFoo* GetFoo() {static Foo* foo = new Foo();return foo;}vsFoo& GetFoo() {static Foo* foo = new Foo();return *foo;}?
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABWS%2BBy%2BfzXWJQc7KHzUF0rodm3ch1BiRN9HdjTWkosuYBn7CA%40mail.gmail.com.
BTW, what does our code style say ofFoo* GetFoo() {static Foo* foo = new Foo();return foo;}vsFoo& GetFoo() {static Foo* foo = new Foo();return *foo;}
PK
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAAHOzFCauk3GYLoYj1u0odfVAFg6MU00skG4auZeCHBKsJRqfA%40mail.gmail.com.
On Tue, Jan 31, 2017 at 4:04 PM, 'Peter Kasting' via cxx <c...@chromium.org> wrote:On Tue, Jan 31, 2017 at 12:57 PM, 'Dmitry Skiba' via cxx <c...@chromium.org> wrote:BTW, what does our code style say ofFoo* GetFoo() {static Foo* foo = new Foo();return foo;}vsFoo& GetFoo() {static Foo* foo = new Foo();return *foo;}"it is a very strong convention in Google code that input arguments are values or const references while output arguments are pointers"The rest of that section is slightly ambiguous, because it speaks strongly of disallowing non-const refs as parameters, but it mostly sounds like it's speaking about input parameters, except for this sentence that speaks about "output arguments".However, at the least, I think this suggests preferring return-by-pointer, even if it's not mandated. In most non-Blink Chromium code I've used (with a few high-profile exceptions), we avoid using non-const refs pretty much anywhere. Because of these factors, I ask authors to avoid non-const refs, and convert code not to use them when I encounter it.Interesting, I've never thought that rules about arguments could apply to return values. Is this a practice followed in google3?
The reasoning for not passing arguments by non-const ref is that the caller can't tell that their lvalue thing is going to be modified. This isn't something relevant for returns though.
On Tue, Jan 31, 2017 at 1:08 PM, <dan...@chromium.org> wrote:On Tue, Jan 31, 2017 at 4:04 PM, 'Peter Kasting' via cxx <c...@chromium.org> wrote:On Tue, Jan 31, 2017 at 12:57 PM, 'Dmitry Skiba' via cxx <c...@chromium.org> wrote:BTW, what does our code style say ofFoo* GetFoo() {static Foo* foo = new Foo();return foo;}vsFoo& GetFoo() {static Foo* foo = new Foo();return *foo;}"it is a very strong convention in Google code that input arguments are values or const references while output arguments are pointers"The rest of that section is slightly ambiguous, because it speaks strongly of disallowing non-const refs as parameters, but it mostly sounds like it's speaking about input parameters, except for this sentence that speaks about "output arguments".However, at the least, I think this suggests preferring return-by-pointer, even if it's not mandated. In most non-Blink Chromium code I've used (with a few high-profile exceptions), we avoid using non-const refs pretty much anywhere. Because of these factors, I ask authors to avoid non-const refs, and convert code not to use them when I encounter it.Interesting, I've never thought that rules about arguments could apply to return values. Is this a practice followed in google3?I don't work in google3, so the quote about "output arguments are pointers" being a "strong convention in Google code" is the only information I have.
The reasoning for not passing arguments by non-const ref is that the caller can't tell that their lvalue thing is going to be modified. This isn't something relevant for returns though.Guessing at motivations, I would say that use of non-const refs in general (not just in function calls) leads to code where it's harder to see that object modifications are happening, so the idea is just to discourage all use of non-const refs.
On Tue, Jan 31, 2017 at 4:11 PM, Peter Kasting <pkas...@google.com> wrote:On Tue, Jan 31, 2017 at 1:08 PM, <dan...@chromium.org> wrote:On Tue, Jan 31, 2017 at 4:04 PM, 'Peter Kasting' via cxx <c...@chromium.org> wrote:On Tue, Jan 31, 2017 at 12:57 PM, 'Dmitry Skiba' via cxx <c...@chromium.org> wrote:BTW, what does our code style say ofFoo* GetFoo() {static Foo* foo = new Foo();return foo;}vsFoo& GetFoo() {static Foo* foo = new Foo();return *foo;}"it is a very strong convention in Google code that input arguments are values or const references while output arguments are pointers"The rest of that section is slightly ambiguous, because it speaks strongly of disallowing non-const refs as parameters, but it mostly sounds like it's speaking about input parameters, except for this sentence that speaks about "output arguments".However, at the least, I think this suggests preferring return-by-pointer, even if it's not mandated. In most non-Blink Chromium code I've used (with a few high-profile exceptions), we avoid using non-const refs pretty much anywhere. Because of these factors, I ask authors to avoid non-const refs, and convert code not to use them when I encounter it.Interesting, I've never thought that rules about arguments could apply to return values. Is this a practice followed in google3?I don't work in google3, so the quote about "output arguments are pointers" being a "strong convention in Google code" is the only information I have.But output arguments != return values. Output arguments are arguments that the function modifies.
A query for "^\ *[a-zA-Z0-9:]+& -operator" finds almost a million instances,
so I don't think this is supposed to apply to return values.
I believe we should:- try to not use LazyInstance in new code;- replace code that uses LazyInstance where it could be replaced by less code (this seems to apply especially to LazyInstance::Leaky);
On Tue, Jan 31, 2017 at 12:15 PM, Scott Graham <sco...@chromium.org> wrote:I believe we should:- try to not use LazyInstance in new code;- replace code that uses LazyInstance where it could be replaced by less code (this seems to apply especially to LazyInstance::Leaky);Doesn't a static call a destructor on shutdown?
Brett
--
You received this message because you are subscribed to the Google Groups "cxx" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cxx+uns...@chromium.org.
To post to this group, send email to c...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABiGVV-%3DN8fjr0%3DXPXYqwXztP0GNAd1Foc%3DYC7jzKzLROWZpNQ%40mail.gmail.com.
We’re not doingSnooze* GetSnooze() {static Snooze s;return &s;}We’re doingSnooze* GetSnooze() {static Snooze* s = new Snooze();return s;}Nothing registers any at-exit code in this case.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHk1GDz6ngr4oA%2BGQ%2B46URzRBP2E%3Did0S1fMmaNuMgkcLtnMQA%40mail.gmail.com.
Returning a reference is nice in the case whether the object is never null:
Returning a reference is nice in the case whether the object is never null:Foo& foo();v.s.// Hey users. The return pointer is never null. So you don't need to do null-check.Foo* foo();
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABxY52A5MFi2R8a%3DSArWRhOZz4QN_ovFpq7uk5Pikt%3DNty-V%3Dg%40mail.gmail.com.
Returning a reference is nice in the case where the object is never null:
Foo& foo();v.s.// Hey users. The return pointer is never null. So you don't need to do null-check.Foo* foo();
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABxY52A5MFi2R8a%3DSArWRhOZz4QN_ovFpq7uk5Pikt%3DNty-V%3Dg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CAHPGDUYG1OkvGUe%3DTWTuhuVpKtDSb7RMEWSLgJD9tQBVv-SQeg%40mail.gmail.com.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/cxx/CABdZ6yApuN5CvKNnEe4t268LpiZAA5kYFo-joWhxNUo-SMCo%3DQ%40mail.gmail.com.