Top or bottom, Sup Forums? Which do you prefer?
Brackets Placement
I'm relatively amateur and used to prefer the top one, but the longer my code gets the more I like the bottom one
Bottom - unless you're retarded.
[CODE]int
main(void)
{
if (1) {
...;
...;
}
}[/CODE]
>functions
top one.
>code blocks inside functions
bottom one UNLESS the code is really long and nested multiple levels and the extra white space increases readability.
Neither.
Top is C# only.
Bottom is Java only.
Everything should be
function()
{
if(1 == 1) {
for(;;) {
}
}
}
Functions get whole line brackets, everything inside them gets layered brackets.
I use both.
At least you can feel like you've written a third more code if you do the above.
Top is unnecessary. Having the open bracket on its own line only wastes space. Having the closing bracket on its own line is good practise for readability.
Also both should be } else { for the ifs, faggot.
None. Pythonistas don't need brackets.
I feel like the top is more readable, because everything feels more grouped together. Especially with nested loops and if statements.
patrician taste my friend
(if condition
then-form
else-form)
Or this:
int
main(void)
{
for (;;) {
no blank lines;
}
for (;;)
{
this needs some;
blank lines;
}
}
>wasted space
it's not like they have to cut down trees for each empty line
Bottom is just better, saves space and it's more readable.
Depends on if I'm being paid by LoC
I dont know why
But I do bottom for functions/methods
But top for the rest
top is literally how to spot a shit programmer
blah function()
{
for(iterations and longer ifs){
}
if(one or two statements) {...;...;}
}
Not really. This would be the readable version:
public void RefreshCatalog()
{
if (IsCacheValid)
ResetFilterToDefaults();
else
RepopulateCatalogFromService();
}
However, those names are shit, so:
public void refresh_catalog()
{
if (valid_cache)
filter_defaults();
else
catalog_repopulate(FROM_SERVICE);
}
FROM_SERVICE would be part of an enum. valid_cache should be a function.
definitely the bottom
Best style.
Bottom one is easier to diff.
> Job interview
> Interviewer says salary is 500k
> Make your own hours
> Don't even have to code just sync repos all day
> BTW we make new lines for every fucking curly brace
> Me: FUCK OFF
We are talking about brace placement, not naming convention.
Having said that refresh_catalog() is better.
inconsistent
based
Top. Bottom is usually a sign of a trash programmer who thinks they're clever.
Also acceptable.
I am disgusted with you
I never understood why people would write the one on the bottom. Shit's completely unreadable
top for C(++)
bottom for Java
disgusting
public static void main(String... args) throws Exception
{
System.err.println("no")
}
Top
I used to be
{
}
When I started VB
But then I found {
}
Is easier when I started Java
#define RefreshCatalog() IsCacheValid ? ResetFilterToDefaults() : RepopulateCatalogFromService()
FWIW both Dennis Ritchie (invented C) and Bjarne Stroustup (C++) both put brackets on the same line in their code examples.
Runtime slows o2 for each whitespace
gofmt
Like this desu fampai
> Job interview
> Interviewer says salary is $1mil
> Make your own hours
> Don't even have to code just sync repos all day
> BTW no white space for code blocks
> Me: FUCK OFF
void isEven (int i) {
if (i % 2) {
printf("That number is odd");
} else {
printf("That number is even");
}
} void isOdd (int i) {
isEven(i-1);
}
Linux style guide.
For opening brackets:
Function brackets go on their own line.
Everything else on the same line.
For closing brackets:
else, else if, and the while in a do...while are on the same line.
Everything else on it's own line.
top for c (if the block is big I can better spot where it begins), bottom in the rare case of js
But I also love the ternary operator so maybe I am retarded
Depends on the language, I go top for C# and bottom for others
Starting to learn C. Bottom ones.
whatever the project specifications say
No brackets at all. If your ifs and fors have more than one statement, it should be extracted.
Keep your functions clean.
} else {
anyone who does this deserves the chair
gofmt doesn't let me chose. It's better this way.
this is exactly what I do
Agreed.
> Function is called isEven
> Returns void
What did he mean by that?
Gross.
By returning void it leads to this kind of answers > isOdd(3)
> calls isEven(2)
> prints "That number is even"
> 3 is even??
> Always print wrong answers
> WOW, seriously, wow.
This is respectable, but I'd take a more detailed approach.
The more integral or individual the line, the more space it deserves, visually. A function name needs to be easily separable because that's the sort of thing you'd care about if you were quickly skimming the file. Interior if statements, ones that don't really have too involved of a purpose can be compressed. I'll often use one-liners or ternaries when it's something that doesn't deserve a lot of attention.
The correct answer would be "it depends on the programming language conventions"
As for what I think, top is cancerous and bottom is the only way to go.
Which language allows to invoke void functions on a ternary?
Bottom because I do a lot of work on a shitty laptop with a teeny tiny screen, so space is precious.
I don't really like it, but the habit is so ingrained at this point that I'll probably never break it.
Top - unless you're retarded.
How so?
brackets are for children and nu-males
chads use a language that has end's
Whatever the IDE I'm using defaults to
>TOP
Clean and readable. Casual friendly.
>Bottom
Not so clean, not so casual friendly.
>brainlets using brackets
Lmao, pythonista here, come over and check out our subreddit /r/python.
No need for brackets.
If you do come, try to keep the swearing down. Racism will result in a ban.
Those are braces
bottom, had a code nazi as my intro c++ course a while back who insisted on top.
Fuckin forced me to use top unless i wanted to lose 40% per assignment.
What? Unless you want to return the value and not just print, making it void doesn't do shit, retard.
from __future__ import braces
>>/Jewddit/
go back to your trash plebbit and stay away from Sup Forums you fucking faggot.
...
Why? It shows clearly the extent of the block, right?
I'm not being a tit, it just seems that's the clearest way to write it without the clutter of additional lines for one brace.
if you use anything else than OP's version 1 you're literally pajeet-tier
neither. I use the all superior whitesmith style. It effortlessly allows you to see each distinct block of code.
Here's a quote from O'Reilly's "The C Programming Language":
[quote]
The position of braces is less
important, although people hold passionate beliefs. We have chosen one of several popular
styles. Pick a style that suits you, then use it consistently.
[/quote]
this to be quite honest with you family
if )1( }
{
else }
{
picrelated is comfy when u get used to it
kek'd
thats how I feel about it.
kys
this this this
torvalds suggested using the same for the kernel iirc
Bottom. You can argue tabs vs spaces all you want, whatever I'll conform to your standards, but I'm not working on anything that uses the top format for braces.
Get real the white board walked in and you couldn't sum primes to 2 million
He implied, that isEven reads like a boolean function, but returs void. This will confuse the reader. (See isOdd impl.) It should be renamed to printParity or something like that.
We can argue about braces, but it won't fix the problem, that most of the programmers just suck at creating readable code.
public class FizzBuzz {
public static void main(String[] args) {
for (int i = 1; i
my man.
only brainlets cant comprehend this kind of formatting.
C#, C++, C - top
JS, TS, Go - bottom
...
if
(
true
)
{
do_something
()
;
}
else
{
do_something_else
()
;
}
Beautiful.
How do you configure it though?
>and the extra white space increases readability.
M8 don't switch coding conventions for that. Just add a blank line.
this
Top because that's how I learned c++ and I'm used to it. It also makes more sense to me that the opening brace is visible and lines up with the closing brace.
This is the real correct answer though. Just fucking pick one and use it. Both are valid for different reasons.
int isOdd(int i) {
return i%2;
}
I used to think this was the best style until I started working on larger projects.
It quickly becomes hard to navigate and maintain with large files. Doesn't seem like it would, but I ended up switching to basically this:
...
>has to write a function for every type
Consider suicide.
wtf, lispfags should use a margin
this is great.