[webkit-dev] Bools are strictly worse than enums
Peter Kasting
pkasting at google.com
Fri Dec 3 13:36:18 PST 2010
On Fri, Dec 3, 2010 at 1:28 PM, Eric Seidel <eric at webkit.org> wrote:
> It seems to me, that using bool types for function arguments is strictly
> worse than using an enum. An enum is always clearer and can be easily
> casted to a bool if needed.
>
> doSomething(something, false);
>
> Is much less readable than:
>
> doSomething(something, AllowNetworkLoads);
>
I agree that in general, the latter is better.
Do any C++ gurus have further information to add here?
>
Restricting bools can limit your ability to pass results of one function as
arguments to another. It is plausible to have function A return a different
"enumerated boolean" type than function B takes, for example, if one type is
a special-case of the other. This means you'll need to add explicit ?: ops,
conditionals, or casts, all of which make me more unhappy than the original
bools did.
This is probably an issue in a minority of cases, but it might be reason to
use "should" rather than "must" language here.
PK
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20101203/20e80f76/attachment.html>
More information about the webkit-dev
mailing list