def foo():
[…]
@nixCraft oof.
Depends on the language and standards of the rest of the code base for me…
I usually prefer 1, but 2 is sometimes a bit easier to read.
Colored brackets in the IDE are great though, makes is so easy to see what’s paired to what.
@nixCraft
Depends on the language each one has its own coding style, some allows you to do what you want, others like Go will give you an error if you dont put the brackets where 'it belongs'
I only care that the style is consistent in all the project
`foo() {` definitely. Seeing just a random '{' on a line by itself seems off for some reason.
When more arguments are needed for the acceptable line width,
`foo(
...
) {`
foo() 80%
bar() 18%
doo() 2% (for those💡moments)
@nixCraft neither, it should be
void foo() {
// code here
}
fubar()
@nixCraft I'm baz( ) 😉 which means foo( ) but my closing bracket has same indentation as opening bracket.
Everything else is wrong .
@nixCraft in C,
void
bar()
{
}
Function name is always bound to the beginning of the line, braces always align.
@nixCraft Method 1.
void foo() {
/* code */
}
Because a professor in college once told me that method 2 is used in college textbooks as a way to make the book longer and therefore more expensive. And that stuck with me.
But if we're being COMPLETELY honest....
def foo():
pass