On 5/11/2019 7:27 PM, Mike Franklin wrote:
I think Walter is conflating how bool is stored in memory with its semantics.

That's exactly what I'm deliberately doing.

I'm currently considering using D's rich modeling features to create a new boolean type that behaves more like a boolean and less like a bit.  But it's unfortunate and disappointing we have to resort to something like that.

I understand. Every programmer, sooner or later, decides to step up and take a swing at inventing boolean. (I have too - did you know that D used to have a `bit` builtin type?) The programming landscape is littered with the corpses of one after another. Phobos has multiple ones - RefCountedAutoInitialize .yes and .no, and even a struct Yes and a struct No. std.bitmanip has an enum A{True,False}. std.json has enum E{True=true}. std.typecons has the bizarre enum issue10647_isAlwaysTrue=true;. (One wonders what would happen if it was set to false. Would it cause a rip in the fabric of space-time? I dare not experiment with that!)

The C++ Committee currently is fiercely debating adding a "Boolean" construct in one of the longest threads I've ever seen. One of their problems is it conflicts with the endless "Boolean" types added to existing C++ code, along with every variation "Bool", "Bool", "boolean", etc.

All this effort strongly implies that there's no such thing as a satisfactory bool type. Will you succeed where 10,000 other programmers have failed? Seems unlikely. But I doubt I will dissuade you from trying.

So what does work reasonably? Treating it like a small integer. We know what the various integer semantics are, and it fits right in with that. I know the operator ++ difference, and it is my fault that I succumbed to a moment of boolean madness and allowed that in. (++ on D bool is saturation arithmetic, unlike the overflow semantics in every other integer type. It is a mistake, please don't use that as justification for adding more quirky behaviors.)

On a final note, C++ added a std::vector<bool> special case, which works unlike any other vector type. Years of experience have shown that to have been a mistake, just like all the others, and it is widely derided as a complete failure.
  • DConf 2019 AGM Lives... Mike Parker via Digitalmars-d-announce
    • Re: DConf 2019 ... Exil via Digitalmars-d-announce
      • Re: DConf 2... Mike Franklin via Digitalmars-d-announce
        • Re: DCo... Nick Sabalausky (Abscissa) via Digitalmars-d-announce
        • Re: boo... Walter Bright via Digitalmars-d-announce
          • Re:... Nick Sabalausky (Abscissa) via Digitalmars-d-announce
            • ... Kagamin via Digitalmars-d-announce
              • ... Mike Franklin via Digitalmars-d-announce
                • ... Andrei Alexandrescu via Digitalmars-d-announce
                • ... Mike Franklin via Digitalmars-d-announce
                • ... Andrei Alexandrescu via Digitalmars-d-announce
                • ... Mike Franklin via Digitalmars-d-announce
                • ... Walter Bright via Digitalmars-d-announce
                • ... Jonathan M Davis via Digitalmars-d-announce
          • Re:... Isaac S. via Digitalmars-d-announce

Reply via email to