[webkit-dev] Code Style: Opinion on returning void

Alex Christensen achristensen at apple.com
Thu Feb 7 19:31:36 PST 2019


If you search for “return completionHandler” in WebKit you will find over a hundred instances.  Most if not all of them return void.  It means call the completion handler and return.  I probably wrote most of them and obviously think it’s a fabulous idiom.

> On Feb 7, 2019, at 2:32 PM, Geoffrey Garen <ggaren at apple.com> wrote:
> 
> FWIW, I’ve always felt conflicted about this case.
> 
> I very much prefer early return to if/else chains.
> 
> However, “return f()” when f returns void is a bit mind bending.
> 
> So, I can’t use my preferred style in functions that return void. Boo. 
> 
> Geoff
> 
>> On Feb 7, 2019, at 12:47 PM, Daniel Bates <dbates at webkit.org> wrote:
>> 
>> Hi all,
>> 
>> Something bothers me about code like:
>> 
>> void f();
>> void g()
>> {
>>    if (...)
>>        return f();
>>    return f();
>> }
>> 
>> I prefer:
>> 
>> void g()
>> {
>>    if (...) {
>>        f();
>>        return
>>    }
>>    f();
>> }
>> 
>> Does it bother you? For the former? For the latter? Update our style guide?
>> 
>> Opinions, please.
>> 
>> Dan
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org
>> https://lists.webkit.org/mailman/listinfo/webkit-dev
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev



More information about the webkit-dev mailing list