On Monday, 12 October 2020 at 10:24:44 UTC, FreeSlave wrote:
Let's say I use Flag type named 'myflagname' in API like this:

import std.typecons;

void func(Flag!"myflagname" flag)
{
//...
}

void main()
{
    func(Yes.myflagname);
}

Later I realize that 'myflagname' is a bad name and I want to change it to something else. But if I do so, I break the existing code using this API as Flag with different name will be a different type and Yes.myflagname and No.myflagname won't fit in. I can't use alias as Yes and No relies on string literal. Can this issue overcome somehow? Looks like a fundamental flaw with std.typecons.Flag.

One of the reason's Flag is there is because of what's known as the boolean trap [0]. If someone changes the name of a parameter, that can potentially mean the semantics have changed. Should Flag work then? And if it should, why not straight up bool?

https://wiki.qt.io/API_Design_Principles#The_Boolean_Parameter_Trap

Reply via email to