Article View: comp.std.c
Article #3597Re: Incrementing a bool
From: Peter Seebach
Date: Tue, 01 Aug 1995 12:35
Date: Tue, 01 Aug 1995 12:35
69 lines
3628 bytes
3628 bytes
In article <3va943$im@gabi.gabi-soft.fr>, J. Kanze <kanze@gabi-soft.fr> wrote: >Come now: I know it is not precise, but you >aren't going to tell me that you've never said things like, "if the >expression is true, we do this". That's one of the things I think... >This is part of what I find causes the confusion: you really don't say >things like: "if this pointer is true..." and you shouldn't say things >like: "if strcmp returns true..." (since the return value of strcmp is >*not* a logical value). More generally, though, what I *really* say is "if pointer". Come on, in English, does one say "if that I am going to the store is true"? No. You say "If I'm going to the store". In C, I don't say "if this pointer is not null". I say "if this pointer". I don't say "if this expression is non zero", I say "If this expression". The comparison with falsehood is the basis of logical if in natural language, and is how it is done in the programming languages I know. The comparison with an appropriate false value is implicit. Similarly, for flags, I just use if(flag), not if(flag != 0). I consider the former clearer; it says exactly what I mean, without adding garbage that a good compiler will ignore. >A special boolean type is a reality, whether C wants to admit it or not. Yes, but it's a reality that consists of an understanding of when something is true, not of a separate type to which everything else is converted. Rather these two are isomorphic, but the former we already have, and the latter involves the addition of new logic and added conversions. >Independantly of the variable, I want the comparison operators to return >bool, not int, and I want if and while to require bool as the expression >type. A new type is not just for declaring variables (although if the >type exists, I want to also be able to declare variables). I just want them to return something that acts like a truth value. All I care about is that there are two trivially different cases, which there are. I don't want "if a is greater than b is true", I want "is a is greater than b." This is what we have. Why would we ever change it? I don't seek ever more confusing phrasings. >Basically, I am a proponent of `say what you mean'. Me too. But, long experience has taught me that a pointer *is* when it's non-null, and *isn't* when it's null. So, if (fp) is perfectly natural for me; it means "if my file pointer", and that's what I mean. I think it helps that I learned Chinese; there's a trivial way to say "there is" that's short enough to be useful, and once you get used to just using the existance-and-or-relevance test, it's nice to have it in a programming language. It works on pointers, it works on everything. It conveniently says exactly what I mean. -s -- Peter Seebach - seebs@solon.com || seebs@intran.xerox.com --- C/Unix proto-wizard -- C/Unix questions? Send mail for help. No, really! Copyright 1995 Peter Seebach. Not for distribution through Microsoft Network. a^n+b^n=c^n has integer solutions a, b, and c only for n=2. To prove, assume
Technical Details
Message-ID:
<3vl72l$dp9@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<KANZE.95Jul19114530@slsvhdt.lts.sel.alcatel.de> <KANZE.95Jul26122240@slsvhdt.lts.sel.alcatel.de> <3v74hd$ndb@caip.rutgers.edu> <3va943$im@gabi.gabi-soft.fr>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: seebs@solutions.solon.com (Peter Seebach) Newsgroups: comp.std.c Subject: Re: Incrementing a bool Date: 1 Aug 1995 07:35:33 -0500 Organization: Usenet Fact Police (Undercover) Message-ID: <3vl72l$dp9@solutions.solon.com> References: <KANZE.95Jul19114530@slsvhdt.lts.sel.alcatel.de> <KANZE.95Jul26122240@slsvhdt.lts.sel.alcatel.de> <3v74hd$ndb@caip.rutgers.edu> <3va943$im@gabi.gabi-soft.fr> NNTP-Posting-Host: solutions.solon.com