This comparison of programming languages compares the features of language syntax (format) for over 50 computer programming languages.
Programming language expressions can be broadly classified into four syntax structures:
(* (+ 2 3) (expt 4 5))
(2 + 3) * (4 ** 5)
2 3 + 4 5 ** *
(2 + 3)(45) $$ note implicit multiply operator
When a programming languages has statements, they typically have conventions for:
A statement separator demarcates the boundary between two separate statements. A statement terminator defines 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.
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.
\
dnl
%
'
, then inserting a -
in column 7 (same position as the *
for comment is used.)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,...)
addpath(directory)
MATLAB[10]COPY filename.
COBOL:-include("filename").
Prolog#include file="filename"
ASP#include "filename"
, AutoHotkey, AutoIt, C, C++#include <filename>
AutoHotkey, AutoIt, C, C++#import "filename"
, Objective-C#import <filename>
Objective-CImport["filename"]
Mathematica, Wolfram Languageinclude 'filename'
Fortraninclude "filename";
PHPinclude [filename] program
, Pick Basic#include [filename] program
Pick Basicinclude!("filename");
Rustload "filename"
Rubyload %filename
Redrequire('filename')
Luarequire "filename";
Perl, PHPrequire "filename"
Rubysource(""filename"")
R@import("filename");
Zig#include filename
C, C++#[path = "filename"] mod altname;
, Rust@import module;
Objective-C<<name
Mathematica, Wolfram Language:-use_module(module).
Prolog:from module import *
Pythonextern crate libname;
, Rustextern crate libname as altname;
Rustmod modname;
, Rustlibrary("package")
R:IMPORT module
Oberonimport altname "package/name"
Go:import package.module;
, Dimport altname = package.module;
Dimport Module
, Haskellimport qualified Module as M
Haskellimport package.*
Java, MATLAB, Kotlinimport "modname";
JavaScript:import altname from "modname";
, JavaScript:import package
Scalaimport package._
, Scalaimport module
Swiftimport module
V (Vlang)import module
, Pythonrequire "gem"
, Rubyuse module
, Fortran 90+use module, only : identifier
Fortran 90+use Module;
, Perluse Module qw(import options);
Perluse Package.Name
Cobrauses unit
Pascalwith package
Ada@import("pkgname");
Zigfrom module import Class
Pythonimport package.class
Java, MATLAB, kotlinimport class from "modname";
, JavaScriptimport {class} from "modname";
, JavaScriptimport {class as altname} from "modname";
JavaScriptimport package.class
, Scalaimport package.{ class1 => alternativeName, class2 }
, Scalaimport package._
Scalause Namespace\ClassName;
, PHPuse Namespace\ClassName as AliasName;
PHPfrom module import function
Python:import package.module : symbol;
, D:import package.module : altsymbolname = symbol;
D:import Module (function)
Haskell:import function from "modname";
, JavaScript:import {function} from "modname";
, JavaScript:import {function as altname} from "modname";
JavaScript:import package.function
MATLAB:import package.class.function
, Scala:import package.class.{ function => alternativeName, otherFunction }
Scala:use Module ('symbol');
Perl:use function Namespace\function_name;
, PHP:use Namespace\function_name as function_alias_name;
PHP:use module::submodule::symbol;
, Rust:use module::submodule::{symbol1, symbol2};
, Rust:use module::submodule::symbol as altname;
Rust:use const Namespace\CONST_NAME;
PHPThe 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).
import package.*
Javaimport package.class
Javaopen module
OCamlimport altname "package/name"
Goimport altname from "modname";
JavaScriptimport module
PythonA 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.
{
... }
for
& loop
loops, or pass a block as argument), R, Rust, Scala, S-Lang, Swift, PowerShell, Haskell (in do-notation), AutoHotkey, Zig(
... )
[
... ]
begin
... end
for
, do/while
& do/until
loops), OCaml, SCL, Simula, Erlang.do
... end
do
... done
for
& while
loops), F# (verbose syntax)[11] Visual Basic, Fortran, TUTOR (with mandatory indenting of block body), Visual Prologdo
... end
for
loop), Seed7 (encloses loop bodies between do
and end
)end
(e.g. if
... end
):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
...)do
...)if
... end if
:If
... :EndIf
or :If
... :End
if
... fi
, do
... done
, case
... esac
;begin
... end
, (
... )
, if
... fi
, do
... od
repeat
... until
IF
... END-IF
, PERFORM
... END-PERFORM
, etc. for statements; ... .
for sentences.If
... End If
, For
... Next
, Do
... Loop
If
... EndIf
, For
... EndFor
, While
... EndWhile
Comments can be classified by:
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:
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. In the examples, the symbol ~ represents the comment; and, the symbols surrounding it are understood by the interpreters/compilers as the delimiters.
Examples:
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.*
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./#
... #/
" 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.|foo# ... #foo|
.--[[comment --[=[ nested comment ]=] ]]
. Lua discards the first newline (if present) that directly follows the opening tag.~S
(which prevents string interpolation) to the triple-quoted string, leading to the final construct ~S""" ... """
. In addition, Elixir supports a limited form of block comments as an official language feature, but as in Perl, this construct is entirely intended to write documentation. Unlike in Perl, it cannot be used as a workaround, being limited to certain parts of the code and throwing errors or even suppressing functions if used elsewhere.[22]#`(...)
to denote block comments.[23] Raku actually allows the use of any "right" and "left" paired brackets after #`
(i.e. #`(...)
, #`[...]
, #`{...}
, #`<...>
, and even the more complicated #`{{...}}
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).=begin
line and closes at =end
line.#<tag>
and #</tag>
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, #<latex>
could indicate the start of a block of LaTeX formatted documentation.#;
.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 comment 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.
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.
/* ... */
, compiler directives can be used to mimic them just as in VB.NET._
can be used to extend a single-line comment to the next line without needing to type '
or REM
again. This can be done up to 24 times in a row.