Do you put your braces like this, or do you do it wrong?

Do you put your braces like this, or do you do it wrong?

Other urls found in this thread:

man.openbsd.org/style
github.com/raywenderlich/swift-style-guide
twitter.com/NSFWRedditGif

Putting the opening brace on the same line saves you a line and looks fine unless you're an autist

for function declarations:
int
main(int argc, char *argv[])
{
return 0;
}

everything else:
for (foo = 0; foo < bar; ++foo) {
dosomething();
}

>saves you a line

and why would you need to 'save' a line

void foo()
{
if (bar) {
// bar stuff
}
}

why the fuck do you put return type on it's own line, it's super ugly
if you do it because "sometimes return types can be rly long lol" then you have a much, much bigger problem

Please stop.

kill yourself

I do it right, like this:
void foo() {

}

void foo()
{
whatever ;
}

why? because a terminal screen is only 24 lines in height, and you shouldn't waste them.

(dotimes (i 10)
(if (= (rem i 2) 0)
(do-something i)
(progn
(do-something-else i)
(do-third-thing i))))

Return type on its own line makes the function easier to find using a regex.

man.openbsd.org/style
kernel normal form. use it.

stop pretending you live in some fantasy land where every single terminal is fully compliant to the ANSI standard. My terminal is 72 characters in height because I use a modern fucking terminal emulator with a modern fucking display. The only part of the ANSI standard that should be conformed to in some way is the 80 character width limit.

No

Don't bother. Tons of Sup Forums have done no real programming so they don't realize how obvious of a benefit this is to do.

Not him but I can just as easily put a brace on the same line meaning I get to view more code without scrolling. It doesn't bother me and improves my efficiency.

I'm very particular in how I like my braces, very densely packed.

Sometimes I'll write loops and if statements in such a way that requires no braces at all.

int main(void)
{
unsigned i;
struct {
int a, b;
union {
double c;
unsigned char d[8];
} u;
} arr[] = {
{ 0, 1, 2.0 }, { 3, 4, 5.6 }
};
for (i = 0; i < sizeof(arr) / sizeof(*arr); i++)
{
if (/* cond */)
if (/* 2nd cond */)
/* do thing here */;
}
return 0;

So you get to decide which standard is ok and which ones aren't?

The only language I write using Allman style (in OP photo) is C#. Well, C# for .NET.

Everything else is K&R.

damn that is ugly.

I am pretty new to programming and am learning python. I really don't get why people rag on python so much. Am I missing something? Not having braces all over your code seems nice and clean. Why the brace love? Can anyone explain?

Braces are a necessity in C. White space does not effect how code runs, so style is up to the person writing the code. This is where the debate comes from.

Yes

def main():
print('>using braces')

#define BEGIN {
#define END }
void foo()
BEGIN
...
END

I do it correctly. You do it wrong.
void foo(bool n) {
if (n) {
bar();
}
else {
baz();
}
}


even though I no longer hate python, I still find significant whitespace to be wholly distasteful

see above

void add(int a, int b) {
return a + b;
}

Suggest a C++ naming convention.

```
fn foo(x: i32) -> i32 {
x + 5
}

...

Significant whitespace gets annoying in more complex code. Python makes the situation worse because it is a super opinionated language and often there isn't really a good way to refactor code involving lots of nested control flow ("there's only one way to do it" mentality).

>not 60 character width limit
Never email anyone

shit-tier
if (cond) {
/* ... */
} else {
/* ... */
}
good tier
if (cond)
{
/* ... */
}
else
{
/* ... */
}
god-tier
if (cond) {
/* ... */
}
else {
/* ... */
}

github.com/raywenderlich/swift-style-guide

This.

>hurr my coding conventions are better than Kernighan's, Ritchie's, and Linus Torvald's!

You ignorant MIT niggers need to be removed from the gene pool

>using a regex
We have much better tools for navigating code today.

What is this nightmare holy shit

wuh is a rej ecks?

>[] in function declaration
automatic failure

>and why would you need to 'save' a line
Seeing more code on a single screen improves readability.

I use whatever source -> format does

void add(int a, int b) return a + b;
void mfw() this.Display(thankmelater.jpg);

Somebody should take you behind the woodshed and put you down.
Python is great for throwaway projects but is really annoying to maintain and update.

t. never wrote a large project in python and likes parroting whatever Sup Forums says

are you ok user?

Stop murdering your co-workers, user.

get out.

It's more because code that reguarly exceeds 80-ish characters is probably bad code.
See pic for contrived example.
Unless of course it's Java. You don' have a HashMap myMap = new HashMap(); choice then.

I've always put curly braces on the same line as the declaration.
However, a guy I work with puts them on the line below as seen in OP.
I find it helps a lot when folding code, as the declaration will be on one line and the folded code will be below.

At the end of the day it really does not matter.

def foo():
...

because I'm not an autistic neet

you animal.

Always
int something(){
code
}

Python is bae but happens

void foo() {

}

or go home

use tagging system you retard

void foo(){inst1;inst2;instN;}

Write like a man.

Is it true that only expert programmers who wrote thousands of fizzbuzzes argue about where to put braces?

>write code
>use the IDE's auto-formation
I don't care. As long as it's consistent.

Yes. Everyone else just sticks with K&R braces unless there's a reason to use something else.

I noticed it's more common for people who write shit code to use braces on the line below.

void
foo(
int x,
int y
)
{
return
"void return";
}

>Python is bae but happens
The point of that pic is that if your lines are starting at several indentation levels deep then something is wrong with your code

(define (foo) ...)

void foo(){bar(){...}}

And the issue with Python is that indentation is obligatory, so sometimes things like those become inevitable.

the only proper way
bix() {
nood
}

That sounds like something my school bully would ask
>are you retarded or fucking retarded?

kek

int main()
{ print("nigger");
return 0;
}

Found the Pascalfag.

This compiles in python 3 apparently, ... is a valid statement

>compiles in python
brap

filecopy(fp) FILE *fp; { /*copy file fp to stdout */
}


all of you are heretics

ansi shills please leave itt

>What is bytecode
It's compiled before being interpreted, numbnuts

>not using the interpretator
braaapfst

>>not using the interpretator
>braaapfst
I see no difference between the two statements

go fmt is the One True Style.

in Go I obey gofmt
in Python I don't use brackets
in C I follow man 9 style on OpenBSD and/or Plan 9
type_to_return
main(int arg, char *argv[])
{
/* body */
}


but on same line everywhere else. This is habit from K&R C style declarations:
int
main(argc, argv)
int argc;
char *argv[];
{
/* body */
}

I don't really get it and it looks pretty bad. Nice anime girl though.

thats what C used to be like before ansi r*ped it

it's not like languages have established standards for where to put braces and naming conventions or anything like that

procedure foo is
begin
...
end foo;

you are actually the dumbest person in this thread lmao

I see someone learned python first

nope

>Prototypes should not have variable names associated with the types
Why not?

> hurdur whitespace is for the compiler right guys
> it makes it run faster
Isn't there a python class you should be failing somewhere?

Yes, the person who writes the code is permitted to choose their format.