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;
}
}
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.
>>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:
Anonymous2010-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;
}
}
>>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.
#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:
Anonymous2010-01-24 19:23
>>23
how fast does that run? 1 line must be pretty fast
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:
Anonymous2010-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:
Anonymous2010-01-24 20:25
#include "stdio.h"
int main(void) {
int x;
char c = 'a';
float y = 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:
Anonymous2010-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;
}
}
>>33-
Asymptotically Approaching Glacial Entropy, if you know what I mean.
Name:
Anonymous2010-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.