Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
QuarkJets
Sep 8, 2008

zergstain posted:

Everyone uses vi/vim. I'm sure if we used an IDE, people would just configure the indenting the way they like and we'd still have the same problem. And I know vim can take care of it, but good luck pushing everybody to use the same config.

Edit: As much as I'd love to, reformatting the whole file is frowned upon because I would show up on every line on CVS annotate (primitive is right, but we're working on a Perforce migration, not sure if that will help in this case though).

And now you have also revealed that your team is using CVS

Adbot
ADBOT LOVES YOU

Coffee Mugshot
Jun 26, 2010

by Lowtax

Deus Rex posted:

fix that opening brace and it is perfect

Yeah, why put a space between the `else` and the `{` and not between the `if` and the `{`? I imagine that's a typo.

Unless you were talking about putting the opening brace on the next line. In which case, gently caress you.

evensevenone
May 12, 2001
Glass is a solid.
:colbert: http://google-styleguide.googlecode.com/svn/trunk/cpplint/cpplint.py :colbert:

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Merely pointing out an annoying coding style.

Deus Rex
Mar 5, 2005

Strong Sauce posted:

Merely pointing out an annoying coding style.

You mean the correctly named One True Brace Style?

Malloc Voidstar
May 7, 2007

Fuck the cowboys. Unf. Fuck em hard.
x264 uses
C code:
    if( i_frame_size )
    {
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );
        *last_dts = pic_out.i_dts;
    }
so therefore this is the one true brace style

Strong Sauce
Jul 2, 2003

You know I am not really your father.





Deus Rex posted:

You mean the correctly named One True Brace Style?

Can't tell if I'm being trolled now since you pointed out the annoyance and then claim it is 1TBS. So I'll just state it: the annoying part is no space after if statement, but space after else statement.

Deus Rex
Mar 5, 2005

It wasn't clear to me from your follow-up post what the annoying part of the style you posted was or whether or not you had made a typo.

Pilsner
Nov 23, 2002

code:
	{
		// Do nothing
	}
The worst comment. :argh:

Bonfire Lit
Jul 9, 2008

If you're one of the sinners who caused this please unfriend me now.

Pilsner posted:

code:
	{
		// Do nothing
	}
The worst comment. :argh:
That's fine if that's the body of a loop where the entire work is done in the condition.

a7m2
Jul 9, 2012


What style you use really doesn't matter, as long as you use it consistently. I usually just adapt to the style of the codebase or my coworkers. For example

Jabor posted:

What about if( <expr> ){?
I use this when making a Wordpress plugin.


Isilkor posted:

That's fine if that's the body of a loop where the entire work is done in the condition.
Even then it could at least explain why it's doing nothing.

vvv Hahaha. True, but it pays.

a7m2 fucked around with this message at 11:43 on Jul 9, 2013

b0lt
Apr 29, 2005

Eruonen posted:

Wordpress plugin.

Horror spotted

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Aleksei Vasiliev posted:

x264 uses
C code:
    if( i_frame_size )
    {
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );
        *last_dts = pic_out.i_dts;
    }
so therefore this is the one true brace style

The one truly wasteful and ugly brace style, yes. Opening curly on the same line as if is the way to go and we all know it.

Jewel
May 2, 2009

See, the thing that makes

code:
if ( <expr> )
{
    //code
} else {
    //other code
}
make the most sense is because when you're going to the brace opening, you get your end brace, scroll your eyes exactly upwards, and bam, you're there.

I get that having the brace on the same line is shorter and cleaner in some fashions, but why would you suffer one newline character (which is a space otherwise anyway) to sacrifice easy human readability. I don't get why you wouldn't use brace-on-newline style.

Wiggly Wayne DDS
Sep 11, 2010



What's the consensus on blocks with single line statements?
C code:
    if (i_frame_size) {
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );
    }
or
C code:
    if (i_frame_size)
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );

weird
Jun 4, 2012

by zen death robot

Jewel posted:

when you're going to the brace opening, you get your end brace, scroll your eyes exactly upwards, and bam, you're there.

Scrolling your eyes up a column for an opening brace isn't any easier than scrolling your eyes up a column for not-whitespace.

zergstain
Dec 15, 2005

QuarkJets posted:

And now you have also revealed that your team is using CVS

Is that somehow sensitive information, or something which can be used against me or something?

nielsm
Jun 1, 2009



Having the brace on the same line is bad because
C++ code:
if (some && ridiculously == (long)expression + with->many
    && elements.that(need, linebreaking) {
    makes_the(code, confusing);
    because_these_lines(are, on+the, same(indentation, level));
}
C++ code:
if (you || compare == to_this + condition &&
    with->the(brace))
{
    on_a->separate(line);
    it_s = less(confusing) + where.the_condition(ends);
}

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...

Jewel posted:

See, the thing that makes

code:
if ( <expr> )
{
    //code
} else {
    //other code
}
make the most sense is because when you're going to the brace opening, you get your end brace, scroll your eyes exactly upwards, and bam, you're there.

I get that having the brace on the same line is shorter and cleaner in some fashions, but why would you suffer one newline character (which is a space otherwise anyway) to sacrifice easy human readability. I don't get why you wouldn't use brace-on-newline style.

If you don't have whitespace, yes, I can see where that's easier. However, most of the world can handle auto-indent, so not only do you not gain readability from knowing where the block starts, but you're also decoupling the brace from the if statement, which in my opinion actually makes this LESS readable. When I scroll my eyes up from }, I don't look for a {, I look for another line of code that's at that level of indentation.

Consider what python does; no braces, indentation is its own mechanism of blocking. And it works, pretty well too.

Hammerite
Mar 9, 2007

And you don't remember what I said here, either, but it was pompous and stupid.
Jade Ear Joe

zylche posted:

What's the consensus on blocks with single line statements?
C code:
    if (i_frame_size) {
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );
    }
or
C code:
    if (i_frame_size)
        i_frame_size = cli_output.write_frame( hout, nal[0].p_payload, i_frame_size, &pic_out );

always use the braces even when they are not needed. prevents accidental "oh I'll just add another line of code to this block. welp something is wrong" bugs

nielsm posted:

Having the brace on the same line is bad because
C++ code:
if (some && ridiculously == (long)expression + with->many
    && elements.that(need, linebreaking) {
    makes_the(code, confusing);
    because_these_lines(are, on+the, same(indentation, level));
}
C++ code:
if (you || compare == to_this + condition &&
    with->the(brace))
{
    on_a->separate(line);
    it_s = less(confusing) + where.the_condition(ends);
}

C++ code:
x = some &&
    ridiculously == (long)expression + with->many &&
    elements.that(need, linebreaking)
if (x) {
   ...
}
C++ code:
if ( some &&
     ridiculously == (long)expression + with->many &&
     elements.that(need, linebreaking)
     ) {
   ...
}

Mogomra
Nov 5, 2005

simply having a wonderful time
Scrub code:
code:
if (foo) {
  bar();
} else {
  baz();
}
Elegant Coad:
code:
if ( foo )
{
  bar();
}
else
{
  baz();
}
:downsgun:

That's actually the style I was taught in college. No idea why. They didn't bother to touch on anything important like source control, or a language people might use these days. Maybe that's how everything worked when my professors were "in the business."

Volmarias
Dec 31, 2002

EMAIL... THE INTERNET... SEARCH ENGINES...
Brace style holy wars are the horror here because I'm right and we all know it because it's really a matter of personal preference.

Mogomra
Nov 5, 2005

simply having a wonderful time
The real horror begins when you and your coworkers can't stick to one style. That's pretty much it.

Sagacity
May 2, 2003
Hopefully my epitaph will be funnier than my custom title.
I like apples because they are clearly better than oranges!

ephphatha
Dec 18, 2009




Mogomra posted:

Elegant Coad:
code:
if ( foo )
{
  bar();
}
else
{
  baz();
}
:downsgun:

That's actually the style I was taught in college. No idea why. They didn't bother to touch on anything important like source control, or a language people might use these days. Maybe that's how everything worked when my professors were "in the business."

Not exactly a common concern but this is useful for people with vision impairments as the spaces mean screen readers can read the code without sounding like an aphex twin song.

Pilsner
Nov 23, 2002

Can we at least agree that people who indent with spaces instead of tabs are objectively wrong? It fucks up diff'ing.

That Turkey Story
Mar 30, 2003

Volmarias posted:

Brace style holy wars are the horror here because I'm right and we all know it because it's really a matter of personal preference.

Yeah, I never understood why people get so annoyed. I always stick to whatever the project uses, but really I don't even care if other people on the same project don't follow the convention. Unless you're doing something like never indenting, I just don't see how it makes code much more or less difficult to read.

1337JiveTurkey
Feb 17, 2005

Pilsner posted:

Can we at least agree that people who indent with spaces instead of tabs are objectively wrong? It fucks up diff'ing.

Tabs for indentation, spaces for alignment within an indented block. So the following will appear lined up regardless of tab size:

code:
	String foo = condition1?               "String Literal":
	             condition2 && condition3? stringMethod():
	             /* default */             "Default String";
Everything is logically indented one level and the subsequent lines are aligned to give a tabular appearance.

No Safe Word
Feb 26, 2005

Sagacity posted:

I like apples because they are clearly better than oranges!

This is right-thinking. :colbert:


Pilsner posted:

Can we at least agree that people who indent with spaces instead of tabs are objectively wrong? It fucks up diff'ing.
Except in Python where it's recommended to use spaces, otherwise this is what I go with:

1337JiveTurkey posted:

Tabs for indentation, spaces for alignment within an indented block. So the following will appear lined up regardless of tab size:

Of course having an editor/IDE that corrects the poo poo to your team's agreed-upon standard and a diff viewer that can ignore whitespace is the best way to make it a non-issue.

astr0man
Feb 21, 2007

hollyeo deuroga

Pilsner posted:

Can we at least agree that people who indent with spaces instead of tabs are objectively wrong?

Nope. gently caress tabs, and use a not terrible diffing tool that understands whitespace.

weird
Jun 4, 2012

by zen death robot
I never understood why people being able to decide for themselves how wide indentation levels should be would be a bad thing.

No Safe Word
Feb 26, 2005

VanillaKid posted:

I never understood why people being able to decide for themselves how wide indentation levels should be would be a bad thing.

Have you ever worked on a multi-developer project where people with various notions of "how wide indentation levels should be" are operating on the same code?

That's why.

Set a team standard, enforce it, flog all violators.

weird
Jun 4, 2012

by zen death robot

No Safe Word posted:

Have you ever worked on a multi-developer project where people with various notions of "how wide indentation levels should be" are operating on the same code?

That's why.

Set a team standard, enforce it, flog all violators.

That's what tabs are for.

JawnV6
Jul 4, 2004

So hot ...
fascinating

New Yorp New Yorp
Jul 18, 2003

Only in Kenya.
Pillbug
I just go with "leave the loving VS defaults alone and save everyone a giant headache"

Let's argue about the conditional operator next.

No Safe Word
Feb 26, 2005

VanillaKid posted:

That's what tabs are for.

Oh if you just mean the visual representation of how wide a tab is then yeah whatever, that doesn't actually affect the code so it doesn't matter.

Although it is useful to use the same one across the team to encourage breaking lines at a reasonable length if you don't have a defined standard for line length.

Bunny Cuddlin
Dec 12, 2004
Are you people loving serious

Blotto Skorzany
Nov 7, 2008

He's a PSoC, loose and runnin'
came the whisper from each lip
And he's here to do some business with
the bad ADC on his chip
bad ADC on his chiiiiip

That Turkey Story posted:

Yeah, I never understood why people get so annoyed. I always stick to whatever the project uses, but really I don't even care if other people on the same project don't follow the convention. Unless you're doing something like never indenting, I just don't see how it makes code much more or less difficult to read.

I never got annoyed until I had to finish a product's firmware that had been done in Whitesmith's style. Couldn't tell what lined up with what for the life of me. Had the same problem last time I hosed around with Common Lisp - the parens were fine (my editor did some rainbow thing with em, which was surprising), the indentation just threw me for a loop.

evensevenone
May 12, 2001
Glass is a solid.
Wow, am I glad I don't work with any of you.

Adbot
ADBOT LOVES YOU

Gazpacho
Jun 18, 2004

by Fluffdaddy
Slippery Tilde
I imagine you all on the day of layoffs, sobbing and crying out "How could we fail? WE HAD A CODING STANDARD!"

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply