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

Said Abou-Hallawa sabouhallawa at apple.com
Wed Feb 20 11:26:16 PST 2019



> On Feb 20, 2019, at 10:35 AM, Mark Lam <mark.lam at apple.com> wrote:
> 
> I also prefer it, and I think some coding patterns may require it e.g. in templates where sometimes we want to specialize into a void function, and other times into a function that returns a value.  However, this is rarely needed in practice.  Without being able to return void, writing such a template will be a pain if not impossible.

But the template and the macro cases are different. The void return in this case is implicit and you do not recognize it unless you see the caller.

template<typename Functor>
auto caller(const Functor& functor)
{
    return functor();
}

Nothing in the return statement above says it will return void. But if you pass it a pointer to a returning void function it will. So outside the scope of macros and templates, I think returning void is not nor really needed.

> 
> Mark
> 
>> On Feb 20, 2019, at 7:26 AM, Saam Barati <sbarati at apple.com <mailto:sbarati at apple.com>> wrote:
>> 
>> I prefer it as well.
>> 
>> - Saam
>> 
>> On Feb 20, 2019, at 6:58 AM, Chris Dumez <cdumez at apple.com <mailto:cdumez at apple.com>> wrote:
>> 
>>> I also prefer allowed returning void. 
>>> 
>>> Chris Dumez
>>> 
>>> On Feb 19, 2019, at 10:35 PM, Daniel Bates <dbates at webkit.org <mailto:dbates at webkit.org>> wrote:
>>> 
>>>> 
>>>> 
>>>> On Feb 19, 2019, at 9:42 PM, Ryosuke Niwa <rniwa at webkit.org <mailto:rniwa at webkit.org>> wrote:
>>>> 
>>>>> On Tue, Feb 19, 2019 at 8:59 PM Daniel Bates <dbates at webkit.org <mailto:dbates at webkit.org>> wrote:
>>>>> > On Feb 7, 2019, at 12:47 PM, Daniel Bates <dbates at webkit.org <mailto: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();
>>>>> > }
>>>>> >
>>>>> Based on the responses it seems there is sufficient leaning to codify
>>>>> the latter style.
>>>>> 
>>>>> I don't think there is a sufficient consensus as far as I can tell. Geoff
>>>> 
>>>> I didn't get this from Geoff's remark. Geoff wrote:
>>>> 
>>>> ***“return f()” when f returns void is a bit mind bending.***
>>>> Don't want to put words in Geoff's mouth. So, Geoff can you please confirm: for the former style, for the latter style, no strong opinion.
>>>> 
>>>>> and Alex both expressed preferences for being able to return void,
>>>> 
>>>> I got this from Alex's message
>>>> 
>>>>> and Saam pointed out that there is a lot of existing code which does this.
>>>> 
>>>> I did not get this. He wrote emphasis mine:
>>>> 
>>>> I've definitely done this in JSC. ***I don't think it's super common***, but I've also seen code in JSC not written by me that also does this.
>>>> 
>>>>> Zalan also said he does this in his layout code.
>>>> 
>>>> I did not get this, quoting, emphasis mine:
>>>> 
>>>> I use this idiom too in the layout code. I guess I just prefer a more
>>>> compact code.
>>>> ***(I don't feel too strongly about it though)***
>>>> 
>>>> By the way, you even acknowledged that "WebKit ... tend[s] to have a separate return.". So, I inferred you were okay with it. But from this email I am no longer sure what your position is. Please state it clearly.
>>>> 
>>>>> - R. Niwa
>>>>> 
>>>> _______________________________________________
>>>> webkit-dev mailing list
>>>> webkit-dev at lists.webkit.org <mailto:webkit-dev at lists.webkit.org>
>>>> https://lists.webkit.org/mailman/listinfo/webkit-dev <https://lists.webkit.org/mailman/listinfo/webkit-dev>
>>> _______________________________________________
>>> webkit-dev mailing list
>>> webkit-dev at lists.webkit.org <mailto:webkit-dev at lists.webkit.org>
>>> https://lists.webkit.org/mailman/listinfo/webkit-dev <https://lists.webkit.org/mailman/listinfo/webkit-dev>
>> _______________________________________________
>> webkit-dev mailing list
>> webkit-dev at lists.webkit.org <mailto: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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20190220/923b5813/attachment.html>


More information about the webkit-dev mailing list