Deutsch English Français Italiano |
<vb75g9$3bntp$1@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: Thiago Adams <thiago.adams@gmail.com> Newsgroups: comp.lang.c Subject: Re: Code guidelines Date: Tue, 3 Sep 2024 11:12:24 -0300 Organization: A noiseless patient Spider Lines: 42 Message-ID: <vb75g9$3bntp$1@dont-email.me> References: <vb6v1t$3b5mb$1@dont-email.me> <vb726n$3b4rq$1@dont-email.me> <vb736j$3b5mb$2@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Tue, 03 Sep 2024 16:12:25 +0200 (CEST) Injection-Info: dont-email.me; posting-host="15b67f073a3e4783414ee664431ab3cb"; logging-data="3530681"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kAZkdY6s7pq6Jlzb708CqAW4ClbDE/+w=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:JMAK0hS7y7pFeOYZ/HVOpKKexcQ= In-Reply-To: <vb736j$3b5mb$2@dont-email.me> Content-Language: en-US On 03/09/2024 10:33, Thiago Adams wrote: .... > For instance: > > The first sample my create confusion (is name optional?) > > void f(struct user* user) > { > if (user->name && strcmp(user->name, "john") == 0) > { > //... > } > } > > But : > void f(struct user* user) > { > assert(user->name); > if (user->name && strcmp(user->name, "john") == 0) > { > //... > } > } > > would show redundancy but making clear the contract still "name should > not be null" Redundant code can either indicate a programmer's mental confusion or serve as a way to address potential contract violations. I believe the objective is to ensure that runtime checks are not questioning the contract but rather functioning as redundant safeguards. In other words, the programmer must demonstrate that they understand the contract and are not messing it. A safeguards for a very low risk situation also may indicate a mental confusion about the risks involved. For instance, assert(2 + 2 == 4);