[webkit-dev] Bools are strictly worse than enums

David Hyatt hyatt at apple.com
Fri Dec 3 13:37:18 PST 2010


On Dec 3, 2010, at 3:33 PM, Darin Fisher wrote:

> 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);
> 
> 
> Do any C++ gurus have further information to add here?  Is my (simple) analysis here incorrect?  If not, seems we should forbid boolean values in multi-argument methods/constructors in our style and add checks to check-webkit-style to prevent further introduction of these confusing callsites.
> 
> -eric
> 
> 
> I was under the impression that this was already an encouraged style in WebKit code.  At least, I really like that is makes call-sites more self-documenting.

The only exception I would make to this rule is if all the call sites use variables and never pass in raw true or false.  In that case there's no loss of readability, and whether you use an enum vs. a bool is irrelevant.

I think in general the rule should be "Keep your call sites readable, and convert to enums if you find that the call sites are becoming inscrutable."

dave
(hyatt at apple.com)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20101203/f7160436/attachment.html>


More information about the webkit-dev mailing list