Sujet : Re: Fixing a sample from K&R book using cake static analyser
De : janis_papanagnou+ng (at) *nospam* hotmail.com (Janis Papanagnou)
Groupes : comp.lang.cDate : 24. Jun 2024, 04:01:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v5anhl$oa76$1@dont-email.me>
References : 1 2 3 4 5
User-Agent : Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0
On 24.06.2024 01:04, Kaz Kylheku wrote:
On 2024-06-23, Anton Shepelev <anton.txt@gmail.moc> wrote:
Kaz Kylheku:
>
What scatter-brained drivel. Watch and learn:
>
struct nlist *install(char *name, char *defn)
{
struct nlist *existing = lookup(name);
>
if (existing) {
return existing;
} else {
>
When the if-branch ends with a return, the else-branch is
redundant, and its body shall be written bare, removing one
(useless) level of nesting and indentation.
I was tempted to post the same comment before I noticed that:
I did that because there are declarations in the else case.
So I at least understand where Kaz was coming from and
abstained from a comment; I think it's a valid view.
I avoid mising declarations and statements, because I consider
that a language misfeature.
In a block structured language, declarations should come first,
then statements.
This is an age old concept, some programming languages even
require that (e.g. Simula, Pascal, just to name a few). But
starting with C++ I preferred the initialized declarations;
introduce objects where you use them, so that you have sort
of a "local scope"[*].
Janis
[*] Note: By that I mean that your context is kept locally
and compact, I don't mean a block scope, or similar.