You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@subversion.apache.org by Daniel Shahaf <da...@elego.de> on 2013/04/04 23:17:50 UTC

Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Lieven Govaerts wrote on Thu, Apr 04, 2013 at 22:03:35 +0200:
> Hi Branko,
> 
> On Thu, Apr 4, 2013 at 8:59 PM, Branko Čibej <br...@wandisco.com> wrote:
> > On 04.04.2013 20:46, Lieven Govaerts wrote:
> >> On Thu, Apr 4, 2013 at 1:28 PM, Philip Martin
> >> <ph...@wandisco.com> wrote:
> >>> Lieven Govaerts <lg...@apache.org> writes:
> >>>
> >>>> On Thu, Apr 4, 2013 at 12:55 AM, philip@apache.org <ph...@apache.org> wrote:
> >>>>> Author: philip
> >>>>> Date: Wed Apr  3 22:55:37 2013
> >>>>> New Revision: 1464228
> >>>>>
> >>>>> URL: http://svn.apache.org/r1464228
> >>>>> Log:
> >>>>> Remove (void) casts of ignored return values from ra_serf.
> >>>>>
> >>>>> * subversion/libsvn_ra_serf/util.c
> >>>>>   (svn_ra_serf__conn_closed, svn_ra_serf__process_pending,
> >>>>>    svn_ra_serf__handle_xml_parser, svn_ra_serf__credentials_callback,
> >>>>>    svn_ra_serf__request_create, expat_start, expat_end,
> >>>>>    expat_cdata, expat_response_handler): Remove cast.
> >>>> What's the benefit of removing these casts? Is the purpose to consider
> >>>> these as warnings in order to solve them later?
> >>> We were not consistently casting to (void) when ignoring return values.
> >>> Branko objected when I added such a cast recently so I decided to remove
> >>> them all.
> >>>
> >>>>> Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
> >>>>> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1464228&r1=1464227&r2=1464228&view=diff
> >>>>> ==============================================================================
> >>>>> --- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
> >>>>> +++ subversion/trunk/subversion/libsvn_ra_serf/util.c Wed Apr  3 22:55:37 2013
> >>>>> @@ -497,7 +497,7 @@ svn_ra_serf__conn_closed(serf_connection
> >>>>>
> >>>>>    err = svn_error_trace(connection_closed(ra_conn, why, pool));
> >>>>>
> >>>>> -  (void) save_error(ra_conn->session, err);
> >>>>> +  save_error(ra_conn->session, err);
> >>>>>  }
> >>>>>
> >>>>>
> >>>>> @@ -1490,7 +1490,7 @@ svn_ra_serf__process_pending(svn_ra_serf
> >>>>>
> >>>>>        /* Tell the parser that no more content will be parsed. Ignore the
> >>>>>           return status. We just don't care.  */
> >>>>> -      (void) XML_Parse(parser->xmlp, NULL, 0, 1);
> >>>>> +      XML_Parse(parser->xmlp, NULL, 0, 1);
> >>>> This confuses me a bit. You leave the comment so I guess you agree
> >>>> with the decision to ignore the return value here, yet you remove the
> >>>> (void) cast which makes the same thing clear from the code.
> >>> If the (void) cast helps then we should be using it everywhere we ignore
> >>> a return value.
> >> Using (void) says the same thing as /* Ignore the return status. We
> >> just don't care. */ but in a more compact and precise manner.
> >> I see no reason to not use it, in those cases where we're absolutely
> >> sure the return value is not needed of course.
> >
> > Using (void) was invented to shut up Lint and its derivatives, back in
> > the day. It's ugly and unnecessary and doesn't tell the compiler
> > anything it doesn't already know. I see every reason not to use it -- it
> > clutters up the code in a way that distracts from the overall meaning.
> >
> 
> This is not about communication to the compiler, but to the person
> reading the code. It says that the original developer of that code
> knows that the function returns something, but that (s)he knowingly
> decide to ignore it.

For example, this implies we won't use (void) in front of printf()
calls (even if that would leave lint complaining).

FWIW, lgo's argument makes sense to me.  I see no reason to remove
(void) casts that make our code more readable because some other
codebases use them to silence lint.

Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by Greg Stein <gs...@gmail.com>.
On Apr 5, 2013 4:29 AM, "Daniel Shahaf" <da...@elego.de> wrote:
>
> Daniel Shahaf wrote on Fri, Apr 05, 2013 at 11:20:02 +0300:
> > Branko Čibej wrote on Fri, Apr 05, 2013 at 08:14:36 +0200:
> > > On 04.04.2013 23:17, Daniel Shahaf wrote:
> > > > FWIW, lgo's argument makes sense to me.  I see no reason to remove
> > > > (void) casts that make our code more readable because some other
> > > > codebases use them to silence lint.
> > >
> > > My point is that they do not make the code more readable. Moreover:
when
> > > someone does turn on the extra compiler options to find places where
> > > return values are ignored, the (void)-cast calls will not be flagged.
> ...
> > > Who's to guarantee that the original author who decided to ignore the
> > > return value and dropped the (void) tu^Wbreadcrumb was right?
> >
> > The bug here is ignoring the return value.  Whether the cast is present
> > or not is of secondary importance.
>
> Having the cast means two things:
>
> - It's easier for human readers to (a) see that there is a return value,
>   and (b) that said return value is being intentionally ignored.
>
> - It may suppress some ($CC, lint, ...) warnings.
>
> Whether it was actually correct to ignore the return value is simply
> independent of the syntax that was used to ignore it.

Agreed. I want to know if/when we are consciously dropping a value on the
floor. As a reader of the source.

Thx,
-g

Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by Branko Čibej <br...@wandisco.com>.
On 05.04.2013 16:20, C. Michael Pilato wrote:
> Guys, we're all overlooking the primary reason to explicitly include the
> "(void)":  it makes the function feel better.
>
> A function who works hard to do a job only to have some of that effort
> ignored could eventually develop issues with self-confidence, ultimately
> leading toward a lifestyle full of destructive habits.  Such functions are,
> as we know from experience in meatspace, rarely as productive as they could
> be, and soon become the unwilling targets of whispered dismissals about how
> much potential they once held.
>
> Nestled between two parentheticals, with no spaces to separate them (perish
> the thought!), that function instead feels the warmth and closelness of his
> soft-edged neighbors, the value of his purpose, and the assurance that while
> his return value was not needed -- in this instance, at least -- his effort
> is nevertheless recognized as having been exerted.  And that's comforting.
>
> Let's love our functions.
>
> (void)snuggle(you, me);
>
> -- C-Mike

Ah, a light dawns! And you're right, of course. Although I have to
wonder if a void snuggle is really up to dispelling that empty feeling
of loneliness on Friday night after a hard week at work.

So allow me to suggest we adopt C99 as the new baseline language
standard, so that we can write the above as:

#include <complex.h>
(complex)snuggle(...);

-- Brane

-- 
Branko Čibej
Director of Subversion | WANdisco | www.wandisco.com


Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by "C. Michael Pilato" <cm...@collab.net>.
Guys, we're all overlooking the primary reason to explicitly include the
"(void)":  it makes the function feel better.

A function who works hard to do a job only to have some of that effort
ignored could eventually develop issues with self-confidence, ultimately
leading toward a lifestyle full of destructive habits.  Such functions are,
as we know from experience in meatspace, rarely as productive as they could
be, and soon become the unwilling targets of whispered dismissals about how
much potential they once held.

Nestled between two parentheticals, with no spaces to separate them (perish
the thought!), that function instead feels the warmth and closelness of his
soft-edged neighbors, the value of his purpose, and the assurance that while
his return value was not needed -- in this instance, at least -- his effort
is nevertheless recognized as having been exerted.  And that's comforting.

Let's love our functions.

(void)snuggle(you, me);

-- C-Mike

-- 
C. Michael Pilato <cm...@collab.net>
CollabNet   <>   www.collab.net   <>   Enterprise Cloud Development


Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by Daniel Shahaf <da...@elego.de>.
Daniel Shahaf wrote on Fri, Apr 05, 2013 at 11:20:02 +0300:
> Branko Čibej wrote on Fri, Apr 05, 2013 at 08:14:36 +0200:
> > On 04.04.2013 23:17, Daniel Shahaf wrote:
> > > FWIW, lgo's argument makes sense to me.  I see no reason to remove
> > > (void) casts that make our code more readable because some other
> > > codebases use them to silence lint.
> > 
> > My point is that they do not make the code more readable. Moreover: when
> > someone does turn on the extra compiler options to find places where
> > return values are ignored, the (void)-cast calls will not be flagged.
...
> > Who's to guarantee that the original author who decided to ignore the
> > return value and dropped the (void) tu^Wbreadcrumb was right?
> 
> The bug here is ignoring the return value.  Whether the cast is present
> or not is of secondary importance.

Having the cast means two things:

- It's easier for human readers to (a) see that there is a return value,
  and (b) that said return value is being intentionally ignored.

- It may suppress some ($CC, lint, ...) warnings.

Whether it was actually correct to ignore the return value is simply
independent of the syntax that was used to ignore it.

Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by Daniel Shahaf <da...@elego.de>.
Branko Čibej wrote on Fri, Apr 05, 2013 at 08:14:36 +0200:
> On 04.04.2013 23:17, Daniel Shahaf wrote:
> > FWIW, lgo's argument makes sense to me.  I see no reason to remove
> > (void) casts that make our code more readable because some other
> > codebases use them to silence lint.
> 
> My point is that they do not make the code more readable. Moreover: when
> someone does turn on the extra compiler options to find places where
> return values are ignored, the (void)-cast calls will not be flagged.

That's not true under gcc 4.2 with warn_unused_result:

    static int f(void) __attribute__ ((warn_unused_result));
    static int f(void) { return 42; }
    
    int main(void)
    {
      (void) f();
      return 0;
    }

    % gcc main.c
    main.c: In function 'main':
    main.c:11: warning: ignoring return value of 'f', declared with attribute warn_unused_result

> Who's to guarantee that the original author who decided to ignore the
> return value and dropped the (void) tu^Wbreadcrumb was right?

The bug here is ignoring the return value.  Whether the cast is present
or not is of secondary importance.

> What if the semantics of the called function, or the calling code,
> changes in such a way that ignoring the return value is no longer
> valid?

Whoever made the incompatible API change to the callee should have
reviewed all callsites.

A change to the calling code that failed to stop ignoring the return
value is called "a change that introduced a bug".  (and, again, the bug
wouldn't become less of a bug if the cast-to-void syntax wasn't used)

> And to respond to Lieven: yes, I (unprintable) well do expect an
> explanation for dropping the return value to the floor in a comment, if
> it's not for a trivially obvious reason. The (void) cast only says "I'm
> ignoring the return value," which is hardly useful information since
> anyone can see that even without the cast. Which does not imply that
> each and every such statement in the code needs its own comment.

Agreed that a comment with the reason should be in place when the reason
isn't obvious.

Re: svn commit: r1464228 - in /subversion/trunk/subversion/libsvn_ra_serf: sb_bucket.c util.c

Posted by Branko Čibej <br...@wandisco.com>.
On 04.04.2013 23:17, Daniel Shahaf wrote:
> Lieven Govaerts wrote on Thu, Apr 04, 2013 at 22:03:35 +0200:
>> Hi Branko,
>>
>> On Thu, Apr 4, 2013 at 8:59 PM, Branko Čibej <br...@wandisco.com> wrote:
>>> On 04.04.2013 20:46, Lieven Govaerts wrote:
>>>> On Thu, Apr 4, 2013 at 1:28 PM, Philip Martin
>>>> <ph...@wandisco.com> wrote:
>>>>> Lieven Govaerts <lg...@apache.org> writes:
>>>>>
>>>>>> On Thu, Apr 4, 2013 at 12:55 AM, philip@apache.org <ph...@apache.org> wrote:
>>>>>>> Author: philip
>>>>>>> Date: Wed Apr  3 22:55:37 2013
>>>>>>> New Revision: 1464228
>>>>>>>
>>>>>>> URL: http://svn.apache.org/r1464228
>>>>>>> Log:
>>>>>>> Remove (void) casts of ignored return values from ra_serf.
>>>>>>>
>>>>>>> * subversion/libsvn_ra_serf/util.c
>>>>>>>   (svn_ra_serf__conn_closed, svn_ra_serf__process_pending,
>>>>>>>    svn_ra_serf__handle_xml_parser, svn_ra_serf__credentials_callback,
>>>>>>>    svn_ra_serf__request_create, expat_start, expat_end,
>>>>>>>    expat_cdata, expat_response_handler): Remove cast.
>>>>>> What's the benefit of removing these casts? Is the purpose to consider
>>>>>> these as warnings in order to solve them later?
>>>>> We were not consistently casting to (void) when ignoring return values.
>>>>> Branko objected when I added such a cast recently so I decided to remove
>>>>> them all.
>>>>>
>>>>>>> Modified: subversion/trunk/subversion/libsvn_ra_serf/util.c
>>>>>>> URL: http://svn.apache.org/viewvc/subversion/trunk/subversion/libsvn_ra_serf/util.c?rev=1464228&r1=1464227&r2=1464228&view=diff
>>>>>>> ==============================================================================
>>>>>>> --- subversion/trunk/subversion/libsvn_ra_serf/util.c (original)
>>>>>>> +++ subversion/trunk/subversion/libsvn_ra_serf/util.c Wed Apr  3 22:55:37 2013
>>>>>>> @@ -497,7 +497,7 @@ svn_ra_serf__conn_closed(serf_connection
>>>>>>>
>>>>>>>    err = svn_error_trace(connection_closed(ra_conn, why, pool));
>>>>>>>
>>>>>>> -  (void) save_error(ra_conn->session, err);
>>>>>>> +  save_error(ra_conn->session, err);
>>>>>>>  }
>>>>>>>
>>>>>>>
>>>>>>> @@ -1490,7 +1490,7 @@ svn_ra_serf__process_pending(svn_ra_serf
>>>>>>>
>>>>>>>        /* Tell the parser that no more content will be parsed. Ignore the
>>>>>>>           return status. We just don't care.  */
>>>>>>> -      (void) XML_Parse(parser->xmlp, NULL, 0, 1);
>>>>>>> +      XML_Parse(parser->xmlp, NULL, 0, 1);
>>>>>> This confuses me a bit. You leave the comment so I guess you agree
>>>>>> with the decision to ignore the return value here, yet you remove the
>>>>>> (void) cast which makes the same thing clear from the code.
>>>>> If the (void) cast helps then we should be using it everywhere we ignore
>>>>> a return value.
>>>> Using (void) says the same thing as /* Ignore the return status. We
>>>> just don't care. */ but in a more compact and precise manner.
>>>> I see no reason to not use it, in those cases where we're absolutely
>>>> sure the return value is not needed of course.
>>> Using (void) was invented to shut up Lint and its derivatives, back in
>>> the day. It's ugly and unnecessary and doesn't tell the compiler
>>> anything it doesn't already know. I see every reason not to use it -- it
>>> clutters up the code in a way that distracts from the overall meaning.
>>>
>> This is not about communication to the compiler, but to the person
>> reading the code. It says that the original developer of that code
>> knows that the function returns something, but that (s)he knowingly
>> decide to ignore it.
> For example, this implies we won't use (void) in front of printf()
> calls (even if that would leave lint complaining).

Well of course you won't, who on earth ever checks the return value of
printf()? In some rare cases you do, but not usually. Unlike, e.g.,
svn_cmdline_printf, which we /do/ check return values from.

> FWIW, lgo's argument makes sense to me.  I see no reason to remove
> (void) casts that make our code more readable because some other
> codebases use them to silence lint.

My point is that they do not make the code more readable. Moreover: when
someone does turn on the extra compiler options to find places where
return values are ignored, the (void)-cast calls will not be flagged.
Who's to guarantee that the original author who decided to ignore the
return value and dropped the (void) tu^Wbreadcrumb was right? What if
the semantics of the called function, or the calling code, changes in
such a way that ignoring the return value is no longer valid?

And to respond to Lieven: yes, I (unprintable) well do expect an
explanation for dropping the return value to the floor in a comment, if
it's not for a trivially obvious reason. The (void) cast only says "I'm
ignoring the return value," which is hardly useful information since
anyone can see that even without the cast. Which does not imply that
each and every such statement in the code needs its own comment.

-- Brane

-- 
Branko Čibej
Director of Subversion | WANdisco | www.wandisco.com