httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ruediger Pluem <rpl...@apache.org>
Subject Re: Coding style
Date Mon, 02 Oct 2006 21:35:03 GMT


On 10/02/2006 11:12 PM, Nick Kew wrote:
> On Monday 02 October 2006 21:39, Ruediger Pluem wrote:
> 
> 
>>In general I agree with the above, but there are situations were the old
>>style really makes sense, e.g (from log_child in server/log.c):
>>
>>if (((rc = apr_procattr_create(&procattr, p)) == APR_SUCCESS)
>>        && ((rc = apr_procattr_cmdtype_set(procattr,
>>                                           APR_SHELLCMD_ENV)) ==
>>APR_SUCCESS) && ((rc = apr_procattr_io_set(procattr,
>>                                      APR_FULL_BLOCK,
>>                                      APR_NO_PIPE,
>>                                      APR_NO_PIPE)) == APR_SUCCESS)
>>        && ((rc = apr_procattr_error_check_set(procattr, 1)) ==
>>APR_SUCCESS) && ((rc = apr_procattr_child_errfn_set(procattr,
>>log_child_errfn)) == APR_SUCCESS)) {
> 
> 
> Now that is true bug-heaven.  If we accept your premise that a complex
> if (...) is better than the alternatives, then a comma-list is much less
> bug-prone:
> 
>   if ((rc = apr_procattr_create(&procattr, p), rc == APR_SUCCESS)
>     && (rc = apr_procattr_cmdtype_set(procattr, APR_SHELLCMD_ENV),
> 		rc == APR_SUCCESS)
>     && (rc = apr_procattr_io_set(procattr, APR_FULL_BLOCK,
>                                                    APR_NO_PIPE, APR_NO_PIPE),
> 		rc == APR_SUCCESS)
>     && (rc = apr_procattr_error_check_set(procattr, 1), rc == APR_SUCCESS)
>     && (rc = apr_procattr_child_errfn_set(procattr, log_child_errfn),
> 		rc == APR_SUCCESS)) {
> 
> (Not sure how that'll look in terms of wrap and whitespace -
> this is a mailer, not a program editor.  But you get the point).

Ok. Point taken. So I guess the best thing for simple if (...) is Garrett's
proposal (put the function call *before* if in a separate line). For more
complex things like the thing above (provided that we want to allow this at all)
the comma-list is better.

Regards

RĂ¼diger



Mime
View raw message