Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-4041-

C++ writing style

Name: vexed 2012-03-25 19:54

When writing code (in C++ particularly), where do you put your curly braces?

ex:
int main()
{

}

OR...

int main(){

}

which do you think is better? clearer? more professional?

Name: Anonymous 2012-03-25 20:11

From a professional point of view they're both good. Personally, I prefer the first one. Looks more balanced, I like that.
At my uni they told us to use the second one though.
Either way, it doesn't really matter.

Name: Anonymous 2012-03-25 20:17

int main(){

}


ONLY.

Name: Anonymous 2012-03-25 20:37


#include <lolnoob>

int main() {
    if(1) {
        printf("All the way to schfifty-five.\n");
    } else {
        printf("It's perfect K&R, except there's no space between control structures and the following parenthesis.\n");
        printf("This is my Achilles heel.\n");
    }
}

Name: Anonymous 2012-03-25 20:38

// also, not putting spaces around things makes you an illiterate assmucher and/or engineer

Name: Anonymous 2012-03-25 20:39

// as does putting in too many spaces

Name: Anonymous 2012-03-25 20:46

>>3 This.

Name: Anonymous 2012-03-25 20:47

Do you write:

if( (test1) || (test2) )

or do you write:

if((test1) || (test2))

or do you write:

if((test1)||(test2))

or do you write:

if( (test1)||(test2) )

or do you write:

if( ( test1 ) || ( test2 ) )

or do you write:

if(( test1 ) || ( test2 ))

or do you write:

if(( test1 )||( test2 ))

??????

Name: Anonymous 2012-03-25 20:51

>>8
if((test1 )|| (  test2) )

Name: Anonymous 2012-03-25 20:58

where's the ``faggot way"?!

Name: Anonymous 2012-03-25 20:59

I use both, usually at the same time

Name: Anonymous 2012-03-25 21:01

>>8
i write (o )( o)

Name: Anonymous 2012-03-25 21:02

if((test1)||(test2))
{

}

Name: Anonymous 2012-03-25 21:04

if(test1 || test2) {
 ...
}

Name: Anonymous 2012-03-25 21:14


if ( ( test1 ) || ( test2 ) )
{
   ...
}

Name: Anonymous 2012-03-25 21:18

Tabs or spaces?  How many?

Name: Anonymous 2012-03-25 21:23

>>16
Always use spaces. The size of tabs can vary greatly between different IDEs/editors.
I always use 4 spaces.

Name: vexed 2012-03-26 0:00

>>2

I know it doesn't matter. Just wondering what people prefer and why. Mostly in an attempt to avoid programming assignments.

Name: Anonymous 2012-03-26 0:08

if(OP==FAGGOT) {
/* use braces like this */
}
else
{
/* use braces sanely */
}

Name: Anonymous 2012-03-26 4:36

>>17
Then tabs are superior, because in most IDE you can change how much are tabs.

Name: Anonymous 2012-03-26 5:32

>>20
2012
still using IDE
ISHYGDDT

Name: Anonymous 2012-03-26 5:34

>>20

lrn2editor/IDE.

Always make your editor expand your tab characters into spaces.
 
see: expandtab.

Name: Anonymous 2012-03-26 5:44

>>1
The first one for function bodies, the second for anything else.

Name: Anonymous 2012-03-26 9:17

What >>23 said, except #1 for structs and union definitions as well, they're not lexical scopes.

Name: Anonymous 2012-03-26 11:44

>>24
Are you just plain stupid? Or are you trolling?

Name: Anonymous 2012-03-26 11:48

>>24
More to the point. What about the following.


#include <"foo.h">

void getData(void)
{
  struct you are;
  are.stupid = 1;
  are.gay = 2;
  are.retarded = 2;
}

Name: Anonymous 2012-03-26 11:54

>>26
<"foo.h">

You're retarded.

Name: Anonymous 2012-03-26 11:56

>>27
I'm not the faggot who is trying to assert that structs and union definitions aren't lexical scopes. Now hush up and go help another customer.

Name: Anonymous 2012-03-26 11:56


int
main()
{
  return 0;
}

Name: Anonymous 2012-03-26 11:58

>>29
And how does that relate to the current topic you idiot?

Name: Anonymous 2012-03-26 11:59

>>28
That doesn't make you any less of a faggot

Name: Anonymous 2012-03-26 12:00

>>30
It relates to the original topic, go derail another thread

Name: Anonymous 2012-03-26 12:02

#include <stdio.h>

#define DEFUN(type, name, params, code) type name params { return code; }

DEFUN(int, main, (),
  (puts("Hello, world!"),
   0))

Name: Anonymous 2012-03-26 12:03

>>32
Go scrub another toilet princess.

Name: Anonymous 2012-03-26 12:03

>>34
Go scrub another torah you mental goy.

Name: Anonymous 2012-03-26 12:15

>>4
ENHANCED
#include <lolnoob>

int
   main(
    )
  {
    if(
     1
     )
   {
;    printf(
      "All the way to schfifty-five.\n"
      )
;   }
    else
   {
;    printf(
      "It's perfect K&R, except there's no space between control structures and the following parenthesis.\n"
      )
;    printf(
      "This is my Achilles heel.\n"
      )
;   }
   }


This style brings several benefits to an ENTERPRISE QUALITY project, among which are:

Scalable statement addition and by the use of canonicalized statement initializers as well as terminators (;). Thus you can always know where a statement begins and where it ends.

Mandatory braces for readability, enforced by the prior rule.

Enhanced formal argument injection, as per mandatory line-separation of parameters (not shown here).

Visual hierarchy of braces. Opening braces are always more important than closing ones, thus they are on space further to the left.

In conclusion: the revised /prog/ coding style brings benefits to ENTERPRISE projects by leveraging the visual recognition competencies of the team members and enforcing itself by the means of industry-standard tooling.

Name: Anonymous 2012-03-26 12:59

I think I just puked a little

Name: VIPPER 2012-03-26 13:19

int main () {
if ( (test1) || (test2))
return shit (shit);
}

Name: Anonymous 2012-03-26 13:50

OP you do it like this:

void
foo
(
int
bar
)

{

//start here


//end here

}

obviously. Now adays space isn't a problem, we have big monitors. so it's important that we pointlessly waste that space as much as possible

Name: Anonymous 2012-03-26 14:15

int
main (c, v)
int c;
char *v[];
{
  //The only valid style
}

Name: Anonymous 2012-03-26 14:35

return_type
function(
    arg1,
    arg2,
    arg3,
)
int arg1;
double arg2;
void *arg3;
{
    if(
        style != this
    )
    {
        style = shit;
    }
}

Name: Anonymous 2012-03-26 15:25

I raged quite a bit reading a lot of those.

That's interesting to notice, how you can come to like or dislike fucking writing styles.

I enjoy K&R style but I use GNU style.

Name: Anonymous 2012-03-26 18:38

>>25
Sorry, this thread is about C++ (that's in the title at least), I was thinkng of C. In C, a struct declared within a struct doesn't have inner scope, but the same scope as the outer struct. Curly braces most often mean ``statement list'', except for variable and array initializations, unions/structs and (some say) function bodies. Statement lists introduce a lexical scope for variable and other names. Structs and unions don't.

Opening bracket for function bodies should be in column 0 so you can jump from function to function with [.

Name: Anonymous 2012-03-27 13:13

if (CheckDubs) {
    Print("Dubz check em'");
} else {
    Print(FindNextDubs(" nice dubs bro."));
}

Name: Anonymous 2012-03-27 14:24

>>44
Nice dubz and style, broh

Name: Anonymous 2012-03-27 15:33

>>43
Statement lists don't always introduce a lexical scope. I'll correct your other idiotic assertions later on today.

Name: Anonymous 2012-03-27 15:35

>>46
This applies to both C and C++.

Name: Anonymous 2012-03-27 15:44

>>46
lol fag you just got trolloled

Name: Anonymous 2012-03-27 15:46

>>46
Statement lists don't always introduce a lexical scope.
Be that as it may. The curly braces of struct/union declarations never do.

Name: Anonymous 2012-03-27 16:22

[code]
#define PROCEDURE void
#define MAIN main
#define BEGIN {
#define END }

PROCEDURE MAIN
BEGIN
    // hurrrrr
END

Name: Anonymous 2012-03-27 17:03

Somone's a a mental midget.

Name: Anonymous 2012-03-27 17:16

>>51
Impressive grammar you've got there.

Name: Anonymous 2012-03-27 17:28

>>52
Your awesome display of technical incompetence is just as impressive.

Name: Anonymous 2012-03-27 17:52

>>51
>>53
Reported, called the cops, sent multiple letters to FBI, NSA and CIA, phoned interpol and europol and lit my house on fire so the cops would come and here my report about you in person.

Hope you enjoy that ass rape in jail kodak-kun

Name: Anonymous 2012-03-27 19:27

>>36
if this is what i have to expect in future jobs im going to kill myself

>>50
is this real life

Name: Anonymous 2012-03-27 21:18

#include "ltd.h" bool main(*&){if(IsOpGay()) return Sahgeh(); else return CheckForDubs();}
bool IsOpGay(void){return true;} bool Sahgeh(void){return true;} bool CheckForDubs(){return temp char* &x;}

Don't change these.
Name: Email:
Entire Thread Thread List