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

Daniel Bates dbates at webkit.org
Tue Feb 19 22:35:35 PST 2019


On Feb 19, 2019, at 9:42 PM, Ryosuke Niwa <rniwa at webkit.org> wrote:

On Tue, Feb 19, 2019 at 8:59 PM Daniel Bates <dbates at webkit.org> wrote:

> > 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();
> > }
> >
> 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20190219/0b1cdab3/attachment.html>


More information about the webkit-dev mailing list