Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: David Brown Newsgroups: comp.lang.c Subject: Re: Interval Comparisons Date: Mon, 10 Jun 2024 17:56:19 +0200 Organization: A noiseless patient Spider Lines: 58 Message-ID: References: <87bk4dz9ve.fsf@nosuchdomain.example.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Mon, 10 Jun 2024 17:56:19 +0200 (CEST) Injection-Info: dont-email.me; posting-host="c8fdaca8f4676d2822b9c14d4f88eea0"; logging-data="562214"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+2Nw1iNHMnXhZeGlQa2sKg8vTnPKsrNLg=" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.11.0 Cancel-Lock: sha1:7HfKgrlKNP1T2/KCYPIW/H+EQCA= In-Reply-To: Content-Language: en-GB Bytes: 4015 On 10/06/2024 17:33, bart wrote: > On 09/06/2024 12:26, David Brown wrote: >> On 07/06/2024 14:20, bart wrote: >>> On 07/06/2024 12:17, David Brown wrote: >> If that is your intent, then fair enough.  But I think that is an >> unusual intent. > > Really,  checking that A and B both have the same value X is that unusual? No. But checking that A and B have the same value, then checking that one of them as the same value as a constant X, is - I would say - definitely an unusual way to think about things. It is more natural to check if A is equal to X, and if B is equal to X. You seem to disagree with that. Fair enough, it is a subjective opinion. >> >> I don't think it is fair to claim particular ways of writing these >> things are always clearer, or better, or uglier, or unclear - it will >> depend on the rest of the language, and how the code is used.  But in >> general I think it helps to write code that follows the logic of what >> the writer really means, rather than alternative constructions that >> give the same result. > > Using function-like syntax is OK when you have the same operator between > multiple terms. 'rising' could have '<' or '<='. Yes. I think that is almost certainly what you would want, except in the case of checking if a value is in a half-open interval. I would be happy with an "in" operator and ranges of some sort for that case. > > All-equal would have the same operator too, but it looks clunkier, and a > bit over-the-top: > >    a = b                2 terms >    all_equal(a, b, c)   3 terms using your feature >    a = b = c            3 terms using chained ops > >    rising(a, b, c)      Using your other feature >    a <= b <= c          Using the same chained-op feature > I guess a lot of this ends up as a matter of taste. > Your solution requires a heavyweight language feature. It also looks > like it will generate a lot of intermediate code that will need a > heavyweight optimiser to tear down again. > I place approximately zero weight on requirements for code generators to be optimising. It is irrelevant to the user - it only matters to the implementer of the tools. It does have to be /possible/ to implement the feature, but it does not matter if the compiler has to optimise well to make it efficient.