Flag proposal

Timon Gehr timon.gehr at gmx.ch
Sat Jun 11 14:58:38 PDT 2011


Jonathan M Davis wrote:
> ...
> The complaints about this generally seem to be one of these:
>
> 1. Dislike of the yes/no enum idiom in the first place. Regardless of how Flag
> does it, it's a problem, because it's promoting an idiom that the poster
> dislikes in the first place.
>
> 2. Flag!"enumName".yes and Flag!"enumName".no are ugly.
>
> 3. The use of a template such as Flag results in ugly error messages when it's
> mistyped. EnumName.yes gets _much_ better errors when mistyped than
> Flag!"enumName".yes.
>
> 4. Flag is seen as a narrow attempt at named arguments which would be far
> better served by actually implementing named arguments.
> [snip.]

5. The approach is too sophisticated and does not pull its own weight.
Imagine what you would have to explain to somebody new to the language who
wondered how Yes.sortOutput works... instant turn-off!


What about allowing anonymous enums in parameter lists? Unfortunately that would
be a language feature. :)

T someAlgorithm(..., enum {unsorted, sorted} sortOutput);

To call: someAlgorithm(..., sorted); / someAlgorithm(..., unsorted);



Timon


More information about the Digitalmars-d mailing list