Suppose you are calling a function, where there's clearly a need to break down the statement into few lines, for readability's sake. However there are at least two way to do it:
Would you do this:
return render(request, template,
{
'var1' : value1,
'var2' : value2,
'var3' : value3
}
)
Or would you rather do that:
return render \
(
request, template,
{
'var1' : value1,
'var2' : value2,
'var3' : value3
}
)
Or, please suggest your own formatting. Please also list reasons why would you use a particular formatting and what's wrong with the other one.
Thanks
Allman styleThis style puts the brace associated with a control statement on the next line, indented to the same level as the control statement. Statements within the braces are indented to the next level.
K&R style minimises the amount of vertical space which the code consumes, while maintaining that the syntax of the control structure itself does not share lines with its contents. Ensuring a control structure doesn't share lines with its content is important.
We strongly recommend you format your curly brackets following Java conventions: Do not put a new line before an opening curly bracket. Always start a new line after an opening curly bracket. A closing curly bracket should always belong on a separate line, except for else statements.
In many computer programming languages, parentheses have a special purpose. For example, they are frequently used to enclose arguments to functions and methods. In languages such as Lisp, parentheses define an s-expression. In regular expressions, parentheses are used for pattern grouping and capturing.
I'd probably do:
return render(
request,
template,
{
'var1' : value1,
'var2' : value2,
'var3' : value3
}
)
I would keep the bracket on the same line, so that searches for render(
work. And because I find it clearer. But I'd put all the arguments on new lines.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With