Coding Style: Curly Braces

Started by
72 comments, last by kunos 10 years, 11 months ago

Just a minute. I'm working on a solution for this.

[attachment=14978:thunderdome.jpg]

void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.
Advertisement

Oh, no need. We're having quite a civilized discussion here. :)

Direct3D has need of instancing, but we do not. We have plenty of glVertexAttrib calls.

Oh, no need. We're having quite a civilized discussion here. smile.png

Well that is exactly the problem which he is trying to solve, right? FIGHT! WOHOOOO! :p

The reason this style is bad is because it's inconsistent and doesnt align the matching braces. The opening brace is at the end of the first line of the code block, while the closing grace is inexplicably on its own line after the code block. No consistency whatsoever. Since you're aligning the end-brace with code instead of an open-brace, that open brace might not even be there and you'd never notice until the compile fails, which might be a significant amount of time wasted on big projects.

It's not bad. It's just not the style you use. The end brace matches the block owning statement. It reads very naturally to people who prefer that style.

And how exactly do you know what style I use?

I tried to make an argument based on logic, which if you actually read what I wrote, is why I gave concrete reasons for my claim. I didnt just say "this style is bad, period". Now, you can disagree with me, but please stop implying that what I'm saying is just because I'm biased. That's just disrespectful. Also, trying to tell me what I do or dont do is disrespectful. You have no idea what style I use, or have used in the past, or will use in the future.

Yes, I understand that a certain style is easier to read for people who are used to that style. I probably even said something like that in a previous post. But I'm not arguing that you should change your style, I'm arguing for what style is technically better, so that people starting out will adopt that style. A lot of people seem to take criticism of their personally preferred style personally, even if it's not intended as personal.

Personally, i prefer this:

if(something){

...

} else {

...

}

It's more compact and i guess im used to it.

Also, i hate spaces between the ) and { , after the ( and before the )... it's rather pointless...

i soooo hate this freaking new tendency it make me want to stab every programmers who does it when i download code rofl...

... and yes, i love triple dots ^o^

Consistency has to do with picking one style and sticking to it throughout the code base. It has nothing to do with braces being on the same indentation level.

Consistency also has to do with how you format your code. If you put your braces in one place part of the time, and in another the rest of the time, then you're not being consistent. Alignment is part of that because it creates a pattern, which is what I was trying to explain above... before people starting getting offended by me criticizing their "preferred" style. Patterns are about consistency. Yes, putting the braces in different parts of the code based on whether they are an opening or closing brace is also a pattern, but it's a more difficult pattern to spot.

I am offended that you use a style other than my own so let me twist your logic and write a totally out-of-context example:

if(f1()) {
if(f2()) {
if(f3()) {
/*...*/ } } }

Let me try to offend you even more by throwing all logic out the window and pretend the concept of indentation levels just doesn’t exist, even though I use them myself when scanning for matching braces:if(f1()) { if(f2()) { if(f3()) { /*...*/ } } }

I'm not offended by others making arguments for their preferred style, but apparently you are. What does offend me is when someone implies that I'm being disingenuous in my arguments, and that what I'm saying is simply based on my bias. In fact, I'm starting to see a pattern here. I post an argument for why a certain style is technically better, and then all those who dont use that style rush to accuse me of being biased, and hence my argument isnt valid. Nice!

Careful, someone might misunderstand that you are close-minded and stuck in your own ways, justifying them as “the best” based solely on the fact that it is what you prefer.

Of course, we all know better than that, right? wink.png

So I'm not just biased and disingenuous, I'm also closed-minded? So many ad hominem attacks... my post must have really hit a nerve.

I wonder what this thread would be like if people were talking about Racket/Scheme instead:
#lang racket
 
{define {foo bar}
  {if {= 5 bar}
      {display "It was 5\n"}
      {if {not {= 42 bar}}
          {display "It was something else\n"}
          {display "It was The Answer\n"}}}}
 
{foo 15}
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

words


lol

Get in the dome.
void hurrrrrrrr() {__asm sub [ebp+4],5;}

There are ten kinds of people in this world: those who understand binary and those who don't.

Consistency also has to do with how you format your code. If you put your braces in one place part of the time, and in another the rest of the time, then you're not being consistent.

Luckily, I always put opening braces at the end of the line and closing braces on their own line, making me quite consistent.

before people starting getting offended by me criticizing their "preferred" style.

Basically I can just stop here since you completely missed the point.

No one really cares enough to be offended, and many people are on your side.
So why were you singled out?
Because those people took an “it is my opinion” approach while you simply stated “X style is best” and “Y style is bad”.

This style is the best one.

The reason this style is bad

See?
All styles are a matter of opinion, so stop stating things as a matter of fact, or I will single you out harder next time. Trust me, I have been holding back in lieu of happy days and things going my way—getting married, getting a raise, getting back my motivation for my job (overcoming the phil67rpg disease) and technical work and my book, etc.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

I wonder what this thread would be like if people were talking about Racket/Scheme instead:


#lang racket
 
{define {foo bar}
  {if {= 5 bar}
      {display "It was 5\n"}
      {if {not {= 42 bar}}
          {display "It was something else\n"}
          {display "It was The Answer\n"}}}}
 
{foo 15}

o man, that's just insane. is that actual regular syntax, or are you intentionally making it weird?

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

This topic is closed to new replies.

Advertisement