Topic on Manual talk:Coding conventions

Jump to navigation Jump to search

Operator placement on line break

5
Summary by Tgr (WMF)

Relaxed the text, PSR-12 style ("Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both.")

Tgr (WMF) (talkcontribs)

The manual says "The operator separating the two lines should be placed at the end of the preceding line." That's poor advice (start-of-line operators are much easier to scan), and in my experience gets routinely ignored. Compare

return $a > 0 &&
    $a < 100 ||
    $a = 0 &&
    $b > 0;

with

return $a > 0
    && $a < 100
    || $a = 0
    && $b > 0;

for readability. Or

doStuffWith( $foo, $bar .
    $baz, $boom );

We should change the coding style to say start-of-line placement, which is what is used in practice in most of our code anyway.

Krinkle (talkcontribs)

I'd recommend taking it out of this page and incorporating it instead into the pages about specific programming languages as needed.

Jdforrester (WMF) (talkcontribs)

What Krinkle says. For good or ill, we have different conventions for JavaScript and PHP right now on operator placement.

Tgr (WMF) (talkcontribs)

Well, I can take it out from here and add to the PHP page; I'd have no idea what to add to JS though.

Tgr (WMF) (talkcontribs)

Relaxed the text, PSR-12 style ("Boolean operators between conditions MUST always be at the beginning or at the end of the line, not a mix of both.")