[webkit-dev] [webkit-reviewers] usage of auto

Chris Dumez cdumez at apple.com
Tue Jan 10 22:02:08 PST 2017


I usually like using auto / auto* as much as possible.

The one exception where I have found using auto confusing was for functions returning an std::optional. 

E.g.
auto value = maximum();
if (!value)
    return;

I find that the check is confusing because it returns early if value is 0 in the case where maximum() returns an integer but checks if the value is set in the case the function returns an std::optional.

Chris Dumez

On Jan 10, 2017, at 9:51 PM, Darin Adler <darin at apple.com> wrote:

>> On Jan 10, 2017, at 9:49 PM, Darin Adler <darin at apple.com> wrote:
>> 
>>> On Jan 10, 2017, at 9:46 PM, Simon Fraser <simon.fraser at apple.com> wrote:
>>> 
>>> auto countOfThing = getNumberOfThings();
>>> ASSERT(countOfThing >= 0);  // Can’t tell by reading whether the ASSERT is assured at compile time if countOfThing is unsigned
>> 
>> I understand wanting to know, but I am not certain this is a bad thing.
> 
> Sorry, let me say something different, but related:
> 
>    int countOfThing = getNumberOfThings();
> 
> Can’t tell from the above code if getNumberOfThings() returns int or unsigned.
> 
> — Darin
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.webkit.org/pipermail/webkit-dev/attachments/20170110/d7cf7158/attachment.html>


More information about the webkit-dev mailing list