Content deleted Content added
Stevebroshar (talk | contribs) →Examples: Limit examples by grouping by similar syntax |
Stevebroshar (talk | contribs) →Examples: Group scripting languages |
||
Line 346:
====Curly brace languages====
Many of the [[curly brace language]]s such as C, C++ and their many derivatives delimit a line comment with {{code|//}} and a block comment with {{code|/*}} and {{code|*/}}. Originally, C lacked the line comment, but it was added in [[C99]].
<syntaxhighlight lang="c">
Line 359:
</syntaxhighlight>
A pattern in many [[scripting language]]s is to delimit a line comment with <code>#</code> and provide no support for a block comment. Notable languages include: [[Bash (Unix shell)|Bash]], [[Python (programming language)|Python]] and [[R (programming language)|R]].
An example in R:
<syntaxhighlight lang="R">▼
# This is a comment▼
print("This is not a comment") # This is another comment▼
</syntaxhighlight>▼
=====In Python=====▼
Although Python does not provide for block comments<ref name=triple>{{cite web |url=https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html |title=Python 3 Basic Syntax |access-date=25 February 2019 |quote=Triple quotes are treated as regular strings with the exception that they can span multiple lines. By regular strings I mean that if they are not assigned to a variable they will be immediately garbage collected as soon as that code executes. hence are not ignored by the interpreter in the same way that #a comment is. |archive-date=19 August 2021 |archive-url=https://web.archive.org/web/20210819164828/https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html |url-status=dead }}</ref>
<syntaxhighlight lang="python">▼
"""▼
At the top of a file, this is the module docstring
"""▼
class MyClass:▼
def my_method(self):▼
</syntaxhighlight>▼
===By language===
Line 643 ⟶ 669:
</syntaxhighlight>
Instead of a regular block commenting construct, Perl uses [[
{{cite web
| title = perlpod – the Plain Old Documentation format
| url = http://perldoc.perl.org/perlpod.html|access-date=2011-09-12
}}
</ref>
{{cite web
| title = Pod::ParseUtils – helpers for POD parsing and conversion
Line 674 ⟶ 700:
return $self;
}
▲</syntaxhighlight>
▲====R====
▲<syntaxhighlight lang="R">
▲# This is a comment
▲print("This is not a comment") # This is another comment
</syntaxhighlight>
Line 748 ⟶ 767:
Write-Host "Goodbye, world!"
▲</syntaxhighlight>
▲====Python====
▲<syntaxhighlight lang="python">
▲Python does not provide for block comments<ref name=triple>{{cite web |url=https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html |title=Python 3 Basic Syntax |access-date=25 February 2019 |quote=Triple quotes are treated as regular strings with the exception that they can span multiple lines. By regular strings I mean that if they are not assigned to a variable they will be immediately garbage collected as soon as that code executes. hence are not ignored by the interpreter in the same way that #a comment is. |archive-date=19 August 2021 |archive-url=https://web.archive.org/web/20210819164828/https://www.tutorialdocs.com/tutorial/python3/python3-basic-syntax.html |url-status=dead }}</ref> but a bare [[string literal]] represented by a triple-quoted string can be and often is used for this purpose.<ref>[https://twitter.com/gvanrossum/status/112670605505077248 "Python tip: You can use multi-line strings as multi-line comments"], 11 September 2011, Guido van Rossum</ref><ref name=triple/> In the examples below, the triple double-quoted strings act like comments, but are also treated as [[docstring]]s:
▲"""
▲"""
▲class MyClass:
▲ """The class's docstring"""
▲ def my_method(self):
▲ """The method's docstring"""
</syntaxhighlight>
|