Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Even if you're on the right track, you'll get run over if you just sit there." -- Will Rogers


devel / comp.lang.c / Re: Do you insist on const-correctness?

SubjectAuthor
* Do you insist on const-correctness?Anton Shepelev
+- Re: Do you insist on const-correctness?Anton Shepelev
+* Re: Do you insist on const-correctness?Ben Bacarisse
|`* Re: Do you insist on const-correctness?Anton Shepelev
| +* Re: Do you insist on const-correctness?David Brown
| |`* Re: Do you insist on const-correctness?David Brown
| | `* Re: Do you insist on const-correctness?comp.lang.c
| |  `* Re: Do you insist on const-correctness?David Brown
| |   +* Re: Do you insist on const-correctness?Keith Thompson
| |   |`- Re: Do you insist on const-correctness?Chris M. Thomasson
| |   +- Re: Do you insist on const-correctness?Scott Lurndal
| |   +* Re: Do you insist on const-correctness?David Brown
| |   |`- Re: Do you insist on const-correctness?Chris M. Thomasson
| |   `- Re: Do you insist on const-correctness?Keith Thompson
| `* Re: Do you insist on const-correctness?Ben Bacarisse
|  `- Re: Do you insist on const-correctness?Anton Shepelev
+* Re: Do you insist on const-correctness?Tim Rentsch
|`* Re: Do you insist on const-correctness?Anton Shepelev
| +* Re: Do you insist on const-correctness?David Brown
| |+* Re: Do you insist on const-correctness?Scott Lurndal
| ||+* Re: Do you insist on const-correctness?Kaz Kylheku
| |||`* Re: Do you insist on const-correctness?Bart
| ||| +* Re: Do you insist on const-correctness?Kaz Kylheku
| ||| |`* Re: Do you insist on const-correctness?Bart
| ||| | +- Re: Do you insist on const-correctness?Chris M. Thomasson
| ||| | +- Re: Do you insist on const-correctness?Kaz Kylheku
| ||| | +- Re: Do you insist on const-correctness?Keith Thompson
| ||| | `- Re: Do you insist on const-correctness?David Brown
| ||| +* Re: Do you insist on const-correctness?David Brown
| ||| |`* Re: Do you insist on const-correctness?Bart
| ||| | +- Re: Do you insist on const-correctness?Ben Bacarisse
| ||| | +- Re: Do you insist on const-correctness?Keith Thompson
| ||| | +* Re: Do you insist on const-correctness?Kaz Kylheku
| ||| | |`* Re: Do you insist on const-correctness?Chris M. Thomasson
| ||| | | `* Re: Do you insist on const-correctness?Keith Thompson
| ||| | |  `* Re: Do you insist on const-correctness?Chris M. Thomasson
| ||| | |   `* Re: Do you insist on const-correctness?Keith Thompson
| ||| | |    `- Re: Do you insist on const-correctness?Chris M. Thomasson
| ||| | `* Re: Do you insist on const-correctness?David Brown
| ||| |  `* Re: Do you insist on const-correctness?Bart
| ||| |   `* Re: Do you insist on const-correctness?David Brown
| ||| |    `* Re: Do you insist on const-correctness?Bart
| ||| |     +- Re: Do you insist on const-correctness?Keith Thompson
| ||| |     +- Re: Do you insist on const-correctness?Kaz Kylheku
| ||| |     `- Re: Do you insist on const-correctness?David Brown
| ||| +- Re: Do you insist on const-correctness?Keith Thompson
| ||| `* Re: Do you insist on const-correctness?James Kuyper
| |||  `* Re: Do you insist on const-correctness?Bart
| |||   `* Re: Do you insist on const-correctness?David Brown
| |||    `* Re: Do you insist on const-correctness?Kaz Kylheku
| |||     `- Re: Do you insist on const-correctness?Chris M. Thomasson
| ||`* Re: Do you insist on const-correctness?David Brown
| || `* Re: Do you insist on const-correctness?Chris M. Thomasson
| ||  `* Re: Do you insist on const-correctness?Chris M. Thomasson
| ||   `* Re: Do you insist on const-correctness?Ben Bacarisse
| ||    `* Re: Do you insist on const-correctness?Chris M. Thomasson
| ||     `* Re: Do you insist on const-correctness?Ben Bacarisse
| ||      `- Re: Do you insist on const-correctness?Chris M. Thomasson
| |+* Re: Do you insist on const-correctness?Kaz Kylheku
| ||`* Re: Do you insist on const-correctness?David Brown
| || `* Re: Do you insist on const-correctness?Anton Shepelev
| ||  `* Re: Do you insist on const-correctness?David Brown
| ||   `* Re: Do you insist on const-correctness?Anton Shepelev
| ||    `- Re: Do you insist on const-correctness?David Brown
| |`* Re: Do you insist on const-correctness?Anton Shepelev
| | +- Re: Do you insist on const-correctness?Bart
| | +- Re: Do you insist on const-correctness?Richard Damon
| | +* Re: Do you insist on const-correctness?Scott Lurndal
| | |`- Re: Do you insist on const-correctness?Anton Shepelev
| | `* Re: Do you insist on const-correctness?David Brown
| |  +* Re: Do you insist on const-correctness?Bart
| |  |`* Re: Do you insist on const-correctness?David Brown
| |  | `* Re: Do you insist on const-correctness?Bart
| |  |  +* Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  |`* Re: Do you insist on const-correctness?Bart
| |  |  | +* Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  | |`- Re: Do you insist on const-correctness?Bart
| |  |  | +* Re: Do you insist on const-correctness?David Brown
| |  |  | |`* Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  | | +- Re: Do you insist on const-correctness?Kaz Kylheku
| |  |  | | `* Re: Do you insist on const-correctness?David Brown
| |  |  | |  `* Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  | |   `- Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  | `* Re: Do you insist on const-correctness?Anton Shepelev
| |  |  |  +* Re: Do you insist on const-correctness?Anton Shepelev
| |  |  |  |`- Re: Do you insist on const-correctness?David Brown
| |  |  |  +- Re: Do you insist on const-correctness?Bart
| |  |  |  +* Re: Do you insist on const-correctness?Dan Cross
| |  |  |  |`* Re: Do you insist on const-correctness?Anton Shepelev
| |  |  |  | `* Re: Do you insist on const-correctness?Dan Cross
| |  |  |  |  `* Re: Do you insist on const-correctness?Scott Lurndal
| |  |  |  |   `- Re: Do you insist on const-correctness?Dan Cross
| |  |  |  `* Re: Do you insist on const-correctness?David Brown
| |  |  |   +* Re: Do you insist on const-correctness?Bart
| |  |  |   |+* Re: Do you insist on const-correctness?Kaz Kylheku
| |  |  |   ||+* Re: Do you insist on const-correctness?Bart
| |  |  |   |||`* Re: Do you insist on const-correctness?David Brown
| |  |  |   ||| +- Re: Do you insist on const-correctness?Anton Shepelev
| |  |  |   ||| `* Re: Do you insist on const-correctness?Bart
| |  |  |   |||  `* Re: Do you insist on const-correctness?David Brown
| |  |  |   |||   `* Re: Do you insist on const-correctness?Ben Bacarisse
| |  |  |   ||`* Re: Do you insist on const-correctness?David Brown
| |  |  |   |`- Re: Do you insist on const-correctness?David Brown
| |  |  |   +* Re: Do you insist on const-correctness?Anton Shepelev
| |  |  |   +* Re: Do you insist on const-correctness?David Brown
| |  |  |   `- Re: Do you insist on const-correctness?Chris M. Thomasson
| |  |  `- Re: Do you insist on const-correctness?David Brown
| |  `* Re: Do you insist on const-correctness?Anton Shepelev
| `* Re: Do you insist on const-correctness?Tim Rentsch
+* Re: Do you insist on const-correctness?Kaz Kylheku
`- Re: Do you insist on const-correctness?Tim Rentsch

Pages:12345678
Re: Do you insist on const-correctness?

<uerguk$1qrj9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29260&group=comp.lang.c#29260

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 10:38:44 +0200
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uerguk$1qrj9$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me> <20230918095305.817@kylheku.com>
<uebnuo$296h8$1@dont-email.me>
<20230923170155.03ab65af4938de3b9c1e7008@gmail.moc>
<uemt48$qssi$1@dont-email.me>
<20230923191325.5e24840b4e13d321f7172551@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 25 Sep 2023 08:38:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0c1edba901eb86494cfd491da435748b";
logging-data="1928809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+iNEAFs4oaeoWaupBKQEuCZ81+aUJ4V9Y="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:dVS3WfhS6vcnXNf4ppSjxEqm4xE=
Content-Language: en-GB
In-Reply-To: <20230923191325.5e24840b4e13d321f7172551@gmail.moc>
 by: David Brown - Mon, 25 Sep 2023 08:38 UTC

On 23/09/2023 18:13, Anton Shepelev wrote:
> David Brown:
>
>> I made a post with multiple reasons why I personally think
>> it is a bad choice -- if you have the opportunity, I think
>> it would be interesting to hear why you think differently.
>> You could add to that list your reasons why you think
>> being able to write C90 code is a good thing. (I'm not
>> saying you are wrong, merely that your preferences are
>> different, and I am curious as to why.)
>
> Yes, I remembered it. Answered five or so minutes ago, but
> (I fear) not to your satisfaction...
>

It was certainly to my satisfaction - I was looking for your reasons for
your choices, not for agreement with /my/ reasons for /my/ choices, and
that's what you gave. (Of course, I'd also be quite happy if you read
my post and changed your mind to agree with me :-) )

Re: Do you insist on const-correctness?

<ueronc$1sd54$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29261&group=comp.lang.c#29261

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 11:51:23 +0100
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <ueronc$1sd54$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 10:51:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6fd42fafa9356a4d258b961b478e0ed6";
logging-data="1979556"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18C0XWjw1KVYNNggytnPB9sVPJylytSjlc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:yvXm5jB+tw1MNGMdDBBbnZRc+Xg=
In-Reply-To: <uera6l$1pr35$1@dont-email.me>
 by: Bart - Mon, 25 Sep 2023 10:51 UTC

On 25/09/2023 07:43, David Brown wrote:
> On 23/09/2023 18:05, Anton Shepelev wrote:

>>    2.  Upon encountering a new variable, the reader can
>>        glance at the top of function to find its type and
>>        desctiption, whereas intermixed style is requires
>>        scanning the entire text, unless, of course, you count
>>        IDE helper tools, which I do not.  Code should read
>>        smooth off a printed page.
>
> No, you are completely wrong here.
>
> With your style, the reader encountering a new variable has to deal with
> two wildly separate parts of the text - the definition at the start of
> the function, and the use of the variable in the code.  It is particular
> bad for large functions or when you have a small screen or window (this
> can be the case when you are debugging, for example), and you have to
> scroll around.

I've spent a few days working with C codebases where I have exactly that
problem: figuring out the details of a typedef, struct, enum, global
variable, function or macro, used in a function, which might be declared
not only 100s or 1000s of lines earlier, but in one of a dozen include
files.

So yes, that happens anyway, but on a big scale. I wish it WAS only at
the start of function that I have to look!

To go back to one of the points I made in those links: suppose I define
a typedef say at module scope to be shared by functions 35, 62 and 78 of
100 functions in that module.

Where should I place that typedef: before the definition of function 1,
or immediately before function 35 since that is where it is first used?

Because I rarely see functions, global variables and typedefs mixed up
like that. Maybe it's the next big thing.

Anyway, it is that segregation that I like to see within a function too.

Re: Do you insist on const-correctness?

<ues2jo$1uh7s$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29263&group=comp.lang.c#29263

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 15:40:07 +0200
Organization: A noiseless patient Spider
Lines: 108
Message-ID: <ues2jo$1uh7s$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 13:40:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0c1edba901eb86494cfd491da435748b";
logging-data="2049276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/9+yJfh8BhcJQ5bkbkh77tmDfUYA3qQYk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:XDn6fTjzVzDrVbsVU3jlucXq9qs=
Content-Language: en-GB
In-Reply-To: <ueronc$1sd54$1@dont-email.me>
 by: David Brown - Mon, 25 Sep 2023 13:40 UTC

On 25/09/2023 12:51, Bart wrote:
> On 25/09/2023 07:43, David Brown wrote:
>> On 23/09/2023 18:05, Anton Shepelev wrote:
>
>>>    2.  Upon encountering a new variable, the reader can
>>>        glance at the top of function to find its type and
>>>        desctiption, whereas intermixed style is requires
>>>        scanning the entire text, unless, of course, you count
>>>        IDE helper tools, which I do not.  Code should read
>>>        smooth off a printed page.
>>
>> No, you are completely wrong here.
>>
>> With your style, the reader encountering a new variable has to deal
>> with two wildly separate parts of the text - the definition at the
>> start of the function, and the use of the variable in the code.  It is
>> particular bad for large functions or when you have a small screen or
>> window (this can be the case when you are debugging, for example), and
>> you have to scroll around.
>
> I've spent a few days working with C codebases where I have exactly that
> problem: figuring out the details of a typedef, struct, enum, global
> variable, function or macro, used in a function, which might be declared
> not only 100s or 1000s of lines earlier, but in one of a dozen include
> files.
>
> So yes, that happens anyway, but on a big scale. I wish it WAS only at
> the start of function that I have to look!

In all code, beyond "Hello, world!" programs, you will need to look in
different parts of the code base when you need more details. There is
no escape from that, in any language.

So you have to do what you can to reduce the effort involved here. (And
not everyone is good at that - please do not blame /me/ for sub-optimal
code organisations in some project you have found.)

Putting your local variable definitions at the point where they have an
initial value, preferably keeping them const, and using minimal
reasonable scopes, will all reduce this effort.

But that is only part of the picture. Use clear header files containing
only the code necessary, with corresponding implementation files that
make everything "static" unless the variable/const/function is
"exported" in the header file. Divide the code into multiple files, in
logical partitions. Use multiple source directories if the project is
big enough. Use good names for everything - files, types, functions,
data, etc. Smaller scope items can have shorter names, bigger scope
items need more descriptive names. Use the best tools you can get hold
of - use good IDE's or editors. Document the code as well as you
reasonably can, based on appropriate needs for the project. Preferably
this should involve automated code documentation tools like doxygen to
minimise the risk of code and documentation mismatches, to reduce the
effort involved in the documentation (writing documentation is rarely
the fun part of development!), and to generate caller/callee/include
graphs, cross-references, etc. Keep a good structure and clean
interfaces at all levels - divide and conquer.

(Using good tools almost invariably means using well established
languages - not necessarily C, but not obscure or rare languages.)

So I don't in any way claim that using proper local variables, defined
when they are used, solves all software development challenges. But it
is /part/ of the solution.

>
> To go back to one of the points I made in those links:

(I haven't read your links.)

> suppose I define
> a typedef say at module scope to be shared by functions 35, 62 and 78 of
> 100 functions in that module.
>
> Where should I place that typedef: before the definition of function 1,
> or immediately before function 35 since that is where it is first used?
>

That's a stupid question. Don't have 100 functions in your module.

In your 20 function module, if your typedef is used in functions 3, 9
and 17, then it's worth considering if the order of functions in the
module makes sense. Assuming it does, then common practice would likely
be placing it near the start of the module. (If the type is part of the
interface to exported code or data, then of course it must be placed in
the header file.)

> Because I rarely see functions, global variables and typedefs mixed up
> like that. Maybe it's the next big thing.
>

"global variables" - variables that are exported from a module - should
be declared in a header file, and are usually then defined at the start
of the implementation file. (Generally, heavy use of global variables
is frowned upon - they can give too tight coupling between different
modules.) Static file-scope data is often defined near the start of a
module, though I am quite happy to define it just before the functions
that use it, especially if there are only one or two and it is
effectively local state for the implementation.

> Anyway, it is that segregation that I like to see within a function too.

I know you do. You and Anton are far from alone in this. But I think
you both write poorer code because of it. (And if you disagree with the
reasons I gave, fair enough - it's your code, not mine.)

Re: Do you insist on const-correctness?

<ueshl5$21lmm$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29265&group=comp.lang.c#29265

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 18:56:53 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <ueshl5$21lmm$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 17:56:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6fd42fafa9356a4d258b961b478e0ed6";
logging-data="2152150"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18JNNNJbRmjgv4TxZbmm6Yng30IGFTxJuo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:/FFssyE0TjN7mbNO1V7s/+CWWSU=
In-Reply-To: <ues2jo$1uh7s$1@dont-email.me>
 by: Bart - Mon, 25 Sep 2023 17:56 UTC

On 25/09/2023 14:40, David Brown wrote:
> On 25/09/2023 12:51, Bart wrote:

>> suppose I define a typedef say at module scope to be shared by
>> functions 35, 62 and 78 of 100 functions in that module.
>>
>> Where should I place that typedef: before the definition of function
>> 1, or immediately before function 35 since that is where it is first
>> used?
>>
>
> That's a stupid question.  Don't have 100 functions in your module.

Huh? I didn't realise that was that controversial. I don't actually know
how many functions I have per module, I've never counted!

But I've counted now, and my projects have 20-40 functions/module on
average. Library modules tend to have more (up to 100), and maximum was
220 functions in one file (handler functions for bytecode, and similar
modules where there is some sort of N-way dispatch going on).

Among C projects (not mine), the first couple I tried were 33 functions
average, 100 max (Lua), and 26 average/200 max (BBX).

LibJPEG averaged 9, but that also uses 70 files for a JPEG-handling
library, so it's rather spread out. You can implement JPEG encoders and
decoders in about one 1Kloc file each.

BTW sql.c (one-file sqlite3.c plus enough code to make a working app),
had 2300 functions on one file, with one of those functions being 7000
lines.

> In your 20 function module

So 20 is reasonable but not 100? OK.

I am aware of the line counts of my modules, and those probably average
1000 lines per module, with a max of 3-5Kloc.

I really don't think it's that critical. Is there a limit on how many
entries in one database before you have to split it up? Or how many
files in one folder? The entries belong together!

Re: Do you insist on const-correctness?

<uesi26$21hbl$7@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29266&group=comp.lang.c#29266

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 11:03:50 -0700
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <uesi26$21hbl$7@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 18:03:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="29c8ca5014253eb1ad25f97759b1defd";
logging-data="2147701"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19y29VdGY6GkofJeuC4rJ8ImJY2tXn0xcI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:cuL4CqfXTM+4EvpyIYunZPx+D4Y=
In-Reply-To: <ueshl5$21lmm$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 25 Sep 2023 18:03 UTC

On 9/25/2023 10:56 AM, Bart wrote:
> On 25/09/2023 14:40, David Brown wrote:
>> On 25/09/2023 12:51, Bart wrote:
>
>>> suppose I define a typedef say at module scope to be shared by
>>> functions 35, 62 and 78 of 100 functions in that module.
>>>
>>> Where should I place that typedef: before the definition of function
>>> 1, or immediately before function 35 since that is where it is first
>>> used?
>>>
>>
>> That's a stupid question.  Don't have 100 functions in your module.
>
> Huh? I didn't realise that was that controversial. I don't actually know
> how many functions I have per module, I've never counted!

I think there is a complexity rule is MISRA that talks about this...

>
> But I've counted now, and my projects have 20-40 functions/module on
> average. Library modules tend to have more (up to 100), and maximum was
> 220 functions in one file (handler functions for bytecode, and similar
> modules where there is some sort of N-way dispatch going on).
>
> Among C projects (not mine), the first couple I tried were 33 functions
> average, 100 max (Lua), and 26 average/200 max (BBX).
>
> LibJPEG averaged 9, but that also uses 70 files for a JPEG-handling
> library, so it's rather spread out. You can implement JPEG encoders and
> decoders in about one 1Kloc file each.
>
> BTW sql.c (one-file sqlite3.c plus enough code to make a working app),
> had 2300 functions on one file, with one of those functions being 7000
> lines.
>
>> In your 20 function module
>
> So 20 is reasonable but not 100? OK.
>
> I am aware of the line counts of my modules, and those probably average
> 1000 lines per module, with a max of 3-5Kloc.
>
> I really don't think it's that critical. Is there a limit on how many
> entries in one database before you have to split it up? Or how many
> files in one folder? The entries belong together!
>

Re: Do you insist on const-correctness?

<ueskug$22af7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29268&group=comp.lang.c#29268

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 19:53:03 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <ueskug$22af7$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 18:53:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6fd42fafa9356a4d258b961b478e0ed6";
logging-data="2173415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19223XDEOb+6+6NAgu2g8r56CuOXXDpWGY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:ToE8rzujRKK10/UcrWVPbATja+w=
In-Reply-To: <uesi26$21hbl$7@dont-email.me>
 by: Bart - Mon, 25 Sep 2023 18:53 UTC

On 25/09/2023 19:03, Chris M. Thomasson wrote:
> On 9/25/2023 10:56 AM, Bart wrote:
>> On 25/09/2023 14:40, David Brown wrote:
>>> On 25/09/2023 12:51, Bart wrote:
>>
>>>> suppose I define a typedef say at module scope to be shared by
>>>> functions 35, 62 and 78 of 100 functions in that module.
>>>>
>>>> Where should I place that typedef: before the definition of function
>>>> 1, or immediately before function 35 since that is where it is first
>>>> used?
>>>>
>>>
>>> That's a stupid question.  Don't have 100 functions in your module.
>>
>> Huh? I didn't realise that was that controversial. I don't actually
>> know how many functions I have per module, I've never counted!
>
> I think there is a complexity rule is MISRA that talks about this...

Are there are also rules about how many lines in a function, and how
many modules in a program?

Minimising one will increase the number of functions, and minimising the
number of functions per module will increase the number of modules.

Further, there will be more complexity due to interactions or interfaces
between functions and between modules being exposed, that could have
been kept private.

Re: Do you insist on const-correctness?

<uesl39$22ard$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29269&group=comp.lang.c#29269

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 11:55:37 -0700
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <uesl39$22ard$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 18:55:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="29c8ca5014253eb1ad25f97759b1defd";
logging-data="2173805"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18GRcd0Q5HHTSevvC2CcLT053t1CDIYrUI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:ctqshOCnFqroMJn7XbpO6anFQhU=
Content-Language: en-US
In-Reply-To: <ueskug$22af7$1@dont-email.me>
 by: Chris M. Thomasson - Mon, 25 Sep 2023 18:55 UTC

On 9/25/2023 11:53 AM, Bart wrote:
> On 25/09/2023 19:03, Chris M. Thomasson wrote:
>> On 9/25/2023 10:56 AM, Bart wrote:
>>> On 25/09/2023 14:40, David Brown wrote:
>>>> On 25/09/2023 12:51, Bart wrote:
>>>
>>>>> suppose I define a typedef say at module scope to be shared by
>>>>> functions 35, 62 and 78 of 100 functions in that module.
>>>>>
>>>>> Where should I place that typedef: before the definition of
>>>>> function 1, or immediately before function 35 since that is where
>>>>> it is first used?
>>>>>
>>>>
>>>> That's a stupid question.  Don't have 100 functions in your module.
>>>
>>> Huh? I didn't realise that was that controversial. I don't actually
>>> know how many functions I have per module, I've never counted!
>>
>> I think there is a complexity rule is MISRA that talks about this...
>
> Are there are also rules about how many lines in a function, and how
> many modules in a program?
>
> Minimising one will increase the number of functions, and minimising the
> number of functions per module will increase the number of modules.
>
> Further, there will be more complexity due to interactions or interfaces
> between functions and between modules being exposed, that could have
> been kept private.

Fwiw, here the documentation that I am referring to:

https://www.stroustrup.com/JSF-AV-rules.pdf

Re: Do you insist on const-correctness?

<ueslrg$22af7$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29270&group=comp.lang.c#29270

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 20:08:32 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <ueslrg$22af7$2@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<uesl39$22ard$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 19:08:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6fd42fafa9356a4d258b961b478e0ed6";
logging-data="2173415"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/0yTrQ+EyJbVBKlGu4n4mik/QZPoB4zsc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:OtHffkygv1kz+YZ1pRG5uELwTHA=
In-Reply-To: <uesl39$22ard$1@dont-email.me>
 by: Bart - Mon, 25 Sep 2023 19:08 UTC

On 25/09/2023 19:55, Chris M. Thomasson wrote:
> On 9/25/2023 11:53 AM, Bart wrote:
>> On 25/09/2023 19:03, Chris M. Thomasson wrote:
>>> On 9/25/2023 10:56 AM, Bart wrote:
>>>> On 25/09/2023 14:40, David Brown wrote:
>>>>> On 25/09/2023 12:51, Bart wrote:
>>>>
>>>>>> suppose I define a typedef say at module scope to be shared by
>>>>>> functions 35, 62 and 78 of 100 functions in that module.
>>>>>>
>>>>>> Where should I place that typedef: before the definition of
>>>>>> function 1, or immediately before function 35 since that is where
>>>>>> it is first used?
>>>>>>
>>>>>
>>>>> That's a stupid question.  Don't have 100 functions in your module.
>>>>
>>>> Huh? I didn't realise that was that controversial. I don't actually
>>>> know how many functions I have per module, I've never counted!
>>>
>>> I think there is a complexity rule is MISRA that talks about this...
>>
>> Are there are also rules about how many lines in a function, and how
>> many modules in a program?
>>
>> Minimising one will increase the number of functions, and minimising
>> the number of functions per module will increase the number of modules.
>>
>> Further, there will be more complexity due to interactions or
>> interfaces between functions and between modules being exposed, that
>> could have been kept private.
>
> Fwiw, here the documentation that I am referring to:
>
> https://www.stroustrup.com/JSF-AV-rules.pdf

That paragraph is in danger of breaching its own rule.

Look at this line from Lua sources:

luaC_barrier(L, clCvalue(s2v(L->ci->func.p)), fr);

(It's of dozens of instances causing problem for my compiler.)

It'a part of function of only 9 lines. It all seems simple enough. But
exactly is it doing?

It turns out those are macros not functions. A preprocessed version of
that line is:

((((fr)->tt_)&(1<<6))?(((((((&((((union
GCUnion*)(((((&(L->ci->func.p)->val))->value_).gc))))->cl.c))))->marked)&((1<<(5))))&&((((((fr)->value_).gc))->marked)&(((1<<(3))|(1<<(4))))))?luaC_barrier_(L,(&(((union
GCUnion*)((((&((((union
GCUnion*)(((((&(L->ci->func.p)->val))->value_).gc))))->cl.c))))))->gc)),(&(((union
GCUnion*)(((((fr)->value_).gc))))->gc))):((void)((0)))):((void)((0))));

This what *I* call complex, even though it is only one line.

Re: Do you insist on const-correctness?

<uesm9l$22hlu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29271&group=comp.lang.c#29271

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 21:16:05 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uesm9l$22hlu$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 19:16:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="23834f7a64e7444316f6177402897f57";
logging-data="2180798"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ih1B8RnISVf0fQLS8BVm+quXNzpUv3mc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:4x2LZ1ybcEH/wMwqJy81mMeVP2k=
In-Reply-To: <ueshl5$21lmm$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Mon, 25 Sep 2023 19:16 UTC

On 25/09/2023 19:56, Bart wrote:
> On 25/09/2023 14:40, David Brown wrote:
>> On 25/09/2023 12:51, Bart wrote:
>
>>> suppose I define a typedef say at module scope to be shared by
>>> functions 35, 62 and 78 of 100 functions in that module.
>>>
>>> Where should I place that typedef: before the definition of function
>>> 1, or immediately before function 35 since that is where it is first
>>> used?
>>>
>>
>> That's a stupid question.  Don't have 100 functions in your module.
>
> Huh? I didn't realise that was that controversial. I don't actually know
> how many functions I have per module, I've never counted!
>

What is "too big" will, of course, vary significantly - there is no
fixed limit. But if you are having difficulty figuring out where to put
things in the file and be able to find them easily, it's too big.

If you want clear and easily navigable code, don't make your files too
big. It's as simple as that.

Re: Do you insist on const-correctness?

<uesn2u$22nob$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29272&group=comp.lang.c#29272

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 21:29:33 +0200
Organization: A noiseless patient Spider
Lines: 64
Message-ID: <uesn2u$22nob$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 19:29:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="23834f7a64e7444316f6177402897f57";
logging-data="2187019"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ew9rDdT3k1UbwKsqgvMBeJEEmb6U+T6w="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.13.0
Cancel-Lock: sha1:Rzyx+90+tIp1jXYG/JXS0RSMeho=
Content-Language: en-GB
In-Reply-To: <ueskug$22af7$1@dont-email.me>
 by: David Brown - Mon, 25 Sep 2023 19:29 UTC

On 25/09/2023 20:53, Bart wrote:
> On 25/09/2023 19:03, Chris M. Thomasson wrote:
>> On 9/25/2023 10:56 AM, Bart wrote:
>>> On 25/09/2023 14:40, David Brown wrote:
>>>> On 25/09/2023 12:51, Bart wrote:
>>>
>>>>> suppose I define a typedef say at module scope to be shared by
>>>>> functions 35, 62 and 78 of 100 functions in that module.
>>>>>
>>>>> Where should I place that typedef: before the definition of
>>>>> function 1, or immediately before function 35 since that is where
>>>>> it is first used?
>>>>>
>>>>
>>>> That's a stupid question.  Don't have 100 functions in your module.
>>>
>>> Huh? I didn't realise that was that controversial. I don't actually
>>> know how many functions I have per module, I've never counted!
>>
>> I think there is a complexity rule is MISRA that talks about this...
>

I am pretty sure there is no such rule. I can't see it in my copy of
MISRA C 2012 (though I don't claim to be very familiar with the
document, so I might have missed something).

> Are there are also rules about how many lines in a function, and how
> many modules in a program?

There is the concept of "Cyclomatic complexity"
(<https://en.wikipedia.org/wiki/Cyclomatic_complexity>) which suggests
that overly complex functions become impossible to test or even to fully
comprehend.

>
> Minimising one will increase the number of functions, and minimising the
> number of functions per module will increase the number of modules.
>

There can certainly be tradeoffs, yes. Sometimes splitting things up
gives better refactorisation and more code reuse, reducing the overall
size. But the idea is to deal with manageable chunks at each level. If
you are having trouble finding information you need, you have probably
chosen the splits poorly - that could mean you have too many divisions,
or divisions in the wrong places, as well as possibly meaning your parts
are too big. It could also mean that you are looking for too much
detail at an inappropriate level - maybe knowing all the details of a
type or a function isn't actually important in order to use it correctly.

> Further, there will be more complexity due to interactions or interfaces
> between functions and between modules being exposed, that could have
> been kept private.

That can indeed be a factor. That is one of the reasons why I can't
give any fixed answers.

But if you tell me you have 100 functions in a module, with use of an
important type scattered randomly amongst them, and it's hard to know
where to put the type definition - then my first guess is the module is
too big. I might change that opinion when I know details of it and why
the code structure is this way, but that's my initial reaction.

Re: Do you insist on const-correctness?

<uesnro$22s1l$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29273&group=comp.lang.c#29273

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 12:42:47 -0700
Organization: A noiseless patient Spider
Lines: 68
Message-ID: <uesnro$22s1l$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<uesn2u$22nob$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 25 Sep 2023 19:42:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="29c8ca5014253eb1ad25f97759b1defd";
logging-data="2191413"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+8z9Jhzuhj/Srxhn5LnM1jNTdzglFsDVY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:KT9uU0IMgp8Fc2yIRqCNLOYuLbU=
In-Reply-To: <uesn2u$22nob$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 25 Sep 2023 19:42 UTC

On 9/25/2023 12:29 PM, David Brown wrote:
> On 25/09/2023 20:53, Bart wrote:
>> On 25/09/2023 19:03, Chris M. Thomasson wrote:
>>> On 9/25/2023 10:56 AM, Bart wrote:
>>>> On 25/09/2023 14:40, David Brown wrote:
>>>>> On 25/09/2023 12:51, Bart wrote:
>>>>
>>>>>> suppose I define a typedef say at module scope to be shared by
>>>>>> functions 35, 62 and 78 of 100 functions in that module.
>>>>>>
>>>>>> Where should I place that typedef: before the definition of
>>>>>> function 1, or immediately before function 35 since that is where
>>>>>> it is first used?
>>>>>>
>>>>>
>>>>> That's a stupid question.  Don't have 100 functions in your module.
>>>>
>>>> Huh? I didn't realise that was that controversial. I don't actually
>>>> know how many functions I have per module, I've never counted!
>>>
>>> I think there is a complexity rule is MISRA that talks about this...
>>
>
> I am pretty sure there is no such rule.  I can't see it in my copy of
> MISRA C 2012 (though I don't claim to be very familiar with the
> document, so I might have missed something).
>
>> Are there are also rules about how many lines in a function, and how
>> many modules in a program?
>
> There is the concept of "Cyclomatic complexity"
> (<https://en.wikipedia.org/wiki/Cyclomatic_complexity>) which suggests
> that overly complex functions become impossible to test or even to fully
> comprehend.
>
>>
>> Minimising one will increase the number of functions, and minimising
>> the number of functions per module will increase the number of modules.
>>
>
> There can certainly be tradeoffs, yes.  Sometimes splitting things up
> gives better refactorisation and more code reuse, reducing the overall
> size.  But the idea is to deal with manageable chunks at each level.  If
> you are having trouble finding information you need, you have probably
> chosen the splits poorly - that could mean you have too many divisions,
> or divisions in the wrong places, as well as possibly meaning your parts
> are too big.  It could also mean that you are looking for too much
> detail at an inappropriate level - maybe knowing all the details of a
> type or a function isn't actually important in order to use it correctly.
>
>> Further, there will be more complexity due to interactions or
>> interfaces between functions and between modules being exposed, that
>> could have been kept private.
>
> That can indeed be a factor.  That is one of the reasons why I can't
> give any fixed answers.
>
> But if you tell me you have 100 functions in a module, with use of an
> important type scattered randomly amongst them, and it's hard to know
> where to put the type definition - then my first guess is the module is
> too big.  I might change that opinion when I know details of it and why
> the code structure is this way, but that's my initial reaction.
>
>
>

I must of remembered it wrong David. I think I remember something about
trying not to have too many functions in a class...

Re: Do you insist on const-correctness?

<20230925140653.578@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29277&group=comp.lang.c#29277

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Mon, 25 Sep 2023 21:11:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <20230925140653.578@kylheku.com>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<uesn2u$22nob$1@dont-email.me> <uesnro$22s1l$1@dont-email.me>
Injection-Date: Mon, 25 Sep 2023 21:11:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="597126d75b51c4a1021936afd4da1e2b";
logging-data="2220064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19DFcehijD4lkAu455I2tKsrXilpQSPJFc="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:WYxLzh0lR0eK/CsbTohBWHhy5DU=
 by: Kaz Kylheku - Mon, 25 Sep 2023 21:11 UTC

On 2023-09-25, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> I must of remembered it wrong David. I think I remember something about
> trying not to have too many functions in a class...

If you have 100 functions in a module, such that a typical use of
the module has to use 95 of them, that's probably not very good.
(Even then, if there is a good argument that there is no other way it
can be done, while meeting some non-negotiable requirement, then it is
what it is.)

If they are various utilities that benefit certain usage scenarios
of the module, it may be acceptable to have a plethora of them.

Then we are just worried about code size in small systems: do we
have a linker that will remove individual unused function, or only
unused object files.

There is a case for having a detailed configuration system whereby the
integrator can select which functions are going to be present in the
image.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Do you insist on const-correctness?

<uetv8m$2cqip$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29290&group=comp.lang.c#29290

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 08:55:18 +0200
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uetv8m$2cqip$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<uesn2u$22nob$1@dont-email.me> <uesnro$22s1l$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 06:55:18 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8599ec46027d5e5cb379f4c86431467e";
logging-data="2517593"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZFXr6jOOnydgeUkKyKjxkjITaIQdYwSw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:vs+yU+2o3MZVAMlNOvlha/4i32w=
Content-Language: en-GB
In-Reply-To: <uesnro$22s1l$1@dont-email.me>
 by: David Brown - Tue, 26 Sep 2023 06:55 UTC

On 25/09/2023 21:42, Chris M. Thomasson wrote:
>
> I must of remembered it wrong David. I think I remember something about
> trying not to have too many functions in a class...

That is not in MISRA either, nor in the JSF rules you linked. (The JSF
rules take a lot of inspiration from MISRA, and are IMHO a better set of
rules.)

I don't know of any coding standards that have fixed maximum limits to
the size of functions or the number of functions in a file. That makes
sense, since there is no way to pick an absolute limit - it varies too
much by circumstance. The best you can have is a generalisation, not a
rule - do not make your source files so big or have so many functions
that they are difficult to navigate.

Re: Do you insist on const-correctness?

<ueu0sh$2d5c9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29291&group=comp.lang.c#29291

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 00:22:56 -0700
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <ueu0sh$2d5c9$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<uesn2u$22nob$1@dont-email.me> <uesnro$22s1l$1@dont-email.me>
<uetv8m$2cqip$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 26 Sep 2023 07:22:57 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="196fae80d8a93b5feca968dadd2c090d";
logging-data="2528649"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198DdAMPcVJ7W3jUAiAAw/LB1gDk3Su1Yo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:9SZOtth5lL3OcPYhQefFnsbln3U=
Content-Language: en-US
In-Reply-To: <uetv8m$2cqip$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 26 Sep 2023 07:22 UTC

On 9/25/2023 11:55 PM, David Brown wrote:
> On 25/09/2023 21:42, Chris M. Thomasson wrote:
>>
>> I must of remembered it wrong David. I think I remember something
>> about trying not to have too many functions in a class...
>
> That is not in MISRA either, nor in the JSF rules you linked.  (The JSF
> rules take a lot of inspiration from MISRA, and are IMHO a better set of
> rules.)
>
> I don't know of any coding standards that have fixed maximum limits to
> the size of functions or the number of functions in a file.  That makes
> sense, since there is no way to pick an absolute limit - it varies too
> much by circumstance.  The best you can have is a generalisation, not a
> rule - do not make your source files so big or have so many functions
> that they are difficult to navigate.
>
>

Yeah. I was misremembering section 3.2:
________________________________
3.2 Code Size and Complexity
AV Rule 1
Any one function (or method) will contain no more than 200 logical
source lines of code (LSLOCs).
Rationale: Long functions tend to be complex and therefore difficult to
comprehend and test.
Note: Section 4.2.1 defines should and shall rules as well the
conditions under which
deviations from should or shall rules are allowed.
AV Rule 2
There shall not be any self-modifying code.
Rationale: Self-modifying code is error-prone as well as difficult to
read, test, and maintain.
AV Rule 3
All functions shall have a cyclomatic complexity number of 20 or less.
Rationale: Limit function complexity. See AV Rule 3 in Appendix A for
additional details.
Exception: A function containing a switch statement with many case
labels may exceed this
limit.
Note: Section 4.2.1 defines should and shall rules as well the
conditions under which
deviations from should or shall rules are allowed.
________________________________

And appendix A wrt AV rule 3.

Re: Do you insist on const-correctness?

<20230926143726.8fd502c51264c4e127203da4@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29293&group=comp.lang.c#29293

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 14:37:26 +0300
Organization: A noiseless patient Spider
Lines: 113
Message-ID: <20230926143726.8fd502c51264c4e127203da4@gmail.moc>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me>
<ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me>
<ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me>
<ueskug$22af7$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="25ca480c1321b8ab0a98e8bba2150e80";
logging-data="2619380"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fYISACqxk64yjCzbj5Gz3hQ8FUJ5IseY="
Cancel-Lock: sha1:jd2lN96E15LA07jclIBzMMOGFXo=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Tue, 26 Sep 2023 11:37 UTC

Bart:
> Chris M. Thomasson:
> > Bart:
> >
> > > Huh? I didn't realise that was that controversial. I
> > > don't actually know how many functions I have per
> > > module, I've never counted!
> >
> > I think there is a complexity rule is MISRA that talks
> > about this...
>
> Are there are also rules about how many lines in a
> function, and how many modules in a program?

In fact, there are. There strictest ones I have ever met
with belong to Rebert Martin. In /Clean code/, he proposes
that a function have no more than 20 lines (and at most 3
parameters!), and a module no more than 200 lines.
Programmers tend to put limits on the complexity of the
lower-level (tactical?) program elements with which they
work, at the expense of higher-level (strategical?)
complexity describing modules/classes/interfaces.

In a 20-line function, I prefer the local variables declared
at the beginning, whereas in a 100-line function they are a
nuisance, but then there are likely other problems with the
function as well, such as trying to do too much, or
embracing more than one level of the conceptual task
hierarchy.

No, I cannot follow Martin's rules even for 80% of my code,
for various reasons. I cannot have a maximum of three
parameters without introducing ad-hoc stuctures to group
them /specificaly/ for that one call. Futhermore, if a
function returns an error flag, providing error details
(text, code, or perhaps a stack of text and code records) in
an output parameter, I am left with but one input parameter
and one output parameter (because the return value is in
use) -- clearly not enough. But that rules is possible in
popular OOP, because classes provide a /lot/ of additional
context to functions (one huge /self/ parameter), and errors
are frequently signalled out-or-bandwith, i.e. via
exceptions (no explicit error code and error info).

Modern languages with multiple returns or tuples provide a
partial solution, another being to unify error info with the
result of successful execution in dynamic languages or ones
with templates (to save the declaring a combined TResult
type for every function). But then, I loose the whole
pupose of an error flag -- the ability to invoke funtions
inside an `if' statement.

> Further, there will be more complexity due to interactions
> or interfaces between functions and between modules being
> exposed, that could have been kept private.

I believe that with a good architecture this kind of higher-
level, strategical complexity is easier to manage, where I
agree with the mainstream consensus. The essence is exactly
to escalate tatcical low-level devilish complexity into the
cloulds, and there to deal with it with more elbow-room.

There are many measures of code/program/architecture
complexity. I wonder if anybody has tried to link with the
depth of nesting directly, although not via the primitive
max or mean statistics, but via something smarter, such as
median, or weighted average.

Linus 8-chareater-tab Torvalds was IMHO right when he
decreed that a function shall not have more then three
levels of nesting, his enourmous tab serving as a dumb,
primitive, mechanical, and ugly means of enforsing this
decree.

I observe that technological progress provides a basis for a
sort of programming nazism, where all code is
unconditionally and obligatorily processed throught a
pretty- (aka ugly-) -printer before even a review, so that
the programmer cannot use any formatting whatsoever to
emphasize structure or better express his intent.

For an example, and the standard if-else-if-else... chain is
in fact a variant of a switch, and a switch has the
structure of a flat, two-dimensional table. That said, the
deeply nested format, often assumed for granted, is wrong (I
hope everyone reads this group in monospace font):

if( test_1 ) {
stat_1 } else {
if( test_2 ) {
stat_2 } else {
if( test_3 ) {
stat_3 } else {

and the correct format is flat and table-like:

if( test_1 ) stat_1;
else if( test_2 ) stat_2;
else if( test_3 ) stat_3;

It shorter, clearer, and better structured, because the
programmer has formatted the code according its intent.
Observe also the indent of the first `if' to have it aligned
with the other entries of the table.

Coding standard rarery (if ever) take these semantical
(intent) and perceptinve (table) considerations into accout,
whereas automatic linters or pretty-printers supply the
necessary technology to implement this Nazism.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Do you insist on const-correctness?

<20230926145757.995e547e064b8fe0347c079c@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29294&group=comp.lang.c#29294

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 14:57:57 +0300
Organization: A noiseless patient Spider
Lines: 60
Message-ID: <20230926145757.995e547e064b8fe0347c079c@gmail.moc>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me>
<ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me>
<ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me>
<ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="25ca480c1321b8ab0a98e8bba2150e80";
logging-data="2625317"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19acnrVmBbXsayqYjZ5zPNSbryQTmwYLJY="
Cancel-Lock: sha1:Q3qAycAuTQhDA+EPySXe+PvI2vM=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Tue, 26 Sep 2023 11:57 UTC

I wrote:

> For an example, and the standard if-else-if-else... chain
> is in fact a variant of a switch, and a switch has the
> structure of a flat, two-dimensional table. That said,
> the deeply nested format, often assumed for granted, is
> wrong (I hope everyone reads this group in monospace
> font):
>
> if( test_1 ) {
> stat_1 } else {
> if( test_2 ) {
> stat_2 } else {
> if( test_3 ) {
> stat_3 } else {
>
> and the correct format is flat and table-like:
>
> if( test_1 ) stat_1;
> else if( test_2 ) stat_2;
> else if( test_3 ) stat_3;
>
> It shorter, clearer, and better structured, because the
> programmer has formatted the code according its intent.
> Observe also the indent of the first `if' to have it
> aligned with the other entries of the table.
>
> Coding standard rarely (if ever) take these semantical
> (intent) and perceptinve (table) considerations into
> accout, whereas automatic linters or pretty-printers
> supply the necessary technology to implement this Nazism.

By the way, my restructuring in the latter format of a large
if-else- chain in DOSBox Staging did not pass code reivew,
the maintainer demanding that I revert it to the "correct"
form it had, which reminds me of another thought: that
enforced coding standards, especially in large projects with
a large and volatile body of programmers, serve to utilise
and organise the effort of so many sheep, who are a not
allowed to think for themselves, nor express themselves.
Junior programmers, fresh for the their university (or
whatever institution), find themselves thus shackled by
their first employer, and indoctrinated into mainstream
dogma at unawares, without a chance at reflection, thereby
losing the ability or independent judjement.

Thus, I know programmers who never gave thought to their
coding style. They simply process their code with the
standard formatting tool (with default settigns!) for their
language and don't care of the rest. This is encouraged, to
facilitate entry into the Nazi party: everbody else is doing
it, employees require it.

To avoid a grave misunderstanding -- the above does not
apply to anybody who has arrived at the mainstream consensus
by way of reason, rather than indoctrination.

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Do you insist on const-correctness?

<ueuk1n$2gm39$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29295&group=comp.lang.c#29295

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 13:49:58 +0100
Organization: A noiseless patient Spider
Lines: 188
Message-ID: <ueuk1n$2gm39$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 12:49:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3a983e4fb81f333ec35c6d9e8f18abd4";
logging-data="2644073"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Z9k5PToqjUzp7vueQZE38DdFYH6ogXNY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:DPWXv0PeDuvm+fZWQEwEgixbtIE=
In-Reply-To: <20230926143726.8fd502c51264c4e127203da4@gmail.moc>
 by: Bart - Tue, 26 Sep 2023 12:49 UTC

On 26/09/2023 12:37, Anton Shepelev wrote:
> Bart:
>> Chris M. Thomasson:
>>> Bart:
>>>
>>>> Huh? I didn't realise that was that controversial. I
>>>> don't actually know how many functions I have per
>>>> module, I've never counted!
>>>
>>> I think there is a complexity rule is MISRA that talks
>>> about this...
>>
>> Are there are also rules about how many lines in a
>> function, and how many modules in a program?
>
> In fact, there are. There strictest ones I have ever met
> with belong to Rebert Martin. In /Clean code/, he proposes
> that a function have no more than 20 lines (and at most 3
> parameters!), and a module no more than 200 lines.
> Programmers tend to put limits on the complexity of the
> lower-level (tactical?) program elements with which they
> work, at the expense of higher-level (strategical?)
> complexity describing modules/classes/interfaces.
>
> In a 20-line function, I prefer the local variables declared
> at the beginning, whereas in a 100-line function they are a
> nuisance, but then there are likely other problems with the
> function as well, such as trying to do too much, or
> embracing more than one level of the conceptual task
> hierarchy.
>
> No, I cannot follow Martin's rules even for 80% of my code,
> for various reasons. I cannot have a maximum of three
> parameters without introducing ad-hoc stuctures to group
> them /specificaly/ for that one call. Futhermore, if a
> function returns an error flag, providing error details
> (text, code, or perhaps a stack of text and code records) in
> an output parameter, I am left with but one input parameter
> and one output parameter (because the return value is in
> use) -- clearly not enough. But that rules is possible in
> popular OOP, because classes provide a /lot/ of additional
> context to functions (one huge /self/ parameter), and errors
> are frequently signalled out-or-bandwith, i.e. via
> exceptions (no explicit error code and error info).
>
> Modern languages with multiple returns or tuples provide a
> partial solution,

To some arbitrarily limit? That would defeat the purpose of the rule:
you can't have more than 3 arguments, but any of those 3 can be a tuple
with 28 arguments!

Presumably that made-up rule was invented before named argument lists
came about. Then, functions with lots of parameters that have default
values, don't need to be called with all the arguments.

(Is there another equally silly rule about not having more than 3
members in a struct?)

>> Further, there will be more complexity due to interactions
>> or interfaces between functions and between modules being
>> exposed, that could have been kept private.
>
> I believe that with a good architecture this kind of higher-
> level, strategical complexity is easier to manage, where I
> agree with the mainstream consensus. The essence is exactly
> to escalate tatcical low-level devilish complexity into the
> cloulds, and there to deal with it with more elbow-room.
>
> There are many measures of code/program/architecture
> complexity.

C gives ample opporunity for complexity in what is supposed to be a
simple language:

* Burying things in layers of macros

* Having nested, conditional code blocks

So that is impossible to see, just by looking at source, exactly what is
being compiled. You need to start at the very top and look at every line
code and keep track of all the macros. But people aren't compilers.

So I think those rules about numbers of parameters, lines in a function
and so on, are pointless given the endless possibilities of C.

MY C code is very conservative, and would be very easy to compile,
understand, or translate, as I don't use conditional blocks and rarely
use macros. Most I come across isn't.

> I wonder if anybody has tried to link with the
> depth of nesting directly, although not via the primitive
> max or mean statistics, but via something smarter, such as
> median, or weighted average.
>
> Linus 8-chareater-tab Torvalds was IMHO right when he
> decreed that a function shall not have more then three
> levels of nesting, his enourmous tab serving as a dumb,
> primitive, mechanical, and ugly means of enforsing this
> decree.

Using hardware tabs on a paper teletype, which also limits you to 80
columns (or was it 72?) really was enforcing it mechanically.

> I observe that technological progress provides a basis for a
> sort of programming nazism, where all code is
> unconditionally and obligatorily processed throught a
> pretty- (aka ugly-) -printer before even a review, so that
> the programmer cannot use any formatting whatsoever to
> emphasize structure or better express his intent.
>
> For an example, and the standard if-else-if-else... chain is
> in fact a variant of a switch, and a switch has the
> structure of a flat, two-dimensional table. That said, the
> deeply nested format, often assumed for granted, is wrong (I
> hope everyone reads this group in monospace font):
>
> if( test_1 ) {
> stat_1 } else {
> if( test_2 ) {
> stat_2 } else {
> if( test_3 ) {
> stat_3 } else {
>

You haven't shown the full thing, which is more like this:

if( test_1 ) {
stat_1; } else {
if( test_2 ) {
stat_2; } else {
if( test_3 ) {
stat_3; } else {}}}

Those stat_* may or may not have braces. But the brace here: 'else {
if', if you were to strictly follow certain guidelines, requires the
correct sequence of closing } braces at the end.

Other languages (even C in its preprocessor!) use a special else-if
keyword to allow the chain without an arbitrary level of nesting and
therefore indents (a 100-way chain would need about 100 indents and 100
} near the end).

But C's {...} around single statements (like a nested 'if') is optional...

> and the correct format is flat and table-like:
>
> if( test_1 ) stat_1;
> else if( test_2 ) stat_2;
> else if( test_3 ) stat_3;

.... which allows you to write it like this, although usually without
that extra alignment. In theory there is still nesting, but no multiple
}s are needed at the end.

(Another way might be to start off with 'if (0);' then all actual blocks
will start with 'else if', except the optional final 'else' not shown in
your second example.)

> It shorter, clearer, and better structured, because the
> programmer has formatted the code according its intent.
> Observe also the indent of the first `if' to have it aligned
> with the other entries of the table.

A trivial extension to the syntax could have taken care of it too. Like
'elsif', or I also created, elsewhere, this form, although I've never
used it:

case # usual control expression is blank
when test_1 then
stat_1a # no braces or begin-end needed
stat_1b
when test_2 then
stat_2
when test_1 then
stat_3
else
stat_4
end

This has the advantage, like my 'if(0)' idea, that any blocks can be
commented, uncommented, deleted, inserted and moved with greater
freedom, because the first condition+block does not have special syntax.

Re: Do you insist on const-correctness?

<ueuo0h$lfu$1@reader2.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29296&group=comp.lang.c#29296

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cro...@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 13:57:37 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <ueuo0h$lfu$1@reader2.panix.com>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc> <uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me> <20230926143726.8fd502c51264c4e127203da4@gmail.moc>
Injection-Date: Tue, 26 Sep 2023 13:57:37 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
logging-data="22014"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)
 by: Dan Cross - Tue, 26 Sep 2023 13:57 UTC

In article <20230926143726.8fd502c51264c4e127203da4@gmail.moc>,
Anton Shepelev <anton.txt@gmail.moc> wrote:
>Bart:
>>[snip]
>> Are there are also rules about how many lines in a
>> function, and how many modules in a program?
>
>In fact, there are. There strictest ones I have ever met
>with belong to Rebert Martin. In /Clean code/, he proposes
>that a function have no more than 20 lines (and at most 3
>parameters!), and a module no more than 200 lines.
>Programmers tend to put limits on the complexity of the
>lower-level (tactical?) program elements with which they
>work, at the expense of higher-level (strategical?)
>complexity describing modules/classes/interfaces.
>
>[snip]
>
>No, I cannot follow Martin's rules even for 80% of my code,
>for various reasons. I cannot have a maximum of three

Robert C Martin is, at best, a middling-quality programmer.
But more than that, the man is a blowhard and frankly no one
should take programming advice from him.

- Dan C.

Re: Do you insist on const-correctness?

<20230926171422.fbc681174edadb9d385a9c0f@gmail.moc>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29297&group=comp.lang.c#29297

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: anton....@gmail.moc (Anton Shepelev)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 17:14:22 +0300
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <20230926171422.fbc681174edadb9d385a9c0f@gmail.moc>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<uesi26$21hbl$7@dont-email.me>
<ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
<ueuo0h$lfu$1@reader2.panix.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="25ca480c1321b8ab0a98e8bba2150e80";
logging-data="2674218"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+JBedIdsPyYFL8tgv17qbEq57+a6qppBM="
Cancel-Lock: sha1:6mOliMKo79xedWniv0F4h0n/r2w=
X-Newsreader: Sylpheed 3.7.0 (GTK+ 2.24.30; i686-pc-mingw32)
 by: Anton Shepelev - Tue, 26 Sep 2023 14:14 UTC

Dan Cross:

> Robert C Martin is, at best, a middling-quality
> programmer.

Maybe he is, but how do you come to that conclusion?

--
() ascii ribbon campaign -- against html e-mail
/\ www.asciiribbon.org -- against proprietary attachments

Re: Do you insist on const-correctness?

<ueupor$kiu$1@reader2.panix.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29298&group=comp.lang.c#29298

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!.POSTED.spitfire.i.gajendra.net!not-for-mail
From: cro...@spitfire.i.gajendra.net (Dan Cross)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 14:27:39 -0000 (UTC)
Organization: PANIX Public Access Internet and UNIX, NYC
Message-ID: <ueupor$kiu$1@reader2.panix.com>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc> <20230926143726.8fd502c51264c4e127203da4@gmail.moc> <ueuo0h$lfu$1@reader2.panix.com> <20230926171422.fbc681174edadb9d385a9c0f@gmail.moc>
Injection-Date: Tue, 26 Sep 2023 14:27:39 -0000 (UTC)
Injection-Info: reader2.panix.com; posting-host="spitfire.i.gajendra.net:166.84.136.80";
logging-data="21086"; mail-complaints-to="abuse@panix.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: cross@spitfire.i.gajendra.net (Dan Cross)
 by: Dan Cross - Tue, 26 Sep 2023 14:27 UTC

In article <20230926171422.fbc681174edadb9d385a9c0f@gmail.moc>,
Anton Shepelev <anton.txt@gmail.moc> wrote:
>Dan Cross:
>
>> Robert C Martin is, at best, a middling-quality
>> programmer.
>
>Maybe he is, but how do you come to that conclusion?

By examining his publicly available work, as well as his
writing.

"Clean Code" in particular is rife with spelling and grammar
errors, and one can look at his code on Github. See, for
example, this:
https://github.com/unclebob/PDP8EmulatorIpad/pull/2
(Here's the original source program:
https://github.com/unclebob/PDP8EmulatorIpad/blob/1eba53c08fb530effb9d29aca8134f7acadfdd5f/src/topt.c
Or, consider this commit:
https://github.com/unclebob/PDP8EmulatorIpad/commit/7a80391bdbc1b1d867079392e4bcf98fcad32014
in light of the timing of the above PR. Writing a bad rinkydink
little program is one thing; unacknowledged lifting from someone
else's work is another.)

One can look at other repositories and find similar examples of
poor quality code, most of which is small and/or demo-oriented,
anyway (he, like Allen Holub and other "Agile Influencers" has
very little production-quality code out in the open).

He also tends to opine on things he knows very little about.
For example, here he rails against static typing:
https://blog.cleancoder.com/uncle-bob/2019/06/08/TestsAndTypes.html
Most of this is simply nonsense, so much so that Shriram
Kirhsnamurthi called him out in a quote-tweet:
https://twitter.com/shriramkmurthi/status/1136411753590472707
(The context here is that a strong, static type system can
render many invalid programs simply unrepresentable, therefore
reducing the amount a programmer may have to test, since a
large swath of invalid programs can't be written in the first
place.)

- Dan C.

Re: Do you insist on const-correctness?

<ueus9s$2ibi2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29299&group=comp.lang.c#29299

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 17:10:51 +0200
Organization: A noiseless patient Spider
Lines: 163
Message-ID: <ueus9s$2ibi2$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 15:10:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8599ec46027d5e5cb379f4c86431467e";
logging-data="2698818"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1944WZKpG6KZXEzXbOaeTk3gLeA3fS86Zk="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:9LbSqeTSLApummK+N5mHfIbdOTs=
In-Reply-To: <20230926143726.8fd502c51264c4e127203da4@gmail.moc>
Content-Language: en-GB
 by: David Brown - Tue, 26 Sep 2023 15:10 UTC

On 26/09/2023 13:37, Anton Shepelev wrote:
> Bart:
>> Chris M. Thomasson:
>>> Bart:
>>>
>>>> Huh? I didn't realise that was that controversial. I
>>>> don't actually know how many functions I have per
>>>> module, I've never counted!
>>>
>>> I think there is a complexity rule is MISRA that talks
>>> about this...
>>
>> Are there are also rules about how many lines in a
>> function, and how many modules in a program?
>
> In fact, there are. There strictest ones I have ever met
> with belong to Rebert Martin. In /Clean code/, he proposes
> that a function have no more than 20 lines (and at most 3
> parameters!), and a module no more than 200 lines.
> Programmers tend to put limits on the complexity of the
> lower-level (tactical?) program elements with which they
> work, at the expense of higher-level (strategical?)
> complexity describing modules/classes/interfaces.
>
> In a 20-line function, I prefer the local variables declared
> at the beginning, whereas in a 100-line function they are a
> nuisance, but then there are likely other problems with the
> function as well, such as trying to do too much, or
> embracing more than one level of the conceptual task
> hierarchy.
>
> No, I cannot follow Martin's rules even for 80% of my code,
> for various reasons. I cannot have a maximum of three
> parameters without introducing ad-hoc stuctures to group
> them /specificaly/ for that one call. Futhermore, if a
> function returns an error flag, providing error details
> (text, code, or perhaps a stack of text and code records) in
> an output parameter, I am left with but one input parameter
> and one output parameter (because the return value is in
> use) -- clearly not enough. But that rules is possible in
> popular OOP, because classes provide a /lot/ of additional
> context to functions (one huge /self/ parameter), and errors
> are frequently signalled out-or-bandwith, i.e. via
> exceptions (no explicit error code and error info).
>
> Modern languages with multiple returns or tuples provide a
> partial solution, another being to unify error info with the
> result of successful execution in dynamic languages or ones
> with templates (to save the declaring a combined TResult
> type for every function). But then, I loose the whole
> pupose of an error flag -- the ability to invoke funtions
> inside an `if' statement.
>

You realise that in C you can return structs, and thus include status
returns as well as value returns in one item? It is maybe not quite as
convenient in C as in languages supporting multiple return values, but
it is certainly possible.

Still, why are you talking about modern languages and object oriented
programming when you insist on using a language outdated a generation ago?

>> Further, there will be more complexity due to interactions
>> or interfaces between functions and between modules being
>> exposed, that could have been kept private.
>
> I believe that with a good architecture this kind of higher-
> level, strategical complexity is easier to manage, where I
> agree with the mainstream consensus. The essence is exactly
> to escalate tatcical low-level devilish complexity into the
> cloulds, and there to deal with it with more elbow-room.
>
> There are many measures of code/program/architecture
> complexity. I wonder if anybody has tried to link with the
> depth of nesting directly, although not via the primitive
> max or mean statistics, but via something smarter, such as
> median, or weighted average.
>
> Linus 8-chareater-tab Torvalds was IMHO right when he
> decreed that a function shall not have more then three
> levels of nesting, his enourmous tab serving as a dumb,
> primitive, mechanical, and ugly means of enforsing this
> decree.

No, Linus was wrong - as he is on many things. (He's right on many
things too, of course.) We are not using typewriters, we are not using
80x25 character displays, and we do not need to have pointless
limitations. I don't advocate for deeply nested or overly complex
functions, of course - I advocate for clear code with immediately
obvious blocks indicated by braces /and/ indents. And if clear code
requires more than 3 levels of nesting, use that.

>
> I observe that technological progress provides a basis for a
> sort of programming nazism, where all code is
> unconditionally and obligatorily processed throught a
> pretty- (aka ugly-) -printer before even a review, so that
> the programmer cannot use any formatting whatsoever to
> emphasize structure or better express his intent.
>
> For an example, and the standard if-else-if-else... chain is
> in fact a variant of a switch, and a switch has the

Not in C.

> structure of a flat, two-dimensional table. That said, the
> deeply nested format, often assumed for granted, is wrong (I
> hope everyone reads this group in monospace font):
>
> if( test_1 ) {
> stat_1 } else {
> if( test_2 ) {
> stat_2 } else {
> if( test_3 ) {
> stat_3 } else {

I have never seen if-else chains formatted that way - it is clearly
incorrect indentation.

>
> and the correct format is flat and table-like:
>
> if( test_1 ) stat_1;
> else if( test_2 ) stat_2;
> else if( test_3 ) stat_3;
>

These are both wrong :-)

if (test1) {
stat_1;
} else if (test2) {
stat_2;
} else if (test3) {
stat_3;
} else {
...
}

That is clearer than yours, and far more maintainable. And any coding
standard with a care for safety, security or reliability, (such as MISRA
or JSF-AV mentioned in this thread) will insist on the braces here.

> It shorter, clearer, and better structured, because the
> programmer has formatted the code according its intent.
> Observe also the indent of the first `if' to have it aligned
> with the other entries of the table.

That's a strawman argument, because no one would ever write an if-else
chain the way you first suggested.

>
> Coding standard rarery (if ever) take these semantical
> (intent) and perceptinve (table) considerations into accout,
> whereas automatic linters or pretty-printers supply the
> necessary technology to implement this Nazism.
>

I have no idea what you are trying to say there.

Re: Do you insist on const-correctness?

<ueusu7$2if5b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29300&group=comp.lang.c#29300

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 17:21:42 +0200
Organization: A noiseless patient Spider
Lines: 93
Message-ID: <ueusu7$2if5b$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
<20230926145757.995e547e064b8fe0347c079c@gmail.moc>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 26 Sep 2023 15:21:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8599ec46027d5e5cb379f4c86431467e";
logging-data="2702507"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18PJiyhCM/K7TAbCXzKLqBzgOEDbjStqhE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Je7jx5vUoKGoowqVysmNI+1ORZA=
In-Reply-To: <20230926145757.995e547e064b8fe0347c079c@gmail.moc>
Content-Language: en-GB
 by: David Brown - Tue, 26 Sep 2023 15:21 UTC

On 26/09/2023 13:57, Anton Shepelev wrote:
> I wrote:
>
>> For an example, and the standard if-else-if-else... chain
>> is in fact a variant of a switch, and a switch has the
>> structure of a flat, two-dimensional table. That said,
>> the deeply nested format, often assumed for granted, is
>> wrong (I hope everyone reads this group in monospace
>> font):
>>
>> if( test_1 ) {
>> stat_1 } else {
>> if( test_2 ) {
>> stat_2 } else {
>> if( test_3 ) {
>> stat_3 } else {
>>
>> and the correct format is flat and table-like:
>>
>> if( test_1 ) stat_1;
>> else if( test_2 ) stat_2;
>> else if( test_3 ) stat_3;
>>
>> It shorter, clearer, and better structured, because the
>> programmer has formatted the code according its intent.
>> Observe also the indent of the first `if' to have it
>> aligned with the other entries of the table.
>>
>> Coding standard rarely (if ever) take these semantical
>> (intent) and perceptinve (table) considerations into
>> accout, whereas automatic linters or pretty-printers
>> supply the necessary technology to implement this Nazism.
>
> By the way, my restructuring in the latter format of a large
> if-else- chain in DOSBox Staging did not pass code reivew,
> the maintainer demanding that I revert it to the "correct"
> form it had, which reminds me of another thought: that
> enforced coding standards, especially in large projects with
> a large and volatile body of programmers, serve to utilise
> and organise the effort of so many sheep, who are a not
> allowed to think for themselves, nor express themselves.

Sorry, but you are wrong here.

Consistent style is very important in large projects, greatly reducing
the effort needed for different programmers to understand and work on
different bits of code. Consistency is usually more important than the
details of the style. Maverick styles like yours have no place in group
efforts.

> Junior programmers, fresh for the their university (or
> whatever institution), find themselves thus shackled by
> their first employer, and indoctrinated into mainstream
> dogma at unawares, without a chance at reflection, thereby
> losing the ability or independent judjement.
>

You are the one who is using a style that, at best, might have been of
interest decades ago. Perhaps you were not influenced by mainstream
coding styles, but that's nothing to be proud of - other people know
better than you, but you have not learned from them. Looking at other
styles and taking the best from them (where "best" depends on many
factors, and is not absolute) is not "indoctrination", it is just
learning from other people's experiences.

> Thus, I know programmers who never gave thought to their
> coding style. They simply process their code with the
> standard formatting tool (with default settigns!) for their
> language and don't care of the rest. This is encouraged, to
> facilitate entry into the Nazi party: everbody else is doing
> it, employees require it.
>

If you don't have particular reason to pick a different style, then
common standards are usually a very good starting point. Maybe the
programmer using them hasn't thought them through in detail - but
/someone/ has.

You /have/ thought about your coding style. That does not make it good.
You just think it is good because you have used it for decades.

> To avoid a grave misunderstanding -- the above does not
> apply to anybody who has arrived at the mainstream consensus
> by way of reason, rather than indoctrination.
>

Some people have this bizarre notion that following common standards, or
listening to mainstream opinions, or - heaven forbid! - paying attention
to established and qualified experts is somehow "indoctrination". Did
it ever occur to you that sometimes when lots of people agree on
something, or work the same way, it is perhaps because it is a good idea?

Re: Do you insist on const-correctness?

<yGCQM.35598$ugs.11802@fx36.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29301&group=comp.lang.c#29301

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Do you insist on const-correctness?
Newsgroups: comp.lang.c
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc> <20230926143726.8fd502c51264c4e127203da4@gmail.moc> <ueuo0h$lfu$1@reader2.panix.com> <20230926171422.fbc681174edadb9d385a9c0f@gmail.moc> <ueupor$kiu$1@reader2.panix.com>
Lines: 30
Message-ID: <yGCQM.35598$ugs.11802@fx36.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 26 Sep 2023 15:22:06 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 26 Sep 2023 15:22:06 GMT
X-Received-Bytes: 1731
 by: Scott Lurndal - Tue, 26 Sep 2023 15:22 UTC

cross@spitfire.i.gajendra.net (Dan Cross) writes:
>In article <20230926171422.fbc681174edadb9d385a9c0f@gmail.moc>,
>Anton Shepelev <anton.txt@gmail.moc> wrote:
>>Dan Cross:
>>
>>> Robert C Martin is, at best, a middling-quality
>>> programmer.
>>
>>Maybe he is, but how do you come to that conclusion?
>
>By examining his publicly available work, as well as his
>writing.
>
>"Clean Code" in particular is rife with spelling and grammar
>errors, and one can look at his code on Github. See, for
>example, this:
>https://github.com/unclebob/PDP8EmulatorIpad/pull/2
>(Here's the original source program:
>https://github.com/unclebob/PDP8EmulatorIpad/blob/1eba53c08fb530effb9d29aca8134f7acadfdd5f/src/topt.c

What's with the screwy indentation? That's a 'do not hire this guy' flag.

Waste of time to bzero the string before constructing it using strcpy,
rather than just using snprintf().

Ah, I see your point is that he writes poor code.

Re: Do you insist on const-correctness?

<ueuv1r$2iped$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29302&group=comp.lang.c#29302

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 16:57:48 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <ueuv1r$2iped$1@dont-email.me>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
<ueus9s$2ibi2$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 26 Sep 2023 15:57:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3a983e4fb81f333ec35c6d9e8f18abd4";
logging-data="2713037"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+aAoRQ06dSh/WycaXJS4x09JelHBOwSmE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:v8kJqWXGXQgqegzufGlxMhknOTM=
In-Reply-To: <ueus9s$2ibi2$1@dont-email.me>
 by: Bart - Tue, 26 Sep 2023 15:57 UTC

On 26/09/2023 16:10, David Brown wrote:
> On 26/09/2023 13:37, Anton Shepelev wrote:

>>          if( test_1 ) stat_1;
>>     else if( test_2 ) stat_2;
>>     else if( test_3 ) stat_3;
>>
>
> These are both wrong :-)
>
>
>     if (test1) {
>         stat_1;
>     } else if (test2) {
>         stat_2;
>     } else if (test3) {
>         stat_3;
>     } else {
>         ...
>     }
>
> That is clearer than yours, and far more maintainable.  And any coding
> standard with a care for safety, security or reliability, (such as MISRA
> or JSF-AV mentioned in this thread) will insist on the braces here.

What is the actual rule about braces? Because you've clearly missed some
out there, in omitting them around the first two 'else' branches.

If you saying this is OK, then that's playing fast and rule with any
such rule that braces must always be used even around one statement.

Re: Do you insist on const-correctness?

<20230926093309.110@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=29303&group=comp.lang.c#29303

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c
Subject: Re: Do you insist on const-correctness?
Date: Tue, 26 Sep 2023 16:40:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <20230926093309.110@kylheku.com>
References: <20230918012105.b9fb2c36e93542dddb654b1f@gmail.moc>
<86a5tkmj1b.fsf@linuxsc.com>
<20230918115357.0c06b3c4225a6c33bb3244dc@g{oogle}mail.com>
<ue9ocg$1qfvq$1@dont-email.me>
<20230923190523.1f810ae96368b345fe455268@gmail.moc>
<uera6l$1pr35$1@dont-email.me> <ueronc$1sd54$1@dont-email.me>
<ues2jo$1uh7s$1@dont-email.me> <ueshl5$21lmm$1@dont-email.me>
<uesi26$21hbl$7@dont-email.me> <ueskug$22af7$1@dont-email.me>
<20230926143726.8fd502c51264c4e127203da4@gmail.moc>
<ueus9s$2ibi2$1@dont-email.me> <ueuv1r$2iped$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 26 Sep 2023 16:40:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="84073cef60c20381e418356514cfa3d7";
logging-data="2731336"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GHk8D58b6TLfNugljDoxeYDQQwSfPjdU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:9t7Z6PcJjFoxdgsXN/rrEjbSmVQ=
 by: Kaz Kylheku - Tue, 26 Sep 2023 16:40 UTC

On 2023-09-26, Bart <bc@freeuk.com> wrote:
> On 26/09/2023 16:10, David Brown wrote:
>> On 26/09/2023 13:37, Anton Shepelev wrote:
>
>>>          if( test_1 ) stat_1;
>>>     else if( test_2 ) stat_2;
>>>     else if( test_3 ) stat_3;
>>>
>>
>> These are both wrong :-)
>>
>>
>>     if (test1) {
>>         stat_1;
>>     } else if (test2) {
>>         stat_2;
>>     } else if (test3) {
>>         stat_3;
>>     } else {
>>         ...
>>     }
>>
>> That is clearer than yours, and far more maintainable.  And any coding
>> standard with a care for safety, security or reliability, (such as MISRA
>> or JSF-AV mentioned in this thread) will insist on the braces here.
>
> What is the actual rule about braces? Because you've clearly missed some
> out there, in omitting them around the first two 'else' branches.

The actual rules is that the required braces, comprising a compound
statement, can be prefixed by something which modifies the statement
into a conditional.
>
> If you saying this is OK, then that's playing fast and rule with any
> such rule that braces must always be used even around one statement.

Indeed, I myself sometimes writes in a style like the following:

if (condition) {
/* loop not needed */
} else for (...) {

}

The else keyword needs a statement, and the for statement
satisfies it. It has braces of its own, so everything is cool.

The for (...) header is effectively a statement prefix which indicates
iteration of that statement.

In my style, I allow the braced statement to be prefixed not only
by if (...) but other, similar statement introducers/prefixes
like while (...) and switch.

I don't think I've ever written a

if (this) {

} else do {

} while(...);

But I totally might. :)

What I wouldn't write is:

if (condition) {
/* loop not needed */
} else for (...)
body_expression_statement;

Or, let alone:

if (condition) {
/* loop not needed */
} else for (...)
/* empty */;

Some languages combine "else" and "if" into a single token, even.
The C preprocessing language is like that: #elif.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.


devel / comp.lang.c / Re: Do you insist on const-correctness?

Pages:12345678
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor