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

Comments: Are they necessary?

Name: Anonymous 2011-07-15 18:33

(20:49:20) <Zhivago> Comments indicate defective code.
(20:49:31) <Zhivago> So the more comments, the worse the code.
(20:49:51) <Zhivago> On the other hand, a lack of comments can indicate uncommented defective code.

discuss

Name: Anonymous 2011-07-16 7:18


/* Code that prints the range of numbers starting from 0 inclusive to 10 inclusive
   This code prints the range of numbers starting from 0 inclusive to 10 inclusive
   Copyright (C) >>20 */
#include /* This is a preprocessor statement that includes the source code of another file, */ <stdio.h> /* and that file is the standard library's <stdio.h>, that contains
                                                        the standard I/O procedures and definitions. */
#include /* This is another preprocessor include statement, */ <stdlib.h> /* the standard library include. We need this for some standard macros and definitions. */

signed int /* This function is declared as `signed int', it means that it will return a signed integer
              between `INT_MIN' and `INT_MAX'. (see <limits.h>) */
main /* The name of this function is `main'. `main' is a special function in C, it defines the entry point
    of the program. Every program must have a `main' function, so here it is. */
( /* This opens the argument list for `main'. */
     signed int argc, /* The argument count variable, it is passed as an argument to main when you start the program.
             It contains the count of the arguments passed to the program. It is a signed integer. */
     char *argv[] /* The argument vector pointer, it is passed as an argument to main when you start the program, just like `argc'.
             It contains the actual strings of the arguments passed to the program. It is a vector of `char*'s of the same
             length of `argc'. */
     ) /* This closes the argument list for `main'. */
{ /* This opens the body of `main', here goes the code. */
     signed int i; /* We declare a `signed int' variable called `i'. It will be used as index variable for a loop later in the program.
              The `i' name comes from FORTRAN, that took it from mathematics, and stands, surprisingly, for index. */
     /* Leaving a space between variable declarations and code is good style. */
     for /* We will be using a looping language construct called `for'. It can be desugarized as:
        for (init; cond; incr) body;
        {init;while(cond){body;incr;}}
        , except that if a `continue' or `break' statement is executed, the `incr' part will be executed as well. */
      ( /* This opens the ``argument'' list for `for' */
           i = 0; /* As `init', we set the `i' index variable to 0. */
           i <= 10; /* We will be looping for all the numbers from 0 inclusive to 10 inclusive, so we check if `i' is less or equal than 10. */
           i++ /* We increase `i' */
           ) /* This closes the ``argument'' list for `for'. */
     { /* This delimits the `body' part of our `for' loop. It is good style to delimit the body of a loop with brackets even if the language
      permits one statement bodies to be undelimited, just to be sure that if we will ever add some code to the loop we will know that
      it will work no matter what. This decreases mistakes in the code. */
      printf /* The `printf' function stands for print formatted. It will be used to print the value of our `i' variable.
            The `printf' function is pretty sofisticated: it takes a format string as first argument, and the printed values as
            rest arguments. The format string and the types must coincide, though, because `printf' is not type safe.
            It is defined in <stdio.h>. */
           ( /* This opens the argument list for `printf'. */
            "%d\n", /* This is our format string. Nothing too complex, just the %d format specifier that says to `printf' that
                   we will be printing a `signed integer', and a \n that means a newline. */
            i /* This is our `i' index variable that contains a number starting from 0 inclusive to 10 inclusive. */
            ); /* This closes the argument list for `printf'. */
     } /* This closes the delimiter of our `for' loop's `body' part. */

     return /* We return a value to the OS. */
      EXIT_SUCCESS; /* We return a success value, because we have successfully printed the range of numbers starting from 0 inclusive to 10 inclusive. */
} /* This closes the body of `main'. */

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