On 4/3/11 4:38 PM, Jonathan M Davis wrote:
On 2011-04-03 13:13, Jacob Carlborg wrote:
Why is this better? This is just like the pointless aliases you want to
avoid. Why do we even have a bool type in the language if we're going to
replace it with enums all the time?

Andrei has been pushing for this, because it makes the calls to the function
easier to read. If it's CheckDns.yes, then it's clear what you wanted, whereas
if it were true, you'd have to look up whether true meant that it's supposed
to check or skip checking. In some cases, that's more useful than others, but
it's already becoming fairly common in Phobos that such explicit enums are
used rather than bools.

This becomes painfully obvious in calls with more than one Boolean-encoded categorical argument.

auto r = getWidget("widget", true, false);

The topic is discussed in the book Code Complete and I suppose in many other style guides.


Andrei

Reply via email to