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

Pages: 1-4041-8081-

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-24 16:15

>>1
fuck you, im so lazy i just use indent without any options.

Name: Anonymous 2010-01-24 16:23

Name: Anonymous 2010-01-24 16:23


c = 'a'
y = 0

for x in range(0,10):
    if x%2 == 0:
        print x
    else:
        print c
        c = chr(ord(c)+1)


is okay?

Name: Anonymous 2010-01-24 16:30

(define main
    (λ void
      (let ((stop 10)
            (output #\a))
        (let loop ((i 0))
          (if (= stop i)
              0
              (begin
                (display (if (even? i)
                             (char->integer output)
                             output))
                (loop (+ i 1))))))))

Name: Anonymous 2010-01-24 16:53

#include "stdio.h"

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

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

(What was the float for?)

There are additional things this short code does not demonstrate.  I tend to place ternary operations in parenthesis.  The simplicity of the statement executed by the if...else branch decides whether I use more lines or put that part on a single line.  I declare purpose-related, type-same variables in the same line.  I have specific spacings: between adjacent classes (three lines), between adjacent functions/methods and their comments (also two lines).  If I declare, initialize, set, or compare variables, I make sure there are spaces, save for the modulus operator.  Putting spaces sparsely on the outside of parenthesis only where it assists readability.

Here's an example of something I'm oft to do when using Java:
System.arraycopy(src,0, dest,0, (j-1));
The first two and the next two parameters may be related but there's no reason to space them like that: I just do.

Name: Anonymous 2010-01-24 17:18

How fitting that I was just reading http://www.artima.com/weblogs/viewpost.jsp?thread=74230

Name: Anonymous 2010-01-24 17:31

>>7
From a comment to that:
This is the image I got when talking to Gosling about his project Jackpot, in which the notion of program truth is not text, but an annotated parse tree... The really interesting conceptual leap I got from the conversation was that maybe future languages could be defined not as a text syntax but as some kind of data structure.

Has no one read their SICP?

Name: Anonymous 2010-01-24 17:47

Fuck, I forgot my other coed tag.

#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;
}


>>4
FIOC

>>6
The float was to see how you did the spacing between variable types and variable names. You put 1 space in between them, for example, while I make all of my variable names line up.

Name: Anonymous 2010-01-24 17:47

Gosling
Java
some kind of data structure
clojure
third order Greenspunning

Name: Anonymous 2010-01-24 17:57

#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;
        }
    }
  
    c > 49 ?
        printf("yes") :
        printf("no");

    return 0;
}

Name: Anonymous 2010-01-24 17:58

#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;
        }
    }
  
    c > 49 ?
        printf("yes") :
        printf("no");

    return 0;
}


durr

Name: Anonymous 2010-01-24 17:59

#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-24 18:06

The problem is they (may think they) teach you how to write code, but not how to read it.

Name: Anonymous 2010-01-24 18:09

#include<stdio.h>
void main(){int x;char c='a';float y=0;for(x=0;x<10;x++,c++)if(!x%2)printf("%d\n",x);else printf("%c\n",c);}


[buio]FROZENVOID QUALITY[/buio]

Name: Anonymous 2010-01-24 18:19

int main ()
{  
   int x;
   char c = 'a';
   float y = 0.0f;
  
   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-24 18:28

>>15
#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes

Name: Anonymous 2010-01-24 18:34

>>15
You shouldn't'f used [code].

Name: Anonymous 2010-01-24 18:51

#include "stdio.h"

int main(void)

    char c = "a";
    float y = 0;
 
    for (int 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-24 18:51

#include "stdio.h"

int main(void)

    char c = "a";
    float y = 0;
 
    for (int 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-24 19:00

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-24 19:09

#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-24 19:09

>>17
>>18

Sorry.

#include "void.h" //handles all the common functions,#defines,#ifdefs and #includes
start int x;char c='a';float y=0;for(x=0;x<10;x++){if(!x%2){printf("%d\n",x) ENDIF else{printf("%c\n",c);c+=1 ENDIF } finish

Name: Anonymous 2010-01-24 19:23

>>23
how fast does that run?  1 line must be pretty fast

Name: Anonymous 2010-01-24 19:37

#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;
}
/*
 GRUNNUR
 ;
 */

Name: Anonymous 2010-01-24 19:51

>>23
Not yet void quality. The negation in !x%2 can be removed by swapping the two cases, and c+=1 should be sepples. Of course, to obtain true FV quality you should manually unroll the loop and simplify it.

Name: Anonymous 2010-01-24 20:25

#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-24 21:02


;;; ZOMGOPTIMIZED
(let ((c-code (char-code #\a)))
  (dotimes (x 10)
    (format t "~A~%"
            (if (zerop (mod x 2))
                x
                (prog1 (code-char c-code) (incf c-code))))))

;;; MORE ``PROPER''
(defun next-char (char)
  (code-char (1+ (char-code char))))
(define-modify-macro next-charf () next-char)

(let ((c #\a))
  (dotimes (x 10)
    (format t "~A~%"
            (if (zerop (mod x 2)) x
                (prog1 c (next-charf c))))))

Name: Anonymous 2010-01-24 23:56

#include "stdio.h"

int main(int argc,char **argv){
    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;
}


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

Name: Anonymous 2010-01-25 1:02

#include "stdio.h"

int main(int argc, char**argv)
{
    char _varc = 'a';
    float _varf = 0;
    int _cont;

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


I try to stick to variables being 4 characters wide, just a habit I got into. I also put an underscore at the front of any local variable. If I'm coding in C++ I will declare structs as s_*name*, unions as u_*name*, enums and classes in the same style. I always declare a counter as close as possible to it's use in it's first loop.

Name: Anonymous 2010-01-25 1:04


#include "stdio.h"

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

Name: !scyTheNg3k 2010-01-25 1:40

int main()
{ for(initialization();condition();repeat()) {
    multiple();
    line();
    loop();
  }
  if(condition()) single_line_if();
  if(othercondition()) {
    multiple();
    line();
    if();
  } else something();
  etc();
}

Name: Anonymous 2010-01-25 1:55

ANYONE WHO DOES NOT KEEP THE { ON THE SAME LINE AS THE INITIATING CODE IS A FUCKING FAGGOT.

Name: Anonymous 2010-01-25 2:04

ANYONE WHO DOES NOT KEEP THE } ON THE SAME LINE AS THE { IS A FUCKING FAGGOT.

Name: Anonymous 2010-01-25 2:26

ANYONE WHO KEEPS THE <<EOF ON THE SAME LINE AS THE INITIATING CODE IS A FUCKING FAGGOT.
{
EOF

Name: Anonymous 2010-01-25 2:28

>>33-
Asymptotically Approaching Glacial Entropy, if you know what I mean.

Name: Anonymous 2010-01-25 2:41

if(condition()) single_line_if();
This is probably the style choice that throws me off the most. Is it so hard to newline? To keep the condition on one line and the procedure on the other? Even in these resource-conscious times, there's no reason to cram all that logic.

Name: Anonymous 2010-01-25 2:53

>>35
Google IL_OP_U_MAD.
Shit bricks.

Name: Anonymous 2010-01-25 3:10

IL_OP_U_MOD?

Name: Anonymous 2010-01-25 3:11


list(map(print, map(lambda x: x if x % 2 == 0 else chr(ord("a") + (x - 1)//2), range(10))))

And nothing forces me to indent my code

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 )

Name: Anonymous 2010-01-26 16:03

Why waste space?

#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 16:35

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 16:40

>>82
You are now parsing white space manually

Name: Anonymous 2010-01-26 16:41

>>82
I think I see Cassiopeia!

Name: Anonymous 2010-01-26 17:05

[telelscope]
>>82
[/telescope]

Name: Anonymous 2010-01-26 17:20

EXPERT MALLARMÉ1 INDENTATION STYLE

1. ^ http://www.direz.fr/site/uploads/Mallarme/Coupde.pdf

Name: 86 2010-01-26 17:22

Fuck. I forgot to quote >>82. Fuck!

Name: Anonymous 2010-01-26 21:59

>>86
I chuckled knowingly

Name: Anonymous 2010-01-26 22:14

>>67
No, it's because the ancient compiler that K&R used had a bug in it where it couldn't parse the opening brace of a function unless it was after a newline. Why would the lack of nested functions matter to indentation style? Java in particular allows nested classes and the official Java style guide suggests putting the opening brace on the same line.

Here's a relevant question for the /prog/ crowd: Do you block and/or indent semantically relevant code blocks, such as mutex locking or glBegin/End?

void PaintRect(void) {
  glBegin(GL_TRIANGLE_STRIP); {
    glVertex2f(0,0);
    glVertex2f(0,1);
    glVertex2f(1,0);
    glVertex2f(0,1);
  } glEnd();
}

void DecRefCount(Object* obj) {
  pthread_mutex_lock(&mutex); {
    if (!--obj->refCount) {
      obj->destroy_fn(obj);
      free(obj);
    }
  } pthread_mutex_unlock(&mutex);
}


It has the same advantage as 1TBS in that code merging by revision control systems is much less likely to produce bad code (you really can't resolve the conflict incorrectly, whereas without the indent, if you aren't paying close enough attention you might accidentally put a critical statement on the wrong side of the mutex, causing a race condition or deadlock). Plus you can't really forget the close/unlock as you're typing when you do it this way (if you're not in the habit of writing open/close at the same time). Lots of OpenGL examples use this style.

However it might be misleading. For instance I would expect to be able to break or return out of a nested scope (since closing the scope usually doesn't have an effect), whereas you really can't do that here. I guess you have to remember to check whether closing braces have a closing statement, whereas I'd be much more hesitant to skip the rest of the function when it's flat. Maybe that's just because my eyes are used to skipping over closing braces, since aside from do {} while, there's never anything after them. Another downside is you have to forward declare variables outside the scope if you want to get their values after unlocking (you could do the indent without the block, but that's even more misleading). And another downside is, where do you draw the line as to what you indent or don't indent? Do you indent temporary variables that need to be destroyed, for instance?

void doSomething() {
  SomeObj temp;
  SomeObjInit(&temp); {
    // do some shit
  } SomeObjDestroy(&temp);
}


I think despite these disadvantages I'm still considering using this style at least for mutex locking in my own projects. Of course if you're in Sepples you should just use RAII. I'm rambling at this point. What do you think?

Name: Anonymous 2010-01-26 22:21

What do you think?
Who, me? Shit, I dunno dude. Use a monad?

Name: Anonymous 2010-01-26 22:43

>>81
Indeed, why waste space?
That said, it is practical to see where the loops&stuff end.

#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 22:49

>>91
Why two spaces after if?

Name: Anonymous 2010-01-26 22:54

>>92
Copypasta + lacklustre error-checking. In one word: typo.

Name: Anonymous 2010-01-26 23:14

>>92
I guess it's to make if sync up with for:


int main()
{
    for (...) ...
    if  (...)
    {
        ...  
    }
}

Name: Anonymous 2010-01-26 23:18

#include <stdio.h>

int main ()
{
    char c = 'a';

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

Name: Anonymous 2010-01-26 23:23

>>81
Why waste space indeed...

#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-27 0:03

>>96
#include"stdio.h"
main(){int x=-1;char c='a';float y=0;for(;x++<9;){if(x%2)printf("%c\n",c++);else printf("%d\n",x);}}

Name: Anonymous 2010-01-27 3:14

>>97
#include<stdio.h>
x;char c=97;main(){for(;x<10;x++)printf(x&1?"%c\n":"%d\n",x&1?c++:x);}


or perhaps…
#include<stdio.h>
x,c=97;main(){for(;x<10;x++)x&1?putchar(c++):printf("%d",x),puts("");}

Name: Anonymous 2010-01-27 3:46

>>96-98, your <void.h> is missing.

Name: Anonymous 2010-01-27 15:57

#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-12-06 10:04

Back to /b/, ``GNAA Faggot''

Name: Anonymous 2011-02-04 11:40

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