For operations on multiple lines, most of the time, i see and use this formatting:
result = object->someValue() +
variable -
function(array) * (arg1 + arg2 + arg3 + arg4);
But i sometimes find this one:
result = object->someValue()
+ variable
- function(array) * (arg1 + arg2 + arg3 + arg4);
Same problem for conditions:
if ((conditionA && conditionB) ||
(conditionC ^ conditionD))
versus
if ((conditionA && conditionB)
|| (conditionC ^ conditionD))
I think the one with operator on newline is more readable, but far less common. Which one would you advise ?
I would like to note that this is not necessarily a matter of personal preference. In some languages, it is objectively better to have one style instead of another.
For example, some languages use automatic semicolon insertion. That means that
could mean something different than
Because the first will be interpreted as
But the second could be interpreted as
That means, depending on which style you use,
acould be set to either -19 or -4;In most languages, it doesn’t matter, and it really is just a matter of personal preference, but in some languages, such as Javascript, which use automatic semicolon insertion, the first style is preferable.