[webkit-dev] Code Style: Opinion on returning void
Keith Miller
keith_miller at apple.com
Wed Feb 13 10:02:13 PST 2019
I’ve definitely done this in JSC before. As with everyone else, I don’t feel particularly strongly about it.
> On Feb 7, 2019, at 8:45 PM, Chris Dumez <cdumez at apple.com> wrote:
>
> Same here, I used it in PSON code with completion handlers. I liked the more concise code but I also do not feel strongly about it.
>
> The extra return line often would have meant adding curly brackets for if statements leading to early returns.
IMO, this is why I think all if/elses should have curlies that way I don’t have to think about whether or not I need them, but ¯\_(ツ)_/¯. It would also make refactoring code much easier.
>
> Chris Dumez
>
> On Feb 7, 2019, at 8:23 PM, Zalan Bujtas <zbujtas at gmail.com <mailto:zbujtas at gmail.com>> wrote:
>
>> 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)
>>
>> Alan.
>>
>>
>> On Thu, Feb 7, 2019 at 7:31 PM Alex Christensen <achristensen at apple.com <mailto:achristensen at apple.com>> wrote:
>> 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 <mailto: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 <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();
>> >> }
>> >>
>> >> 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 <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 <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
> https://lists.webkit.org/mailman/listinfo/webkit-dev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20190213/27390f32/attachment.html>
More information about the webkit-dev
mailing list