Flag proposal

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Jun 11 20:27:55 PDT 2011


On 06/11/2011 03:52 PM, Nick Sabalausky wrote:
> "Andrei Alexandrescu"<SeeWebsiteForEmail at erdani.org>  wrote in message
> news:it07ni$1pvj$1 at digitalmars.com...
>>
>> Anyway, that was the first thing "grep yes std/*" found. Let's see the
>> next one:
>>
>> /**
>> Specifies whether the output of certain algorithm is desired in sorted
>> format.
>>   */
>> enum SortOutput {
>>      no,  /// Don't sort output
>>      yes, /// Sort output
>> }
>>
>> This already is very unpleasant because "certain" is as imprecise as it
>> gets. Plus one for Flag, I hope you agree.
>>
>
> Flag -= 1
> s/output of certain algorithm/output of an algorithm/ += 1
>
> That one-word doc change makes it all perfectly clear.

Not at all. The typo in the original text must have confused you: it 
should be "certain algorithms" because SortOutput is used in four 
distinct algorithms (one of which has two overloads). Grep std/algorithm.d.

Flag += 2

> Also, since you're in favor of Flag, I think you'd agree with me that the
> doc comments on the "no" and "yes" values are unnecessary and can be
> ditched. Which makes the whole idiom this:
>
> enum SortOutput { no, yes }

This exact kind of argument has been made in 1995 in favor of STL 
algorithms that require defining a struct outside the current context. 
The cost of adding one extra symbol turned out to be a fair amount more 
unpleasant than it was initially though.

Assessing that the boilerplate in this case is one line would be missing 
that important aspect.


Andrei


More information about the Digitalmars-d mailing list