[webkit-dev] WebKit style for switch statement

Eric Seidel eric at webkit.org
Wed Jan 20 14:23:06 PST 2010


No, we leave out the default:  That allows compilers to warn when
cases are missing.

Any time you see a default: in a WebCore switch, it's sub-optimal in my opinion.

-eric

On Wed, Jan 20, 2010 at 2:19 PM, Yong Li <yong.li.webkit at gmail.com> wrote:
> As everyone may know, current webkit style (at least for most source code)
> for a switch statement is like this:
>
> switch (var) {
> case valueFirst:
>   ...
>   break;
> ...
> case valueLast:
>   ...
>   break;
> default:
>   ASSERT_NOT_REACHED()
> }
>
> This looks good. But some compilers may give a warning like: "statement is
> unreachable". Disabling this warning is a solution. But this warning can
> be helpful in some cases.
>
> So, how about changing the webkit style to this?
>
> switch (var) {
> case valueFirst:
>   ...
>   break;
> ...
> default:
>   ASSERT(var == valueLast);
>   ...
>   break;
> }
>
>
> -Yong
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev
>
>


More information about the webkit-dev mailing list