Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
@scroach actually, real devs don't care. As long as it runs with minimal errors. That's why there's so much spaghetti code out there.
-
Surely it depends on the language you're using? If I'm doing c# they go one a new line, if I'm doing JavaScript they don't.
-
coolq48267yPersonally I like to have my curly braces on new lines, but that's just my preference.
A teacher should not push their preferences into their students. -
zankar20757yI use both, depends on the situation. But I don't get the people (mostly teachers) who are trying to force something into their students i.e. code formatting.
That proves that those teachers are just a bunch of incompetent idiots unable and unwilling to learn a single thing. -
Let's break convention and used a mixed-form.
Whenever we need braces, we shall randomly choose where to put the opening brace. -
shdw9507yThere is an xSR for each language (first letter of the language being the x). When I read PHP code that is not PSR compliant it's often not very easy to understand nor fast to read. There is also a JSR (Java) etc and surprisingly many developers haven't come across these. At the risk of sounding like an old pessimist, the good old "braces is a personal taste" is just not a thing anymore.
-
scroach13437y@shdw PSR2 states "Code MUST use 4 spaces for indenting, not tabs" - no sir, i will not accept that!
-
scroach13437y@shdw so how does it look different and on what system? every ide since like decades supports a preference where you can set "how many spaces wide" a tab should be displayed. and i just always found it annoying to navigate through code with spaces cause e.g. you got to hit the arrow key 4 times instead of once
-
shdw9507y@scroach there has been quite a lot debate on this matter. The fact that you are able to adjust your tab width in each IDE/system is the exact reason for using standard spaces instead. Some people argue that they prefer to be in charge of their own layout which is fully understandable. The PSR reflects the majority of developers opinion on matters like tabs, braces etc and the agreement of the majority is to use four spaces (hence the standard: what most people prefer). When I navigate a code base I rarely use the arrow keys alone when jumping between blocks or sentences. I usually use ctrl+arrow or ctrl+e/a. Don't know if that is any better for you to handle the "four-spaces-annoyance"?
-
MatPag587yI think every language has its own style for braces. You should follow this convention and not trying to apply a style to other languages. For example Java has braces on the same line while C# not.
-
@runfrodorun I must respectfully disagree. I find readability much higher when the curly brace is on the same line. Otherwise they look like two separate bits of code.
-
I did this once in my practicals
function name(){
...
}
During verification she asked me to change it and commented that I was trying to save space. Was so annoying as fuck. She even decreased my score because of it. -
I might get shit for this but i always use
Foo () {
}
Unless i have a long function or a function with nested loops etc
Foo ()
{
For () {
.}
}
Because with nesting sometimes finding which brace corresponds to which block is a bit obfuscated -
wizzzard8137yRule #1 - Consistency is King...
Be consistent throughout your project no matter which coding style/indentation style you choose to use.
Rule #2 - When in Rome...
When you join someone else's project, adopt their style for any work done for said project.
Rule #4 - Deception...
There is no rule #3
That said, I prefer Allman style indentation, though with different use of spaces:
void DoSomething( int x, int y )
{
if( x > y )
{
Console.WriteLine( "X wins!" );
}
} -
If you think it's OK to put { on a new line, try this JS code:
return {
foo: "bar"
};
And this code:
return
{
foo: "bar"
};
Once you catch that bad habit, you'll lose hours trying to figure out why a function is returning undefined.
Again, I'm not saying anything about the function, I'm saying that writing it that way (with } on a new line) creates a habit. -
love how people come up with the "having one character in a line is bad" ... it's not like you're paying 100$ for that char... and you can minify your code if it's not compiled after you're done
Related Rants
A teacher who came to see if I'm programming correctly asked me to start my curly braces on a new line like
F()
{
}
because where the fuck did you learn the other version
F() {
}
" that's just wrong"
undefined
wk66