C
C
Crash2019-08-26 18:15:45
Source
Crash, 2019-08-26 18:15:45

Is it correct not to put a line break in this case?

A colleague of ours got into an argument about a single line break. I'll show you with an example.

$data = [];
foreach ($items as $item) {
    $data[] = getStuff($item);
}

It is clear that the code can be simplified using the array_map function, this is not the point.
I insist that an empty line between $data and the foreach loop is needed, because these are different constructs (assigning a value to a variable and a loop).
He says no, because. $data and foreach form a single logical structure - the variable is used in the loop.
His code turns out to be concise and heavy for my perception (there can be many of these variable assignments, there can be long chains of Active Record selections, the loop itself can also take up half a screen or more). He's fine.
Which one of us is right? Please do not delete the question and let it brew.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ronald McDonald, 2019-08-26
@Zoominger

He says no, because. $data and foreach form a single logical structure - the variable is used in the loop.

true.
Are you a team leader? Not? Then your perception is only your concern.

D
Developer, 2019-08-26
@samodum

There is no correct unambiguous answer.
As agreed, so it will be right.
This will be your Code Convention

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question