Commenting code is the process of adding normal English statements to source code. This is done for several reasons. The first is to clarify a confusing block of code, or a particularly tricky section of code. A second reason why commenting is done is for documentation. Commenting the preconditions and postconditions as well as the purpose of all functions, method, procedures, or any named block of code allows for them to be reused without having to read the code. Commenting code is suppose to be done while coding. In practice this is rarely done. Comments if added at all are added after the fact.

The syntax for a comment in code will change from language to language all most all imperative programming languages have comments in some form. Commenting types can come in three forms depending on the language. The first main type is "unique line only". This type of comment can only be written on a line by itself. It can not share a line with a normal executable statement. An example of this is found in ADA. The second main type of comment is “anywhere” comments. These comments can be placed anywhere within code. C and Java both support this type of commenting with the /* and */. The third and finally common type of comments comes in the form of "end of line". These comments an be on the same line as an executable statement but only to the right of the statement. An example of this is C++ and Java with //. Pascal is a language that encourages "end of line" style.

a reference

See also how to shoot yourself in the foot in various programming languages, programming languages geneology project, programming metanode

Please message me if you have additions or corrections, or if you feel my scope of included "significant" languages is too small


ALGOL:
  • comment (keyword "comment" must be placed at the beginning of a statement) to semicolon;
  • // to end of line
BCPL:
  • // to end of line
B, C, PL/1, Prolog, BC, Calc, YACC:
  • /* Between these symbols */
C99, C++, Objective C, Java, Javascript:
  • /* Between these symbols */
  • // to end of line
Shell scripting, Python, TCL, Icon, Unlambda:
  • # to end of line
Perl:
  • # to end of line
  • =cut
    Everything between a line beginning with an = and a line beginning with =end
    =end
Ruby:
  • # to end of line
  • =begin
    Everything between a line beginning with =begin and a line beginning with =end
    =end
LISP, Scheme, LOGO, Orthogonal, TinyFugue:
  • ; to end of line
Pascal:
  • { Between these symbols }
BASIC, DOS batch file:
  • REM to end of line
QBasic, Visual Basic, ASP:
  • ' to end of line
HTML:
  • <!-- Between these symbols -->
Postscript, Turing:
  • % to end of line
FORTRAN:
  • C to end of line
FORTRAN 90:
  • ! to end of line
Forth:
  • \ to end of line
Ada:
  • /* Between these symbols */
  • -- to end of line
Eiffel, Haskell, Applescript, Hypertalk:
  • -- to end of line
Smalltalk, vim:
  • " to end of line
COBOL, SNOBOL, SPITBOL:
  • * to end of line
SQL:
  • remark to end of line
ML, CAML, SML, Mathematica, Modula, Oberon:
  • (* Between these symbols *)
A/PL:
  • @ to end of line
Javadoc:
  • /** Between these symbols **/
DC:
  • [ Between these symbols ]sd
TECO:
  • ! Between these symbols !
Miranda, Curl:
  • || to end of line
INTERCAL:
  • Any line containing an odd number of instances of the strings "not" or "n't". (As far as i can tell, anyway-- note, though, that the INTERCAL manual is extremely unclear and i may be misinterpreting it.)
Brainfuck:
  • Brainfuck does not have an explicit comment syntax; however because the interpreter will ignore any input other than the eight one character operators in the brainfuck language
    you may just write whatever you like and it will be interpreted as a comment

Original partial source / inspiration for this node was http://s lashdot.o rg/comments.pl?s id=01/04/0 6/1335241&cid=223 .. vast majority but not all of remaining entries came from the infinite 99 Bottles of Beer webpage, which contains many other languages not included here .. thanks to dogbert2 on undernet .. this source disclaimer may or may not be removed from this node eventually

Log in or register to write something here or to contact authors.