Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c++ > #86073

Re: To C or not to C++

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c++
Subject Re: To C or not to C++
Date 2022-08-25 11:36 -0700
Organization None to speak of
Message-ID <87lerckw63.fsf@nosuchdomain.example.com> (permalink)
References (16 earlier) <392fc8fe-b516-434c-8962-c11e2154f4c6n@googlegroups.com> <87y1vcwo4q.fsf@bsb.me.uk> <6aeee22b-9030-481e-86cb-4a47c6746f0bn@googlegroups.com> <87mtbsw8vf.fsf@nosuchdomain.example.com> <9af97d69-57b6-4b58-bd51-e7557692b3cen@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
> On Thursday, 25 August 2022 at 18:06:45 UTC+1, Keith Thompson wrote:
>> Malcolm McLean <malcolm.ar...@gmail.com> writes: 
>> [...]
>> > Computer science people would tend to think that it's important to have 
>> > a boolean type, because a lot of logic works on values which are inherently 
>> > true or false. Practical programmers would tend to say that it's not, because 
>> > most hardware won't support it. You will of course find exceptions.
>> Many practical programmers would tend to say it's important to have a 
>> boolean type because it makes it easier to write clear code. (Some 
>> probably prefer to use zero and non-zero rather than explicit bool, 
>> false, and true.) 
>>
> It does document that a value is logically bi-valued. So we can enable or disable
> a button, but we can't have it in a half-enabled state. However the problem is
> that when you look at C++ code which uses booleans, it's not clear what is
> being passed
> e.g. if you see
> Button mybutton("OK", &rect, true);
> Obviously this is creating a button. Obviously it's got the display text "OK". Obviously
> rect is some sort of rectangle containing the position. But what is "true"? 
> If we make enabled / disabled an enum, then it's more clear what  the code is doing.

Agreed -- but what does that have to do with what we were discussing?
You were talking about hardware support.  The same considerations apply
to a built-in boolean type or to a 2-element enum.

>> Why would a "practical programmer" care whether there's direct hardware 
>> support for bool? If the compiler handles it correctly, it just works. 
>> In a very real sense, all hardware supports booleans, with more or less 
>> work required by the compiler.
>> 
> Well one issue is whether if (flag == true) works as expected. If the hardware supports
> 1 bit types, then it must work, because flag cannot have any bit pattern other than
> bit clear / bit set. If bool is something provided by software, and the underlying type
> is an integer, then it might hold unexpected values.
> A theoretical person doesn't really have to worry about this, because in his world, all
> bools are initialised to 1 or 0 and all operations on them yield 1 or 0. In the practical
> programmer's world, things can get more messy, because some of the code might
> be written in another language, for example. 

First off, why would you write `if (flag == true)` rather than `if(flag)`?

But for a boolean type that's built into the language, like C's _Bool or
C++'s bool, none of that is an issue in the absence of memory
corruption.  Conversions to bool always yield false or true (0 or 1).
If some of the code is written in another language, then *of course* you
have to make sure that anything converted to a native boolean is
normalized.  Anything that stores a value other than 0 or 1 in a C or
C++ boolean object is buggy, and needs to be fixed.

None of this has anything to do with some distinction between
theoretical and practical programmers.

Sometimes I'm a theoretical programmer, and sometimes I'm a practical
programmer.  In either role, I care that something is supported by the
combination of the hardware and the compiler.  As long as the compiler
does its job, it works.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Working, but not speaking, for Philips
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c++ | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

To C or not to C++ NOSPAM.Alan.Beck@darkrealms.ca (Alan Beck) - 2022-08-08 09:43 +0000
  Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-08 20:02 +0300
  Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-09 05:38 +0000
    Re: To C or not to C++ Ralf Fassel <ralfixx@gmx.de> - 2022-08-09 11:07 +0200
      Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-10 02:25 +0200
        Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-09 17:52 -0700
          Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-09 21:39 -0700
            Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-10 07:45 +0000
          Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-10 19:50 +0000
            Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-10 13:13 -0700
            Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-11 04:29 +0200
        Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-10 02:41 +0000
        Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-10 07:39 +0000
          Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-10 10:11 -0700
            Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 08:23 +0000
              Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-12 12:12 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 14:41 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:09 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 10:28 +0200
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-13 09:37 +0000
              Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-12 15:55 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 14:43 +0000
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-12 18:07 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-12 15:14 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:11 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-13 09:38 +0000
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 17:56 +0200
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 11:32 +0300
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 11:33 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-24 04:37 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 13:31 +0100
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:09 +0000
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 15:31 +0100
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:38 +0000
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 15:57 +0100
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-24 10:41 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-24 21:48 +0100
                Re: To C or not to C++ "Alf P. Steinbach" <alf.p.steinbach@gmail.com> - 2022-08-25 07:34 +0200
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 11:29 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 04:14 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 12:36 +0100
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 05:16 -0700
                Re: To C or not to C++ Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 17:16 +0100
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:35 +0200
                [OT] Bad CS course, no cookie (Was: To C or not to C++) Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-25 21:32 +0100
                Re: [OT] Bad CS course, no cookie (Was: To C or not to C++) David Brown <david.brown@hesbynett.no> - 2022-08-25 23:16 +0200
                Re: [OT] Bad CS course, no cookie Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-26 00:33 +0100
                Re: [OT] Bad CS course, no cookie David Brown <david.brown@hesbynett.no> - 2022-08-26 10:39 +0200
                Re: [OT] Bad CS course, no cookie Ben Bacarisse <ben.usenet@bsb.me.uk> - 2022-08-26 10:57 +0100
                Re: [OT] Bad CS course, no cookie David Brown <david.brown@hesbynett.no> - 2022-08-26 12:49 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 19:56 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 10:47 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 02:48 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 13:02 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 04:57 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-26 14:55 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-26 06:20 -0700
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-27 18:44 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-28 11:30 +0200
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 10:06 -0700
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-25 10:32 -0700
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 11:36 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:47 +0200
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-26 03:11 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 09:21 +0200
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-25 12:58 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 10:23 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-25 20:51 +0200
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-25 12:14 -0700
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-24 13:56 +0000
                Re: To C or not to C++ Paavo Helde <eesnimi@osa.pri.ee> - 2022-08-24 17:18 +0300
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-24 14:25 +0000
                Re: To C or not to C++ scott@slp53.sl.home (Scott Lurndal) - 2022-08-12 16:46 +0000
                Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-15 06:16 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-15 19:01 +0000
                Re: To C or not to C++ Bo Persson <bo@bo-persson.se> - 2022-08-15 22:22 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-16 08:48 +0200
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-16 19:19 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-16 12:56 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-17 18:47 +0000
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-17 14:49 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-18 14:49 +0000
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-19 03:10 +0200
                Re: To C or not to C++ d thiebaud <thiebauddick2@aol.com> - 2022-08-18 22:12 -0400
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-18 20:08 -0700
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-19 10:39 +0000
                Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-17 06:45 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-17 18:48 +0000
                Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-16 19:16 +0000
              Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:03 -0700
        Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-10 10:13 +0200
          Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-11 04:25 +0200
            Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-11 01:03 -0700
            Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-11 08:11 +0000
            Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-11 13:53 +0200
              Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-13 04:13 +0200
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-13 21:13 +0200
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-13 12:29 -0700
                Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-13 13:12 -0700
                Re: To C or not to C++ David Brown <david.brown@hesbynett.no> - 2022-08-14 00:44 +0200
            Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-12 02:54 -0700
              Re: To C or not to C++ Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2022-08-12 12:12 -0700
                Re: To C or not to C++ Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2022-08-12 16:22 -0700
                Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-12 17:49 -0700
                Re: To C or not to C++ Manfred <noname@add.invalid> - 2022-08-13 03:16 +0200
                Re: To C or not to C++ Öö Tiib <ootiib@hot.ee> - 2022-08-13 09:08 -0700
                Re: To C or not to C++ Tim Rentsch <tr.17687@z991.linuxsc.com> - 2022-08-15 14:44 -0700
        Re: To C or not to C++ Ralf Fassel <ralfixx@gmx.de> - 2022-08-10 12:06 +0200
        Re: To C or not to C++ Juha Nieminen <nospam@thanks.invalid> - 2022-08-11 07:04 +0000
  Re: To C or not to C++ Bonita Montero <Bonita.Montero@gmail.com> - 2022-08-09 12:31 +0200
    Re: To C or not to C++ Muttley@dastardlyhq.com - 2022-08-09 15:59 +0000
    Re: To C or not to C++ Frederick Virchanza Gotham <cauldwell.thomas@gmail.com> - 2022-08-19 04:09 -0700
  Re: To C or not to C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-13 12:17 -0700
  Re: To C or not to C++ "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2022-08-27 23:15 -0700

csiph-web