| Deutsch English Français Italiano |
|
<vq785i$1u7v7$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail
From: bart <bc@freeuk.com>
Newsgroups: comp.lang.c
Subject: Re: Which code style do you prefer the most?
Date: Tue, 4 Mar 2025 16:01:54 +0000
Organization: A noiseless patient Spider
Lines: 78
Message-ID: <vq785i$1u7v7$1@dont-email.me>
References: <vpkmq0$21php$1@dont-email.me>
<20250304175602.c9fe683d678d3a2ed101a4ac@g{oogle}mail.com>
<vq75k8$1t6ut$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 04 Mar 2025 17:01:54 +0100 (CET)
Injection-Info: dont-email.me; posting-host="3a66dca0b51e8281c40f90343694f6ac";
logging-data="2039783"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Do2o4pATIUogkx8E7el65"
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5kSY+DvgG2CPi8j2n+TXTZACW7c=
Content-Language: en-GB
In-Reply-To: <vq75k8$1t6ut$2@dont-email.me>
On 04/03/2025 15:18, Richard Heathfield wrote:
> On 04/03/2025 14:56, Anton Shepelev wrote:
>> Ar Rakin:
>>
>>> I've been writing C code for a long time, in different styles, but
>>> always wanted to know which code style most people prefer. This is all
>>> about that question. Which one of the following do you prefer the most?
>>
>>> 1. GNU Style
>>> 2. Linux Style
>>
>> I don't like them much. Below is a piece of my code
>
> I don't like most of the choices you've made :-) *but* I can see
> perfectly good reasons for making those choices (if that's any
> consolation).
>
> Just about the only choice of yours that I /do/ like is your brace
> placement:
>
> {
> {
> {
> }
> }
> }
>
> which like because it makes the code's structure stand out so clearly.
> I know a lot of people criticise this style for being wasteful of
> vertical space, but I've never seen that as a problem. My screen can
> hold more than enough code to occupy me, and my annual vertical space
> bill is very reasonable.
>
I assume that style would be used like this:
if (cond)
{
stmt1;
}
else
{
stmt2;
}
So 50% of lines are solely for braces, with braces not having their own
indent level. However if I now look at AS's post, that isn't it: opening
braces don't have their own dedicated line, they are shared with the
first line of the block:
if (cond)
{ stmt1;
}
else
{ stmt2;
}
This cuts down the line count, but now the first line is a special case:
it's got that extra clutter at the start, makes it harder to swap with
other lines, to temporarily comment out, to delete, or to add extra,
perhaps debugging, lines at the start of the block.
The style I use for generated code is like this:
if (cond) {
stmt1;
}
else {
stmt2;
}
The same amount of vertical space, but none of those problems. So this
is superior IMV.
(That is, when you have to use braces; generally I don't like that style
of syntax *because* there are so many placement styles: there are
multiple ways of writing the three tokens of '} else {'; not so many if
it's just the single token 'else'.)