[cfe-dev] clang-format chromium ternary operator

Tobias Grosser tobias at grosser.es
Tue Aug 13 08:09:25 PDT 2013


On 08/13/2013 04:37 AM, Daniel Jasper wrote:
> As for structure: With simple cases and all operands having the same
> length, it always looks structured. But consider the case from the original
> code review:
>
> return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ?
>      GetItemPadding() / 2 : 0;
>
> return (ui::GetDisplayLayout() == ui::LAYOUT_TOUCH) ? GetItemPadding() / 2
>                                                      : 0;
>
> I know that a lot of this boils down to personal preference and what
> patterns one is used to, but I find the second version significantly more
> structured. The semi-objective reasons I can come up with are:
>
> a) The alignment and close proximity of ? and : aid in understanding
> that this is a conditional expression and clearly separate / show the
> boundaries of the three operands.
>
> b) A conditional expression is a branch and branches in code are
> usually vertical.

To break this discussion. What about making this an option. Both are 
definitely not uncommon cases, and I am sure people will have different 
options.

In terms of the default for Chromium, I would suggest to default to what
today is the more common practice. Changing this practice is than a 
policy decision which seems to be best communicated (to both 
clang-format and none clang-format users), by suggesting an explicit 
style guide addition on their mailing list either by you or by people in 
the Chromium community who care. If the explicit style guide change has 
been discussed and committed, switching the Chromium style in 
clang-format becomes a no-brainer.

Cheers,
Tobi




More information about the cfe-dev mailing list