Path: ...!news.nobody.at!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Janis Papanagnou Newsgroups: comp.lang.c Subject: Re: Fixing a sample from K&R book using cake static analyser Date: Mon, 24 Jun 2024 05:01:07 +0200 Organization: A noiseless patient Spider Lines: 44 Message-ID: References: <20240623034624.135@kylheku.com> <20240624014040.c7a4b34e68ce734ff837868d@gmail.moc> <20240623160155.649@kylheku.com> MIME-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Injection-Date: Mon, 24 Jun 2024 05:01:09 +0200 (CEST) Injection-Info: dont-email.me; posting-host="8b06e05337e091ed4f227526767ebb5e"; logging-data="796902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18fKUxP2o2Gp5JE0R1ogiKW" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 Cancel-Lock: sha1:oL8/G7h5pS7QcePveiOQ+6w1JZk= In-Reply-To: <20240623160155.649@kylheku.com> X-Enigmail-Draft-Status: N1110 Bytes: 2620 On 24.06.2024 01:04, Kaz Kylheku wrote: > On 2024-06-23, Anton Shepelev 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.