--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Beyond the fairly limited case of bool conversions, can you think of any other use case for Chromium code?
I support this exactly for our implementations such as scoped_ptr, weak_ptr, and skia::RefPtr.People often write if (foo.get()) or if (foo.get() != NULL) instead of just if (foo), and I think it's because it's really difficult to see that there is an operator bool on these types, since we have to disguise it so much. This would make the operator explicit, highly visible, and more easily learnable.I don't mind waiting on this for a bit, but this would only improve the readability of some of our more core classes.
Beyond the fairly limited case of bool conversions, can you think of any other use case for Chromium code?This doesn't seem to be all that rare, and is not only limited to "bool" conversions. Here is a top chunk of search results... The list goes on...
scoped_ptr and weak_ptr are currently testable, so people shouldn't be using .get() in those cases.
On Thu, Sep 25, 2014 at 3:11 PM, Daniel Cheng <dch...@chromium.org> wrote:scoped_ptr and weak_ptr are currently testable, so people shouldn't be using .get() in those cases.Yes, my point is that people don't. I have to correct this in code reviews a lot. If making this more obvious in the classes would mean I have to comment on this and look for it in review less, then I fully support that. And I suspect that it would, but hey, maybe not.
On Sep 25, 2014 12:21 PM, "Alex Vakulenko" <avaku...@chromium.org> wrote:
>
> I have to agree with Dana. I'm kind of new and while reading through the header implementation of scoped_ptr<> if I had seen "explicit operator boo() const" I would have known what I should be using to test the validity of the pointer. If I see "operator Testable()" which in turn is a private type, this makes no sense to me and I might be inclined to do if(ptr.get()) instead. I thought we were trying to tailor the code for the benefit of the reader.
If you're reading the header, you're reading the comment right next to it.
However, this optimization for readers has little (but some...) to do with reading headers, and has everything to do with "Can you infer from the code at the code site what will happen, WITHOUT having to read the header"
And this discussion does not in any meaningful way change that.
Put differently, whether explicit bool or Testable, its a matter of evagenlizing that .get() isn't needed. And frankly, that isn't something the header will change.
I support this exactly for our implementations such as scoped_ptr, weak_ptr, and skia::RefPtr.People often write if (foo.get()) or if (foo.get() != NULL) instead of just if (foo), and I think it's because it's really difficult to see that there is an operator bool on these types, since we have to disguise it so much. This would make the operator explicit, highly visible, and more easily learnable.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.
The reason I always mess them up is that it's been in perpetual transition and I can't keep in my mind which one works and is recommended vs which one works but is deprecated vs which one is recommended but doesn't work yet vs which one the compiler refuses (which varies per platform!), × the context (pointer conversion vs null testing vs equality comparison), × the type of smart pointer.
--
--
Chromium Developers mailing list: chromi...@chromium.org
View archives, change email options, or unsubscribe:
http://groups.google.com/a/chromium.org/group/chromium-dev
Daniel
Explicit conversion operators appear to be buggy in VS 2013. https://codereview.chromium.org/609593004 attempts to add an explicit bool conversion operator scoped_refptr, but it fails on Windows bots. The failing contexts are all comparisons of a scoped_refptr to NULL.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-dev...@chromium.org.