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

Code Style

Name: Anonymous 2010-01-24 16:09

The following program demonstrates your tab width, indentation style, and various other aspects of your code style. Please write it (in verbatim) in your preferred style. Remember to use spaces instead of tabs, as shitchan automatically converts tabs into 3 space characters.

[code]#include "stdio.h"

int main (void)
{   int   x;
    char  c = 'a';
    float y = 0;
   
    for (x = 0; x < 10; x++)
    {   if  (x % 2 == 0)
            printf ("%d\n", x);
        else
        {   printf ("%c\n", c);
            c +=1;
        }
    }
   
    return 0;
}

Name: Anonymous 2010-01-25 3:17

>>38
JESUS FUCKING CHRIST!

Name: Anonymous 2010-01-25 7:25

#include "stdio.h"

#define ENTRY_POINT int main()
#define SCOPE_START {
#define SCOPE_FINISH }
#define INTEGER int
#define CHARACTER char
#define FLOAT float
#define LOOP_START(v) while(v){
#define LOOP_END }
#define EXIT_POINT(x) return(x);}
#define PRINT_A_FORMATTED_STRING printf
#define CONDITIONAL_BOOLEAN_START(b) if(b){
#define CONDITIONAL_BOOLEAN_FINISH }
#define SET(v,t) v = t
#define EQUALS(v,t) (v == t)
#define LINE_END
#define LESS_THAN(v,t) (v < t)
#define ONE 1
#define ZERO 0
#define ADD(v,t) (v + t)
#define INCREMENT_VALUE_BY_ONE(v) SET(v, ADD(v, 1))
#define ELSE } else {
#define REMAINDER(v,t) (v % t)
#
#define ENTRY_POINT int main(){
#define SCOPE_START {
#define SCOPE_FINISH }
#define INTEGER int
#define CHARACTER char
#define FLOAT float
#define EXIT_POINT(x) return(x); SCOPE_FINISH
#define IF_START(b) if (b)
#define THEN SCOPE_START
#define IF_FINISH SCOPE_FINISH
#define SET(v,t) v = t
#define EQUALS(v,t) (v == t)
#define LINE_END
#define NOT !
#define LESS_THAN(v,t) (v < t)
#define ONE 1
#define ZERO 0
#define ADD(v,t) (v + t)
#define INCREMENT_VALUE_BY_ONE(v) SET(v, ADD(v, 1))
#define ELSE LINE_END else SCOPE_START
#define LINE_END ;
#define LOOP_START while(ONE) SCOPE_START
#define LOOP_EXIT break
#define LOOP_END LINE_END

ENTRY_POINT
INTEGER
XVALUE
LINE_END
CHARACTER
CVALUE
LINE_END
FLOAT
YVALUE
LINE_END
SET
(CVALUE, 'a')
LINE_END
SET
(FVALUE, 0)
LINE_END
SET
(XVALUE, 0)
LINE_END
LOOP_START
IF_START
(NOT LESS_THAN
(XVALUE, 10))
THEN
LOOP_EXIT
IF_FINISH
INCREMENT_VALUE_BY_ONE
(XVALUE)
LINE_END
LOOP_END
EXIT_POINT
(0)

Name: Anonymous 2010-01-25 7:29

>>40
yes, since that's one statement and you could easily use colons and braces (Gweedo bastardized braces, though).

Name: Anonymous 2010-01-25 7:29

>>6
This is exactly my style, including the little details. Creepy. Are you me?

Name: Anonymous 2010-01-25 7:34

>>16
Is that sum microsoft?

Name: Anonymous 2010-01-25 8:00

#include "stdio.h"

int
main
     (
 void
)
                        {
 int
  x;
 char
    c
  = 'a';
 float
    y
  = 0;
 for
         (
    x
  = 0;
    x
  < 10;
  x++
 )
                       {
 if         (
       x
     % 2
  == 0
 )
  printf (
   "%d\n"
   , x
  );
 else
                      {  
   printf (
    "%c\n"
    ,c
   );
      c
   += 1;
  }
 }
 return 0;
}

Name: Anonymous 2010-01-25 8:03

FROZEN VOID QUALITY

Name: Anonymous 2010-01-25 8:54


/* This is the main function. The main function will do
   everything in the program. */

int main (void)
{

  /* In this section rest the declarations
     for the variables used througout the program. */

  int x; /* This will be use for the counter. */
  char c;
  float y; /* ``float'' is a nice word. */

  /* Here we initialize the char (declared above)
     and the float. */

  c = 'a';
  y = 0;
  
  /* This section of the code loops from 0 to 9,
     and handles things differently depending on whether
     ``x'' divides by two. */

  for (x = 0; x < 10; x++) {  

    /* If-else clause. Handles what happens depending
       on the value of x. */

    /* If... */

    if  (x % 2 == 0)

      /* If x divides, it prints x, and a newline. */
      printf ("%d\n", x);

    /* Else... */

    else {

      /* If x does not divide, it prints ``c'', and a newline,
         and adds 1 to c. */

      printf ("%c\n", c);
      c = c + 1;
    }

  }
  
  /* This section returns ``0''. */

  return 0;

}

Name: Anonymous 2010-01-25 9:18


#includeway "iostday.hay"

intway ainmay (oidvay)
{   intway   xay;
    archay  cay = 'a'WAY;
    oatflay yay = 0;
  
    orfay (xay = 0; xay < 10; xay++)
    {   ifway  (xay % 2 == 0)
            intfpray ("%day\nay", xay);
        elseway
        {   intfpray ("%cay\nay", cay);
            cay +=1;
        }
    }
  
    eturnray 0;
}


IGPAY ATINLAY ENTERPRISEWAY URNKEYTAY OLUTIONSAY!

Name: Anonymous 2010-01-25 9:31

I MENA >>42
>>47

Name: Anonymous 2010-01-25 11:02

>>48
Write it in WEB and don't come back until you're done

Name: Anonymous 2010-01-25 11:28

>>51
Ok.


/* This is the anonymous function. This function will do
   everything in the program. */

(function() {

  /* In this section rest the declarations
     for the variables used througout the program. */

  var x; /* This will be use for the counter. */
  var c;
  var y; /* ``float'' is a nice word. */

  /* Here we initialize the vars declared above. */

  c = 'a';
  y = 0;
 
  /* This section of the code loops from 0 to 9,
     and handles things differently depending on whether
     ``x'' divides by two. */

  for (x = 0; x < 10; x++) { 

    /* If-else clause. Handles what happens depending
       on the value of x. */

    /* If... */

    if  (x % 2 == 0)

      /* If x divides, it prints x, and a newline. */
      alert (x + '\n');

    /* Else... */

    else {

      /* If x does not divide, it prints ``c'', and a newline,
         and adds 1 to c. */

      alert (c + '\n');
      c = c + 1;
    }

  }
 
  /* This section returns ``0''. */

  return 0;

}) ();

Name: Anonymous 2010-01-25 11:38

>>48
EWWWWW

Name: Anonymous 2010-01-25 13:45

COMMENTS ?!?!?!?
COMMENTS FOR EVERY FUCKING LINE?!?!?!
ARE YOU NIGGERS MAD?

And y'all call yourselves programmers!!!

HAHAHAHAHAHAHAHAHAHAHAAHAHA


Maybe if y'all learn to code properly y'all wouldn't need so many comments.

Name: Anonymous 2010-01-25 13:47

>>54
Welcome to /prog/.

Name: Anonymous 2010-01-25 17:16

>>13
this

Name: Anonymous 2010-01-25 18:17

#include "stdio.h"

int main (void) {
   int x;
   char c = 'a';
  
   for (x = 0; x < 10; x++) {
      if (x%2 == 0) printf("%d\n", x);
      else printf("%c\n", c++);
   }
  
   return 0;
}

Name: Anonymous 2010-01-25 18:44

>>29
Why am I the only person that doesn't put a space between if(...) and {? :<

Because it looks FUCKING BUTT-SHIT-UGLY LIKE YOUR MOTHER

I wish I could fucking stab everyone who doesn't leave spaces there.

Name: Anonymous 2010-01-25 20:08

>>44

Everyone writes like that.

Name: Anonymous 2010-01-25 20:10

#include <stdio.h>

int main(void) {
  char c = 'a';
  float y = 0.0f;
  
  for (int x = 0; x != 10; ++x) {
    if (x % 2 == 0)
      printf("%d\n", x);
    else
      printf("%c\n", c++);
  }

  return 0;
}


The one true style. And no, I don't do C89 bullshit block declarations. It's 2010 for fuck's sake.

Name: Anonymous 2010-01-25 20:40

Oh god, so many hideous code styles. The only one remotely passable is >>31, and it has the legacy compatibility limitations of old K&R, such as requiring the open brace of a function on a newline. >>29 actually isn't terrible, except for the fact that his spacebar seems to be broken.

As the author of >>60, I feel I must educate furthur as to the one true style. There's lots of stuff this did not cover:

double braces around assignment in if statements
if ((x = 7)) do_some_shit();

related declarations should have equal signs aligned
int something      = 4;
int something_else = 7;


repeated related function calls should have arguments aligned (with space only after the commas, none trailing; no alignment of commas or closing brace)
some_func(an_arg,      another_arg);
some_func(a_third_arg, last_arg);


braces can be used around and in ternary operator when needed, and put spaces around ? and : (but never inside braces). usually put braces around arms when needed to clarify, even when the precedence order would allow no braces (mainly because the inner arm of ?: breaks the precedence order)
some_func(a ? (b + c) : d, e);

if an else block needs braces, add braces for the if block as well (don't do like OP). they don't add any lines in this case.
if (x % 2 == 0) {
  printf ("%d\n", x);
} else {
  printf("%c\n", c);
  c = c + 1;
}


no line length limits; this isn't the stone ages. but be reasonable. repeated related function calls however can break the 'reasonable' limitation, and run well over 200 characters; scrolling horizontally to see a table of well-aligned function calls is much preferable to 30 lines of repeated function calls with no alignment to show you the argument layout.

Name: Anonymous 2010-01-25 22:09

whatever gnu indent spits out is ok by me

Name: Anonymous 2010-01-26 2:15

>>61

Uh... No, all of the non-joke coding styles listed in this thread are fine, as long as they're consistent.

Name: Anonymous 2010-01-26 2:31

>>61
related declarations should have equal signs aligned
int something      = 4;
int something_else = 7;
Fair enough.  Although I think Guido might object.
repeated related function calls should have arguments aligned (with space only after the commas, none trailing; no alignment of commas or closing brace)
some_func(an_arg,      another_arg);
some_func(a_third_arg, last_arg);
Uggggh.  IHBT.

Name: Anonymous 2010-01-26 3:20

K&R or kernel style.
GNU are retards and trolls the lot of them.

Name: Anonymous 2010-01-26 4:15

GNU style.
KorR or kernel are retards and trolls the lot of them.

Name: Anonymous 2010-01-26 6:02

The reason opening function brackets are on newlines is because you can't portably nest functions in C.

Name: Anonymous 2010-01-26 6:15

Beauty:

if(flags&CAN_HAXX_ANUS)
{
    haxx(anus);
    return 0;
}


PIG DISGUSTING:

if(flags&CAN_HAXX_ANUS) {
    haxx(anus);
    return 0;
}

Name: Anonymous 2010-01-26 6:17

>>64
Fair enough.  Although I think Guido might object.
Please, don't tell him! I'm begging you!

Name: Anonymous 2010-01-26 6:36

When it comes to C-likes, here's what I think of them:
  K&R - okay, if consistent, but I find it less readable
  Allman - more readable, I tend to find it easier to parse
  BSD - okay, but less readable than Allman, however I like how function return type is declared on a separate line
  Whitesmith - I don't see any advantage to it.
  GNU - It's not terrible, but the braces having their own indent level is just plain weird.
  Horstmann - Pretty good. Combines Allman's advantages with K&R's advantages. Probably one of the better ones, but it requires a good editor like Emacs to be used with. Is this what OP used?

For C-likes, I tend to use Allman, but if I'd use a more superior editor like Emacs for C code, I'd write in Horstmann style.
Indentation style is an already fully solved problem for some languages, for example Lisp has its own style, which is used by all sane Lispers (it's actually hard to read code written in non-standard lisp indentation styles, which are usually nonexistent and only used by misguided newbies which don't have a good editor). Emacs (and other lisp editors) provide full (re)indentation support and paren-matching, as well as many other useful features. This is ideal, but it helps having an uniform syntax, which is not what C-likes have.

Name: Anonymous 2010-01-26 6:41

>>70
Allman - more readable, I tend to find it easier to parse
And how is that possible?

Name: Anonymous 2010-01-26 6:51

>>71
I didn't mean "parse" in the sense of writing a program which parses such source code. I meant it in the mental sense: my brain seems to take less time reading C code indented in Allman than it does with K&R style. It may be a small difference, but it's enough for me to write my own(when working with code written by others, it's best to keep consistent) C code in Allman style.

Name: Anonymous 2010-01-26 7:15

K&R style
Yes, though I don't like having the brace on a newline after a function definition if I can help it. Long function definitions and constructors that initialize data are my exceptions.
1TBS
No.
Allman style
Awful.
BSD KNF style
Could be worse. I hate including else statements on the closing brace of an if, though.
Whitesmiths style
FUCK NO!!!
GNU style
As pig-disgusting as Stallman himself.
Horstmann style
Maybe if I was a troll. So basically, no.

Name: Anonymous 2010-01-26 7:44

you forgot frozenvoid style. no newlines.

Name: Anonymous 2010-01-26 8:19

The One True Indentation Style for C
#include "stdio.h"
int main(void)
  {int x;
   char c='a';
   float y=0;
   for (x=0;
        x<10;
        x++)
     {if(x%2==0)
        printf("%d\n",x);
      else
        {printf("%c\n",c);
         c +=1;}}
   return 0;}

Name: Anonymous 2010-01-26 9:17

>>74
No one cares about you or remembers about you. Stop trying to remind us that you exist.

Name: Anonymous 2010-01-26 9:18

Dicktower
( ≖‿≖)  D
( ≖‿≖ )   I
(≖‿≖ )  C
(‿≖   )   K
(≖   )   
(     )   T
(     )   O
(   ≖)   W
(  ≖‿)   E
( ≖‿≖)  R

Name: Anonymous 2010-01-26 9:29

>>75
I'm loling right now but I think I might just try this on my next C project.

Name: Anonymous 2010-01-26 9:41

Nobody uses my indentation style anymore? :(


#include "stdio.h"

int main
     (
 void
)                      {
 int   x;
 char  c = 'a';
 float y = 0;

 for
         (
  x = 0;
  x < 10;
  x++
 )                    {
  if
             (
   x % 2 == 0
  )
   printf("%d\n", x);
  else
                     {
   printf("%c\n", c);
   c +=1;
  }
 }
 return 0;
}

Name: Anonymous 2010-01-26 10:29

>>79
I did, but then I improved it ( see >>46 )

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