[webkit-dev] [Coding Style] Clarification about multiple assignments on one line

Ryosuke Niwa rniwa at webkit.org
Fri Feb 22 14:52:05 PST 2013


On Fri, Feb 22, 2013 at 2:35 PM, Julien Chaffraix <jchaffraix at webkit.org>wrote:
>
> over several reviews, I have been saying that the following line is a
> coding style violation:
>
> firstVariable = secondVariable = 0;
>

That's what I've been doing as well.

For a concrete example, the computePreferredLogicalWidths uses the
> following pattern:
>
> minWidth = maxWidth = max<int>(minWidth, tableLogicalWidth.value());
>
> My justification is that those are 2 statements and thus should be on
> 2 lines per "Each statement should get its own line.".


That's my understanding.

Some people consider that the previous rule doesn't apply to multiple
> assignments on one line and that such code is fine by the book.
>

Strictly speaking, an assignment in C++ is an "expression" but I don't
think that's our intention when we say "single statement per line".
Preferring to the general concept of statement (e.g. see
http://en.wikipedia.org/wiki/Statement_%28programming%29) in programming
languages, an assignment is a statement. It then follows that our rule
of *single
statement per line* mandates each assignment to be on its own line.

- R. Niwa
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20130222/c40689a7/attachment.html>


More information about the webkit-dev mailing list