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-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

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