[prev in list] [next in list] [prev in thread] [next in thread] 

List:       webkit-dev
Subject:    Re: [webkit-dev] Code Style: Opinion on returning void
From:       Maciej Stachowiak <mjs () apple ! com>
Date:       2019-02-20 21:14:38
Message-ID: 142DE48D-AAD3-4393-957A-1071C6BFA740 () apple ! com
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


It seems like `return foo();` where foo() is a void function can always be replaced \
with `foo(); return;` for greater clarity at the cost of one extra line break. For \
people who prefer the one-line style, can you say why you don't like the other way?

 - Maciej

> On Feb 20, 2019, at 10:33 AM, Simon Fraser <simon.fraser@apple.com> wrote:
> 
> I find it mind bending. It makes me wonder if the author made a coding error.
> 
> Simon
> 
> > On Feb 20, 2019, at 7:48 AM, Daniel Bates <dbates@webkit.org \
> > <mailto:dbates@webkit.org>> wrote: 
> > Thanks for the opinion!
> > 
> > Dan
> > 
> > On Feb 20, 2019, at 7:26 AM, Saam Barati <sbarati@apple.com \
> > <mailto:sbarati@apple.com>> wrote: 
> > > I prefer it as well.
> > > 
> > > - Saam
> > > 
> > > On Feb 20, 2019, at 6:58 AM, Chris Dumez <cdumez@apple.com \
> > > <mailto:cdumez@apple.com>> wrote: 
> > > > I also prefer allowed returning void. 
> > > > 
> > > > Chris Dumez
> > > > 
> > > > On Feb 19, 2019, at 10:35 PM, Daniel Bates <dbates@webkit.org \
> > > > <mailto:dbates@webkit.org>> wrote: 
> > > > > 
> > > > > 
> > > > > On Feb 19, 2019, at 9:42 PM, Ryosuke Niwa <rniwa@webkit.org \
> > > > > <mailto:rniwa@webkit.org>> wrote: 
> > > > > > On Tue, Feb 19, 2019 at 8:59 PM Daniel Bates <dbates@webkit.org \
> > > > > > <mailto:dbates@webkit.org>> wrote:
> > > > > > > On Feb 7, 2019, at 12:47 PM, Daniel Bates <dbates@webkit.org \
> > > > > > > <mailto:dbates@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@lists.webkit.org <mailto:webkit-dev@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@lists.webkit.org <mailto:webkit-dev@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@lists.webkit.org <mailto:webkit-dev@lists.webkit.org>
> > https://lists.webkit.org/mailman/listinfo/webkit-dev
> 
> _______________________________________________
> webkit-dev mailing list
> webkit-dev@lists.webkit.org
> https://lists.webkit.org/mailman/listinfo/webkit-dev


[Attachment #5 (text/html)]

<html><head><meta http-equiv="Content-Type" content="text/html; \
charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; \
line-break: after-white-space;" class=""><div class=""><br class=""></div>It seems \
like `return foo();` where foo() is a void function can always be replaced with \
`foo(); return;` for greater clarity at the cost of one extra line break. For people \
who prefer the one-line style, can you say why you don't like the other way?<div \
class=""><br class=""></div><div class="">&nbsp;- Maciej<br class=""><div><br \
class=""><blockquote type="cite" class=""><div class="">On Feb 20, 2019, at 10:33 AM, \
Simon Fraser &lt;<a href="mailto:simon.fraser@apple.com" \
class="">simon.fraser@apple.com</a>&gt; wrote:</div><br \
class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" \
content="text/html; charset=utf-8" class=""><div style="word-wrap: break-word; \
-webkit-nbsp-mode: space; line-break: after-white-space;" class="">I find it mind \
bending. It makes me wonder if the author made a coding error.<div class=""><br \
class=""></div><div class="">Simon<br class=""><div class=""><br class=""><blockquote \
type="cite" class=""><div class="">On Feb 20, 2019, at 7:48 AM, Daniel Bates &lt;<a \
href="mailto:dbates@webkit.org" class="">dbates@webkit.org</a>&gt; wrote:</div><br \
class="Apple-interchange-newline"><div class=""><div dir="auto" class="">Thanks for \
the opinion!<br class=""><br class=""><div dir="ltr" class="">Dan</div><div dir="ltr" \
class=""><br class="">On Feb 20, 2019, at 7:26 AM, Saam Barati &lt;<a \
href="mailto:sbarati@apple.com" target="_blank" class="">sbarati@apple.com</a>&gt; \
wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" \
class="">I prefer it as well.<br class=""><br class=""><div dir="ltr" class="">- \
Saam</div><div dir="ltr" class=""><br class="">On Feb 20, 2019, at 6:58 AM, Chris \
Dumez &lt;<a href="mailto:cdumez@apple.com" target="_blank" \
class="">cdumez@apple.com</a>&gt; wrote:<br class=""><br class=""></div><blockquote \
type="cite" class=""><div dir="ltr" class="">I also prefer allowed returning \
void.&nbsp;<br class=""><br class=""><div dir="ltr" class=""><div \
style="direction:inherit" class="">Chris Dumez</div></div><div dir="ltr" class=""><br \
class="">On Feb 19, 2019, at 10:35 PM, Daniel Bates &lt;<a \
href="mailto:dbates@webkit.org" target="_blank" class="">dbates@webkit.org</a>&gt; \
wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" \
class=""><div dir="ltr" class=""><div dir="auto" class=""><div dir="ltr" \
class=""><span class=""></span></div><div dir="ltr" class=""><div dir="ltr" \
class=""><div dir="ltr" class=""><div dir="ltr" class=""><div dir="ltr" class=""><div \
dir="ltr" class=""><div dir="ltr" class=""><div dir="auto" class=""><br class=""><div \
dir="ltr" class=""><br class="">On Feb 19, 2019, at 9:42 PM, Ryosuke Niwa &lt;<a \
href="mailto:rniwa@webkit.org" target="_blank" class="">rniwa@webkit.org</a>&gt; \
wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div dir="ltr" \
class=""><div dir="ltr" class=""><div dir="ltr" class="">On Tue, Feb 19, 2019 at 8:59 \
PM Daniel Bates &lt;<a href="mailto:dbates@webkit.org" target="_blank" \
class="">dbates@webkit.org</a>&gt; wrote:<br class=""></div><div \
class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px \
0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex">&gt; \
On Feb 7, 2019, at 12:47 PM, Daniel Bates &lt;<a href="mailto:dbates@webkit.org" \
target="_blank" class="">dbates@webkit.org</a>&gt; wrote:<br class=""> &gt;<br \
class=""> &gt; Hi all,<br class="">
&gt;<br class="">
&gt; Something bothers me about code like:<br class="">
&gt;<br class="">
&gt; void f();<br class="">
&gt; void g()<br class="">
&gt; {<br class="">
&gt;&nbsp; &nbsp; &nbsp;if (...)<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return f();<br class="">
&gt;&nbsp; &nbsp; &nbsp;return f();<br class="">
&gt; }<br class="">
&gt;<br class="">
&gt; I prefer:<br class="">
&gt;<br class="">
&gt; void g()<br class="">
&gt; {<br class="">
&gt;&nbsp; &nbsp; &nbsp;if (...) {<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;f();<br class="">
&gt;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return<br class="">
&gt;&nbsp; &nbsp; &nbsp;}<br class="">
&gt;&nbsp; &nbsp; &nbsp;f();<br class="">
&gt; }<br class="">
&gt;<br class="">
Based on the responses it seems there is sufficient leaning to codify<br class="">
the latter style.<br class=""></blockquote><div class=""><br class=""></div><div \
class="">I don't think there is a sufficient consensus as far as I can tell. Geoff \
</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I \
didn't get this from Geoff's remark. Geoff wrote:</div><div class=""><br \
class=""></div><div class=""><pre style="white-space: pre-wrap;" class="">***"return \
f()" when f returns void is a bit mind bending.***</pre><pre \
style="white-space:pre-wrap" class=""><font class="">Don't want to put words in \
Geoff's mouth. So,</font><span \
style="color:rgb(34,34,34);font-family:Arial,Helvetica,sans-serif" \
class="">&nbsp;Geoff can you please confirm: for the former style, for the latter \
style, no strong opinion.</span><font class=""><br class=""></font></pre></div><br \
class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div dir="ltr" \
class=""><div class="gmail_quote"><div class="">and Alex both expressed preferences \
for being able to return void,</div></div></div></div></blockquote><div class=""><br \
class=""></div><div class="">I got this from Alex's message</div><div class=""><br \
class=""></div><blockquote type="cite" class=""><div dir="ltr" class=""><div \
dir="ltr" class=""><div class="gmail_quote"><div class=""> and Saam pointed out that \
there is a lot of existing code which does this. \
</div></div></div></div></blockquote><div class=""><br class=""></div><div class="">I \
did not get this. He wrote emphasis mine:</div><div class=""><br class=""></div><div \
class=""><pre style="white-space: pre-wrap;" class="">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.</pre></div><br class=""><blockquote type="cite" \
class=""><div dir="ltr" class=""><div dir="ltr" class=""><div \
class="gmail_quote"><div class="">Zalan also said he does this in his layout \
code.</div></div></div></div></blockquote><div class=""><br class=""></div><div \
class="">I did not get this, quoting, emphasis mine:</div><div class=""><br \
class=""></div><div class=""><pre style="white-space: pre-wrap;" class="">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)***</pre><pre style="white-space: \
pre-wrap;" class=""><br class=""></pre></div><div class="">By the way, you even \
acknowledged that "<span style="white-space: pre-wrap;" class="">WebKit ... \
</span><span style="white-space: pre-wrap;" class="">tend[s] to have a separate \
return."</span>. 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.</div><br \
class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div dir="ltr" \
class=""><div class="gmail_quote"><div class="">- R. Niwa</div><div class=""><br \
class=""></div></div></div> \
</div></blockquote></div></div></div></div></div></div></div> </div></div></div>
</div></blockquote><blockquote type="cite" class=""><div dir="ltr" class=""><span \
class="">______________________________<wbr class="">_________________</span><br \
class=""><span class="">webkit-dev mailing list</span><br class=""><span class=""><a \
href="mailto:webkit-dev@lists.webkit.org" target="_blank" \
class="">webkit-dev@lists.webkit.org</a></span><br class=""><span class=""><a \
href="https://lists.webkit.org/mailman/listinfo/webkit-dev" target="_blank" \
class="">https://lists.webkit.org/<wbr \
class="">mailman/listinfo/webkit-dev</a></span><br \
class=""></div></blockquote></div></blockquote><blockquote type="cite" class=""><div \
dir="ltr" class=""><span class="">______________________________<wbr \
class="">_________________</span><br class=""><span class="">webkit-dev mailing \
list</span><br class=""><span class=""><a href="mailto:webkit-dev@lists.webkit.org" \
target="_blank" class="">webkit-dev@lists.webkit.org</a></span><br class=""><span \
class=""><a href="https://lists.webkit.org/mailman/listinfo/webkit-dev" \
target="_blank" class="">https://lists.webkit.org/<wbr \
class="">mailman/listinfo/webkit-dev</a></span><br \
class=""></div></blockquote></div></blockquote></div> \
_______________________________________________<br class="">webkit-dev mailing \
list<br class=""><a href="mailto:webkit-dev@lists.webkit.org" \
class="">webkit-dev@lists.webkit.org</a><br class=""><a \
href="https://lists.webkit.org/mailman/listinfo/webkit-dev" \
class="">https://lists.webkit.org/mailman/listinfo/webkit-dev</a><br \
class=""></div></blockquote></div><br \
class=""></div></div>_______________________________________________<br \
class="">webkit-dev mailing list<br class=""><a \
href="mailto:webkit-dev@lists.webkit.org" class="">webkit-dev@lists.webkit.org</a><br \
class="">https://lists.webkit.org/mailman/listinfo/webkit-dev<br \
class=""></div></blockquote></div><br class=""></div></body></html>



_______________________________________________
webkit-dev mailing list
webkit-dev@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-dev


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic