[Info-vax] Style question, was: Re: Empty blocks in FILES-11 directory files.
Arne Vajhøj
arne at vajhoej.dk
Tue Sep 27 15:19:13 EDT 2022
On 9/27/2022 1:56 PM, Simon Clubley wrote:
> On 2022-09-25, Mark Daniel <mark.daniel at wasd.vsm.com.au> wrote:
>>
>> odsptr->Rab.rab$l_ubf = odsptr->DataPtr;
>> for (;;)
>> {
>> if (SizeInBytes > 512*127)
>> odsptr->Rab.rab$w_usz = 512*127;
>> else
>> if (SizeInBytes > 0)
>> odsptr->Rab.rab$w_usz = SizeInBytes;
>> else
>> break;
>>
>
> I have a style question about this part of Mark's code and was wondering
> if this was a common style, or if you always made liberal use of braces
> to help draw attention to the nesting going on here and to help avoid
> some later editing mistakes.
>
> For example, I would write this code section as something like this:
>
> if (SizeInBytes > 512*127)
> {
> odsptr->Rab.rab$w_usz = 512*127;
> }
> else
> {
> if (SizeInBytes > 0)
> {
> odsptr->Rab.rab$w_usz = SizeInBytes;
> }
> else
> {
> break;
> }
> }
>
> (and yes, wrapping single statements in braces is also deliberate here.)
>
> For me, I find the liberal use of braces helps to draw attention to the
> code structure, is more readable in general (at least to me), and helps
> avoid some mistakes during later editing.
>
> Just wondering which is the more common style in the C code you have seen.
For both whether to use block construct for single statement and
for indentation style the right answer is whatever style is agreed on
in the project.
:-)
If I were in the project meeting discussing these topics then I would
argue for using block construct for single statements.
But honestly then I sometimes I forget myself.
Arne
PS: For braces I would vote Allman for C/C++, but different for other
languages.
More information about the Info-vax
mailing list