Path: csiph.com!eternal-september.org!feeder.eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Tim Rentsch
Newsgroups: comp.lang.c
Subject: Re: Coding style for small if statements
Date: Sun, 16 Feb 2020 05:34:04 -0800
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <86sgjafygj.fsf@linuxsc.com>
References: <20200131234613.59047e037939ceb549b8e6d6@gmail.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: reader02.eternal-september.org; posting-host="5afe6ca82d77f883ab9def33834e0994"; logging-data="6778"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dCB5gXNFERPibRfe6VS+FDK091v1Qs8s="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:lpQWcAs6swaawXMWbhn0qEaGgvw= sha1:xBbU+V0M32RxQL0bQkFwGfELrV4=
Xref: csiph.com comp.lang.c:150046
Jorgen Grahn writes:
> On Fri, 2020-01-31, Anton Shepelev wrote:
>
>> Hello, all
>>
>> What do you think about the formatting and readability of
>> the following code of mine from a display-setup function for
>> the DOSBox emulator:
>>
>> if( dblh != dblw )
>> if( dblh ) gfx_flags |= GFX_DBL_H; else
>> gfx_flags |= GFX_DBL_W;
>
> ...
>
>> What are your opinions?
>
> My opinion is simple: I like and use a short, simple, one-line if:
>
> if (dblh) gfx_flags |= GFX_DBL_H;
I am curious. Would your criteria for shortness and simpleness
admit the whole ball of wax here as a single one-line statement:
if( dblh != dblw ) gfx_flags |= dblx ? GFX_DBL_H : GFX_DBL_H;
My own criteria for admitting a one-line 'if' include the question
"Does this make sense being read as a single line?", which probably
gets a Yes answer in this case. (The "probably" arises because
there may be other not-yet-known context that would bear on the
question.)
> but for anything more more complex, I want curly brackets
> and proper indentation.
Yeah. I might be willing to make an exception in some unusual
circumstances, but circumstances sufficiently unusual are few
and far between.