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
-
I immensely dislike 1.
2 forever.
I feel like this issue has been posted here a few times before. -
@CrashOverride yeah. I'm still on the fence about tab vs. spaces. I just hate for them to be mixed in one file or project. Let it all be spaces or let it all be tabs. Of the same width.
Also, only hipsters true to the creator's will say jiff. -
@corscheid I have said it once and I will say it again. It sucks when creators of things are wrong.
-
Back to OP tho. To those people like @projektaquarius who would rather...
if (foo)
{
bar();
}
else
{
baz();
}
...than...
if (foo) {
bar();
} else {
baz();
}
... my question is, Why? What makes 1 better and what reasons are there to hate on 2? I love 2. (I originally was gonna make a derpy array index out of bounds joke because of 1,2 instead of 0,1 but meh. :P) -
1 is easier on the eyes. More spread out so easier to see and read. I am lazy, I don't want to have to read extra words when all I want to know is where the damn loop starts.
-
@projektaquarius I use newlines for separating blocks and consistent indentation for knowing where stuff starts and ends. I otherwise love the compact nature of whatever the other version is. Why have an if else-if else-if else statement take up an entire page scroll when it could take up a quarter?
-
ZaLiTHkA8418yIt's really interesting reading different opinions on this one..
Personally, I find having the opening bracket on the same line as what defines it's contents makes it easier to see not only where it starts, but also what it does.
Either way, all things considered I also like using ternary operators for the quick if/else checks. Less lines makes for quicker reading. -
I just think you should be able to draw a straight line between each opening brace and each closing brace.
The real question is why do those who like to scrunch up their code not also put the close brace at the end of the last line just like they put the opening brace at the end of the line?
If you want your code scrunched up so that you can see more code at the same time on a screen then why aren't you consistent?
I mean this seriously by the way. This isn't meant as a troll, I would genuinely like to hear the rationale behind it.
I appreciate you do things differently to me, I just don't understand why. It looks like habit because that was how the K&R book did it. But we don't have tiny screens any more, so why continue doing it? -
Enocra6178yDepends on the language I am using. With PHP (and frameworks as symfony, laravel, etc), I will use the first. With java, the second.
-
mrzl4158ySorry... Is this the post where we talk about the difference between tab and four spaces?
-
@Wildgoose
if (foo) {
| bar();
} // put this here for the exact same
reason as you. But instead, I like drawing a straight line between the first character of the statement that opened a brace, to the closing brace. -
@sylflo this. My code all is of the 2nd style but in a php project I'm collaborating on, I'm using 1st style because that's how his code is.
Consistency has precedence.
Mixing them is evil unless the manner of mixing is consistent. e.g., ...
class Foo extends Bar
{
public void baz()
{
quux();
if (moo) {
blah();
} else {
other ();
}
}
}
...such as all class and methods use style 1 but all if, for, while, etc. use style 2. I think this is acceptable.
EDIT: WTF, devRant keeps un-indenting my if statement. -
JamiePed348y@corscheid I think 1 is significantly easier to see where statements begin and end when you see code that has lots of nested if statements - at a glance you can immediately see this tabbed section comes under this if, and this one this if. I also think longer multiline conditional statements look cleaner this way too because it doesn't merge into the code
-
@JamiePed I think 2 looks just as good to my eyes with many nested ifs. I have many files with a whole bunch of these. Indentation is everything. I don't usually have very long conditions. If I ever split mine into multiple lines of the condition, yeah it would probably look a little weird. But as long as it is indented consistently it's not bad. I'm just so used to using and looking at 2, it just feels so strange and a waste of lines just to put only '{' on its own line. Sure you could say this about '}' on its own line, but the point with that one is, it aligns to the first char of the statement. '{' would IMO redundantly also align to the same on its own line.
-
@projektaquarius 2 puts the whitespace in the right spots though. It's confusing having an almost blank line between if statement and content.
-
@TheInitializer I disagree. I find it much more difficult to spot loops, conditionals, etc. at a glance in 2.
-
@projektaquarius with 1, while quickly skimming the code it appears that the if statement is its own line of code (not related to the content) which is confusing.
-
I like JS minifiers 😆 so what do you think about this:
if(s){t.d(z);t.o();}else{t.e(z);f();} -
Andre748y@Wildgoose I like 2, and I don't put the closing brace at the end of the last line because I like having the statements themselves on their own lines.
Plus, if it's a long statement for some reason, you don't have to look at the end of the line to see if it's closed, you just look directly below.
(Sorry for the double reply, the app glitched for me and wasn't loading my replies) -
@TheInitializer That's a fair point - however I always put a blank line after a sequence of close braces, so it doesn't affect me.
We have big monitors now, might as well use them! 🤓 -
Honey! Make me some popcorn and grab me a beer, I'm watching programmers having a brawl on the internet
-
ZaLiTHkA8418y@Khundzaka, minified code doesn't count here, this is about how you write it beforehand..
@Andre, ++ for not only sharing my name, but also mentality. Lol. (: -
@flonach
int main(int argc, char **argv) {
// this one.
}
//Who TF does the following??
int
main(int argc, char **argv) {
/* Are return types not part of
* the function signature anymore?
*/
} -
Mitiko62068yI use the first one so much, that when someone forces me to use the second when writing js, I cry.
Let me see 🙅
undefined