Flag proposal

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jun 10 15:54:35 PDT 2011


On 6/10/11 5:14 PM, Steven Schveighoffer wrote:
> On Fri, 10 Jun 2011 16:21:59 -0400, Andrei Alexandrescu
> <SeeWebsiteForEmail at erdani.org> wrote:
>> There is general agreement (which includes myself) that a language
>> feature is nicer than Flag,
>
> Yes.
>
>> and that Flag is nicer than the current state of affairs.
>
> No. Flag!"KeepTerminator".yes is much worse than KeepTerminator.yes. And
> Flag!"KeepTerminator" keepTerminator is just, horrendous, in
> documentation *or* source.

https://github.com/andralex/phobos/commit/84c75336a4ef04b4c3b1924d7ac9329e744ab8e7

> If the rote creation of boolean enums is a problem, why not a mixin?
>
> template Flag(string name)
> {
> mixin("enum " ~ name ~ " : bool { no = false, yes = true }");
> }
>
> mixin Flag!"KeepTerminator";

Because you still need to define it separately from use.

>> This is no surprise because a specialized language feature will
>> _always_ be better than one built from tools offered within the
>> language. It's like God vs. human.
>
> I think the debate is more about how this solution is a step in the
> wrong direction more than it's not as good as a real solution.
>
>> So the crucial question is whether a language change is warranted.
>
> If the options are Flag or a language solution, the answer is yes. I'd
> much rather keep things as they are than have Flag!string.

Keeping things as they are fosters awkward duplication or coupling.


Andrei


More information about the Digitalmars-d mailing list