SUPPORT THE WORK

GetWiki

Comparison of programming languages (syntax)#Comments

ARTICLE SUBJECTS
aesthetics  →
being  →
complexity  →
database  →
enterprise  →
ethics  →
fiction  →
history  →
internet  →
knowledge  →
language  →
licensing  →
linux  →
logic  →
method  →
news  →
perception  →
philosophy  →
policy  →
purpose  →
religion  →
science  →
sociology  →
software  →
truth  →
unix  →
wiki  →
ARTICLE TYPES
essay  →
feed  →
help  →
system  →
wiki  →
ARTICLE ORIGINS
critical  →
discussion  →
forked  →
imported  →
original  →
Comparison of programming languages (syntax)#Comments
[ temporary import ]
please note:
- the content below is remote from Wikipedia
- it has been imported raw for GetWiki
{{Use dmy dates|date=January 2011}}{{Refimprove|date=October 2009}}{{ProgLangCompare}}This comparison of programming languages compares the features of language syntax (format) for over 50 computer programming languages.

Expressions

Programming language expressions can be broadly classified into four syntax structures:
prefix notation
  • Lisp ( (+ 2 3) (expt 4 5))


infix notation


suffix, postfix, or Reverse Polish notation


math-like notation
  • TUTOR (2 + 3)(45) $$ note implicit multiply operator

Statements

Programming language statements typically have conventions for:
  • statement separators;
  • statement terminators; and
  • line continuation
A statement separator is used to demarcate boundaries between two separate statements. A statement terminator is used to demarcate the end of an individual statement. Languages that interpret the end of line to be the end of a statement are called "line-oriented" languages."Line continuation" is a convention in line-oriented languages where the newline character could potentially be misinterpreted as a statement terminator. In such languages, it allows a single statement to span more than just one line.{| class="wikitable sortable"! Language! Statement separator-terminator! Secondary separatorFor multiple statements on one line
| ABAP| period separated
Ada (programming language)>Ada| semicolon terminated
| ALGOL| semicolon separated
| ALGOL 68| semicolon and comma separatedThree different kinds of clauses, each separates phrases and the units differently:
    • serial-clause using go-on-token (viz. semicolon): begin a; b; c end – units are executed in order.
    • collateral-clause using and-also-token (viz. “,”): begin a, b, c end – order of execution is to be optimised by the compiler.
    • parallel-clause using and-also-token (viz. “,”): par begin a, b, c end – units must be run in parallel threads.
APL (programming language)>APL| newline terminated| â‹„ separated
| AppleScript| newline terminated
| AutoHotkey| newline terminated
| BASIC| newline terminated| colon separated
Boo (programming language)>Boo| newline terminated
C (programming language)>C| semicolon terminates statements| comma separates expressions
| C++| semicolon terminates statements| comma separates expressions
C Sharp (programming language)>C#| semicolon terminated
| COBOL| whitespace separated, sometimes period separated, optionally separated with commas and semi-colons.|
Cobra (programming language)>Cobra| newline terminated
| CoffeeScript| newline terminated
D (programming language)>D| semicolon terminated
Eiffel (programming language)>Eiffel| newline terminated| semicolon
Erlang (programming language)>Erlang| colon separated, period terminated
F Sharp (programming language)>F#| newline terminated| semicolon
| Fortran| newline terminated| semicolon
Forth (programming language)>Forth| semicolons terminate word definitions
| GFA BASIC| newline terminated
Go (programming language)>Go| semicolon separated (inserted by compiler)
Haskell (programming language)>Haskell (in do-notation)| newline separated
Haskell (programming language)>Haskell (in do-notation, when braces are used)| semicolon separated
Java (programming language)>Java| semicolon terminated
| JavaScript| semicolon separated (but sometimes implicitly inserted on newlines)
Kotlin (programming language)>Kotlin|semicolon separated (but sometimes implicitly inserted on newlines)
Lua (programming language)>Lua| whitespace separated (semicolon optional)
| Mathematica| semicolon separated
| MATLAB| newline terminated| semicolon or commasemicolon – result of receding statement hidden, comma – result displayed
Object Pascal (Delphi (programming language)>Delphi)| semicolon separated
| Objective-C| semicolon terminated
| OCaml| semicolon separated
Pascal (programming language)>Pascal| semicolon separated
| Perl| semicolon separated
| Perl 6| semicolon separated
| PHP| semicolon terminated
| Pick Basic| newline terminated| semicolon separated
| PowerShell| newline terminated| semicolon separated
| Prolog| period terminated
Python (programming language)>Python| newline terminated| semicolon
Ruby (programming language)>Ruby| newline terminated| semicolon
Rust (programming language)>Rust| semicolon terminates statements| comma separates expressions
Scala (programming language)>Scala| newline terminated (semicolon optional)| semicolon
| Seed7| semicolon separated (semicolon termination is allowed)
| Simula| semicolon separated
S-Lang (programming language)>S-Lang| semicolon separated
| Smalltalk| period separated
| Standard ML| semicolon separated
Swift (programming language)>Swift| semicolon separated (inserted by compiler)
| Visual Basic| newline terminated| colon separated
| Visual Basic .NET| newline terminated| colon separated
| Wolfram Language| semicolon separated
| Xojo| newline terminated
class="sortbottom"! Language! Statement separator-terminator! Secondary separator

Line continuation

Line continuation is generally done as part of lexical analysis: a newline normally results in a token being added to the token stream, unless line continuation is detected.
Whitespace – Languages that do not need continuations
  • Ada – Lines terminate with semicolon
  • C – Lines terminate with semicolon
  • JavaScript - Lines terminate with semicolon (which may be inferred)
  • Lua
  • OCaml


Ampersand as last character of line


Backslash as last character of line


Backtick as last character of line


Hyphen as last character of line


Underscore as last character of line


Ellipsis (as three periods–not one special character)
  • MATLAB: The ellipsis token need not be the last characters on the line, but any following it will be ignored.Mathworks.com {{webarchive|url=https://web.archive.org/web/20100207151905weblink |date=7 February 2010 }} (In essence, it begins a comment that extends through (i.e. including) the first subsequent newline character. Contrast this with an inline comment, which extends until the first subsequent newline.)


Comma delimiter as last character of line
  • Ruby (comment may follow delimiter)


Left bracket delimiter as last character of line


Operator as last object of line
  • Ruby (comment may follow operator)


Operator as first character of continued line
  • AutoHotkey: Any expression operators except ++ and --, as well as a comma or a perioweblink


Backslash as first character of continued line


Some form of inline comment serves as line continuation


Character position
  • Fortran 77: A non-comment line is a continuation of the previous non-comment line if any non-space character appears in column 6. Comment lines cannot be continued.
  • COBOL: String constants may be continued by not ending the original string in a PICTURE clause with ', then inserting a - in column 7 (same position as the for comment is used.)
  • TUTOR: Lines starting with a tab (after any indentation required by the context) continue the previous command.


[End and Begin] using normal quotes
  • C and C++ preprocessor: The string is ended normally and continues by starting with a quote on the next line.

Libraries

{{Expand section|date=December 2009}}To import a library is a way to read external, possibly compiled, routines, programs or packages. Imports can be classified by level (module, package, class, procedure,...) and by syntax (directive name, attributes,...)
File import
  • ASP: include file="filename"
  • AutoHotkey, AutoIt, C, C++: include "filename", include
  • COBOL: COPY filename.
  • Falcon: load "filename"
  • Fortran: include 'filename'
  • Lua: require("filename")
  • Mathematica and Wolfram Language: Import["filename"]
  • MATLAB: addpath(directory)For an M-file (MATLAB source) to be accessible by name, its parent directory must be in the search path (or current directory).
  • Objective-C: import "filename", import
  • Perl: require "filename";
  • PHP: include "filename";, require "filename";
  • Pick Basic: include [filename] program, include [filename] program
  • R: source(""filename"")
  • Rust: include!( "filename");


Package import
  • Ada: with package
  • C, C++: include filename
  • Cobra: use Package.Name
  • D: import package.module;, import altname = package.module;
  • Falcon: load module, load module.submodule
  • Fortran 90+: use module, use module, only : identifier
  • Go: import altname "package/name"
  • Haskell: import Module, import qualified Module as M
  • Java, MATLAB, kotlin: import package.
  • JavaScript: import altname from "modname";, import "modname";
  • Lua: require("modname")
  • Mathematica and Wolfram Language: alternativeName, otherFunction }


Constant import
  • PHP: use const NamespaceCONST_NAME;
The above statements can also be classified by whether they are a syntactic convenience (allowing things to be referred to by a shorter name, but they can still be referred to by some fully qualified name without import), or whether they are actually required to access the code (without which it is impossible to access the code, even with fully qualified names).
Syntactic convenience
  • Java: import package., import package.class
  • OCaml: open module


Required to access code
  • Go: import altname "package/name"
  • JavaScript: import altname from "modname";
  • Python: import module

Blocks

A block is a notation for a group of two or more statements, expressions or other units of code that are related in such a way as to comprise a whole.
Braces (a.k.a. curly brackets) { ... }:


Parentheses ( ... )


Square brackets [ ... ]
  • Smalltalk (blocks are first class objects. a.k.a. closures)


begin ... end:


do ... end:


do ... done:


do ... end
  • Lua, Ruby (pass blocks as arguments, for loop), Seed7 (encloses loop bodies between do and end)


X ... end (e.g. if ... end):
  • Ruby (if, while, until, def, class, module statements), OCaml (for & while loops), MATLAB (if & switch conditionals, for & while loops, try clause, package, classdef, properties, methods, events, & function blocks), Lua (then / else & function)


(begin ...):


(progn ...):


(do ...):


Indentation


Others

Comments

Comments can be classified by:
  • style (inline/block)
  • parse rules (ignored/interpolated/stored in memory)
  • recursivity (nestable/non-nestable)
  • uses (docstrings/throwaway comments/other)

Inline comments

Inline comments are generally those that use a newline character to indicate the end of a comment, and an arbitrary delimiter or sequence of tokens to indicate the beginning of a comment.Examples:{| class="wikitable"! Symbol! Languages
|C|Fortran I to Fortran 77 (C in column 1)
|REM|BASIC, Batch files
|::|Batch files, COMMAND.COM, cmd.exe
|NB.
J (programming language)>J; from the (historically) common abbreviation Nota bene, the Latin for "note well".
|⍝
APL (programming language)>APL; the mnemonic is the glyph (jot overstruck with shoe-down) resembles a desk lamp, and hence "illuminates" the foregoing.
|#
Bourne shell and other UNIX shells, Cobra (programming language)>Cobra, Perl, Python (programming language), Ruby (programming language)>Ruby, Seed7, Windows PowerShell, PHP, R (programming language), Make (software)>Make, Maple (software), Elixir (programming language)>Elixir, Nim (programming language)|Nim]weblink
|%
TeX, Prolog, MATLAB,MATHWORKS.COMACCESSDATE=25 JUNE 2013, Erlang (programming language), S-Lang (programming language)>S-Lang, Visual Prolog
|//
ActionScript, C (programming language)>C (C99), C++, C Sharp (programming language), D (programming language)>D, F Sharp (programming language), Go (programming language)>Go, Java (programming language), JavaScript, Kotlin (programming language)>Kotlin, Object Pascal (Delphi), Objective-C, PHP, Rust (programming language), Scala (programming language)>Scala, Sass (stylesheet language), Swift (programming language)>Swift, Xojo
|'
Monkey X>Monkey, Visual Basic, VBScript Small Basic, Gambas, Xojo
|!|Fortran, Basic Plus, Inform, Pick Basic
|;
x86 assembly language>Assembly x86, AutoHotkey, AutoIt, Lisp (programming language), Common Lisp, Clojure, Rebol, Scheme (programming language)>Scheme,
-
Euphoria (programming language)>Euphoria, Haskell (programming language), SQL, Ada (programming language)>Ada, AppleScript, Eiffel (programming language), Lua (programming language)>Lua, VHDL, SGML
|*
IBM Basic assembly language and successors> Assembler S/360 (* in column 1), COBOL I to COBOL 85, PAW, Fortran IV to Fortran 77 (* in column 1), Pick Basic
|Curl (programming language)>Curl
|"|Vimscript, ABAP
|
Forth (programming language)>Forth
|*>|COBOL 90

Block comments

Block comments are generally those that use a delimiter to indicate the beginning of a comment, and another delimiter to indicate the end of a comment. In this context, whitespace and newline characters are not counted as delimiters.Examples:{| class="wikitable"! Symbol! Languages
| comment ~ ;| ALGOL 60, SIMULA
| ¢ ~ ¢,# ~ #, co ~ co,comment ~ comment
ALGOL 68ALGOL68_REVISED_REPORT-AB.PDF ON PDF PAGE 61-62, ORIGINAL DOCUMENT PAGE 121-122ACCESSDATE=27 MAY 2014, HTML VERSION OF THE ALGOL68 REVISED REPORT AB>URL=HTTP://JMVDVEER.HOME.XS4ALL.NL/REPORT.HTML#941HDEADURL=YESARCHIVEDATE=17 MARCH 2013, dmy-all,
| /* ~ */
AutoHotkey, C, C++, C#, D,DLANG.ORG, LEXICALACCESSDATE=27 MAY 2014, Go, Java (programming language), JavaScript, Kotlin (programming language)>kotlin, Objective-C, PHP, PL/I, Rexx, Rust (programming language) (can be nested), Scala (can be nested), SAS language>SAS, SASS, SQL, Swift, Visual Prolog, CSS
| #cs ~ #ce
AutoItAUTOITSCRIPT.COM KEYWORD REFERENCE, #COMMENTS-STARTACCESSDATE=27 MAY 2014,
| /+ ~ +/| D (can be nested)
| /# ~ #/
Cobra (programming language)>Cobra (can be nested)
| <# ~ #>| Powershell
| =begin ~ =cut| Perl
| #`( ~ )| Perl6 (bracketing characters can be (), , {}, [], any Unicode characters with BiDi mirrorings, or Unicode characters with Ps/Pe/Pi/Pf properties)
| =begin ~ =end| Ruby
End-of-file>EOF,#iffalse ~ #endif, #ifntrue ~ #endif, #if false ~ #endif, #if !true ~ #endifS-Lang (programming language)>S-LangSLANG-2.2.4/SRC/SLPREPR.C - LINE 43 TO 113>URL=FTP://SPACE.MIT.EDU/PUB/DAVIS/SLANG/V2.2/SLANG-2.2.4.TAR.BZ2, 28 May 2014,
| {- ~ -}
Haskell (programming language)>Haskell (can be nested)
| (* ~ *)
Delphi, ML, Mathematica, Object Pascal, Pascal (programming language)>Pascal, Seed7, Applescript, OCaml (can be nested), Standard ML (can be nested), Maple, Newspeak (programming language), F Sharp (programming language)>F#
| { ~ }| Delphi, Object Pascal, Pascal
# ~ #|| Curl
| %{ ~ %}| MATLAB (the symbols must be in a separate line)
~ |#Lisp (programming language)>Lisp, Scheme (programming language), Racket (programming language)>Racket (can be nested in all three).
| -- ~ ,--[=[ ~ ]=]
Lua (programming language)>Lua (the former form can be nested, but only within the latter, which can't be nested)
| " ~ "| Smalltalk
| (comment ~ )|Clojure

Unique variants

Fortran

  • Indenting lines in Fortran 66/77 is significant. The actual statement is in columns 7 through 72 of a line. Any non-space character in column 6 indicates that this line is a continuation of the previous line. A 'C' in column 1 indicates that this entire line is a comment. Columns 1 though 5 may contain a number which serves as a label. Columns 73 though 80 are ignored and may be used for comments; in the days of punched cards, these columns often contained a sequence number so that the deck of cards could be sorted into the correct order if someone accidentally dropped the cards. Fortran 90 removed the need for the indentation rule and added inline comments, using the ! character as the comment delimiter.

COBOL

  • In fixed format code, line indentation is significant. Columns 1–6 and columns from 73 onwards are ignored. If a or / is in column 7, then that line is a comment. Until COBOL 2002, if a D or d was in column 7, it would define a "debugging line" which would be ignored unless the compiler was instructed to compile it.

Cobra

  • Cobra supports block comments with "/ ... /" which is like the "/ ... /" often found in C-based languages, but with two differences. The character is reused from the single-line comment form " ...", and the block comments can be nested which is convenient for commenting out large blocks of code.

Curl

  • Curl supports block comments with user-defined tags as in |foo ... foo|.

Lua

  • Like raw strings, there can be any number of equals signs between the square brackets, provided both the opening and closing tags have a matching number of equals signs; this allows nesting as long as nested block comments/raw strings use a different number of equals signs than their enclosing comment: --comment --[=[ nested comment ]=] . Lua discards the first newline (if present) that directly follows the opening tag.

Perl 5

  • Block comments in Perl 5 are considered part of the documentation, and are given the name Plain Old Documentation (POD). Technically, Perl 5 does not have a convention for including block comments in source code, but POD is routinely used as a workaround.

Perl 6

  • Perl 6 uses `(...) to denote block comments.WEB,weblink Perl 6 Documentation (Syntax), Comments, docs.perl6.org, 2017-04-05, Perl 6 actually allows the use of any "right" and "left" paired brackets after ` (i.e. `(...), `[...], `{...}, `, and even the more complicated `&123;{...}&125; are all valid block comments). Brackets are also allowed to be nested inside comments (i.e. `{ a { b } c } goes to the last closing brace).

PHP

  • PHP supports standard C/C++ style comments, but supports Perl style as well.

Python

  • The use of the triple-(double)quotes although sometimes used to comment-out lines of source, does not actually form a comment. The enclosed text becomes a string, usually a string statement. Python usually ignores a lone string as a statement (except when a string is the first statement in the body of a module, class or function; see docstring).

Ruby

  • As with Python and Perl, Ruby has no specific block-comment syntax. However, like Perl, documentation blocks can be used as block comments as they are ignored by the interpreter.

S-Lang

  • The region of lines enclosed by the and delimiters are ignored by the interpreter. The tag name can be any sequence of alphanumeric characters that may be used to indicate how the enclosed block is to be deciphered. For example, could indicate the start of a block of LaTeX formatted documentation.

Scheme and Racket

  • The next complete syntactic component (s-expression) can be commented out with ; .

ABAP

ABAP supports two different kinds of comments. If the first character of a line, including indentation, is an asterisk (*) the whole line is considered as a comment, while a single double quote (") begins an in-line commet which acts until the end of the line. ABAP comments are not possible between the statements EXEC SQL and ENDEXEC because Native SQL has other usages for these characters. In the most SQL dialects the double dash (--) can be used instead.

Esoteric languages

Comment comparison

There is a wide variety of syntax styles for declaring comments in source code.BlockComment in italics is used here to indicate block comment style.InlineComment in italics is used here to indicate inline comment style.{| class="wikitable"!width=30%| Language!width=30%| In-line comment!width=40%| Block comment
Ada (programming language)>Ada, Eiffel (programming language), Euphoria (programming language)>Euphoria, Occam (programming language), SPARK (programming language)>SPARK, ANSI SQL, and VHDL
- InlineComment|
Algol 60>ALGOL 60||comment BlockComment;
Algol 68>ALGOL 68||¢ BlockComment ¢comment BlockComment commentco BlockComment co
  1. BlockComment
£ BlockComment £
APL (programming language)>APL|⍝ InlineComment|
|AppleScript
- InlineComment|(* BlockComment *)
|Assembly language (varies)|; InlineComment   one example (most assembly languages use line comments only)|
|AutoHotkey|; InlineComment|/* BlockComment */
AWK (programming language)>AWK, Bash (Unix shell), Bourne shell, C shell, Maple computer algebra system>Maple, R, Tcl, and Windows PowerShell|# InlineComment|
BASIC programming language>BASIC (various dialects):|'InlineComment (not all dialects)REM InlineComment|
C (programming language)>C (K&R, ANSI/C89/C90), CHILL, PL/I, and REXX||/* BlockComment */
C (programming language)#C99>C (C99), C++, Go, and JavaScript|// InlineComment|/* BlockComment */
C Sharp (programming language)>C# InlineComment/ InlineComment (XML documentation comment)|/* BlockComment *//** BlockComment */ (XML documentation comment)
|COBOL I to COBOL 85| * InlineComment (* in column 7)|
|COBOL 2002|*> InlineComment|
Curl programming language>Curl||| InlineComment||# BlockComment #||foo# BlockComment #|
Cobra (programming language)>Cobra|# InlineComment|/# BlockComment #/ (nestable)
D programming language>D InlineComment/ Documentation InlineComment (ddoc comments)|/* BlockComment *//** Documentation BlockComment */ (ddoc comments)/+ BlockComment +/ (nestable)/++ Documentation BlockComment +/ (nestable, ddoc comments)
DIGITAL Command Language>DCL|$! InlineComment|
|ECMAScript (JavaScript, ActionScript, etc.)|// InlineComment|/* BlockComment */
Forth (programming language)>Forth| InlineComment|( BlockComment ) (single line as well as multiline)( before -- after ) stack comment convention
|FORTRAN I to FORTRAN 77|C InlineComment (C in column 1)|
|Fortran 90|! InlineComment |
Haskell (programming language)>Haskell
- InlineComment|{- BlockComment -}
Java (programming language)>Java|// InlineComment|/* BlockComment *//** BlockComment */ (Javadoc documentation comment)
Lisp (programming language)>Lisp and Scheme|; InlineComment|#| BlockComment |#
Lua (programming language)>Lua
- InlineComment| --[==[ BlockComment]==] (variable number of = signs)
Maple (software)>Maple|# InlineComment|(* BlockComment *)
|Mathematica||(* BlockComment *)
|Matlab|% InlineComment|%{BlockComment (nestable)%}Note: Both percent–bracket symbols must be the only non-whitespace characters on their respective lines.
Object Pascal>Object Pascal (Delphi)|// InlineComment|(* BlockComment *){ BlockComment }
|OCaml||(* BlockComment (* nestable *) *)
Pascal (programming language)>Pascal, Modula-2, Modula-3, Oberon (programming language), and ML (programming language)>ML:||(* BlockComment *)
Perl and Ruby (programming language)>Ruby|# InlineComment BlockComment=cut (=end in Ruby) (Plain Old Documentation>POD documentation comment)__END__Comments after end of code
|Perl 6|# InlineComment |#`{BlockComment}weblink titlePerl 6 POD Comments, WEB, urweblink titlePerl 6 POD (Abbreviated Blocks),
">

comment    This comment paragraph goes until the next POD directive'    or the first blank line.WEB, urweblink titlePerl 6 POD Comments, WEB, urweblink titlePerl 6 POD (Abbreviated Blocks),

|PHP|# InlineComment' InlineComment
BlockComment *** Documentation BlockComment'' */ (PHPDoc>PHP Doc comments)
|PILOT|R:InlineComment|
|PLZ/SYS||! BlockComment !
|PL/SQL and TSQL
- InlineComment|/* BlockComment */
Python (programming language)>Python|# InlineComment | BlockComment """ BlockComment """(Documentation string when first line of module, class, method, or function)
Rust (programming language)>Rust|// InlineComment/// InlineComment ("Outer" rustdoc comment)//! InlineComment ("Inner" rustdoc comment)|/* BlockComment */ (nestable)/** BlockComment */ ("Outer" rustdoc comment)/*! BlockComment */ ("Inner" rustdoc comment)
SAS System>SAS||* BlockComment;/* BlockComment */
|Seed7|# InlineComment|(* BlockComment *)
|Simula||comment BlockComment;! BlockComment;
|Smalltalk||"BlockComment"
Smarty (template engine)>Smarty||{* BlockComment *}
|Standard ML||(* BlockComment *)
TeX, LaTeX, PostScript, Erlang (programming language)>Erlang, Elixir (programming language) and S-Lang (programming language)>S-Lang|% InlineComment|
|Texinfo|@c InlineComment@comment InlineComment|
TUTOR (programming language)>TUTOR|* InlineCommentcommand $$ InlineComment|
|Visual Basic|' InlineCommentRem InlineComment|
|Visual Basic .NET|' InlineComment' InlineComment'' (XML documentation comment)Rem InlineComment|
|Visual Prolog|% InlineComment|/* BlockComment */
|Wolfram Language||(* BlockComment *)
|Xojo|' InlineComment// InlineCommentrem InlineComment|

See also

References

{{Reflist}}

- content above as imported from Wikipedia
- "Comparison of programming languages (syntax)#Comments" does not exist on GetWiki (yet)
- time: 9:23am EST - Mon, Dec 17 2018
[ this remote article is provided by Wikipedia ]
LATEST EDITS [ see all ]
GETWIKI 09 MAY 2016
GETWIKI 18 OCT 2015
M.R.M. Parrott
Biographies
GETWIKI 20 AUG 2014
GETWIKI 19 AUG 2014
GETWIKI 18 AUG 2014
Wikinfo
Culture
CONNECT