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.
Language | Statement separator-terminator | Secondary separator-terminator [1] |
---|---|---|
ABAP | period separated | |
Ada | semicolon terminated | |
ALGOL | semicolon separated | |
ALGOL 68 | semicolon and comma separated [2] | |
APL | newline terminated | [Direct_function ⋄] separated Secondary |
AppleScript | newline terminated | |
AutoHotkey | newline terminated | |
BASIC | newline terminated | colon separated |
Boo | newline terminated | |
C | semicolon terminates statements | comma separates expressions |
C++ | semicolon terminates statements | comma separates expressions |
C# | semicolon terminated | |
COBOL | whitespace separated, sometimes period separated, optionally separated with commas and semi-colons. | |
Cobra | newline terminated | |
CoffeeScript | newline terminated | |
CSS | semicolon terminated | |
D | semicolon terminated | |
Eiffel | newline terminated | semicolon |
Erlang | colon separated, period terminated | |
F# | newline terminated | semicolon |
Fortran | newline terminated | semicolon |
Forth | semicolons terminate word definitions. space terminates word use | |
GFA BASIC | newline terminated | |
Go | semicolon separated (inserted by compiler) | |
Haskell (in do-notation) | newline separated | |
Haskell (in do-notation, when braces are used) | semicolon separated | |
Java | semicolon terminated | |
JavaScript | semicolon separated (but often inserted as statement terminator) | |
Kotlin | semicolon separated (but sometimes implicitly inserted on newlines) | |
Lua | whitespace separated (semicolon optional) | |
Mathematica also called Wolfram | semicolon separated | |
MATLAB | newline terminated | semicolon or comma [3] |
MUMPS also called M | newline terminates line-scope, the closest to a "statement" that M has | a space separates/terminates a command, allowing another command to follow |
Nim | newline terminated | |
Object Pascal (Delphi) | semicolon separated | |
Objective-C | semicolon terminated | |
OCaml | semicolon separated | |
Pascal | semicolon separated | |
Perl | semicolon separated | |
PHP | semicolon terminated | |
Pick Basic | newline terminated | semicolon separated |
PowerShell | newline terminated | semicolon separated |
Prolog | comma separated (conjunction), semicolon separated (disjunction), period terminated (clause) | |
Python | newline terminated | semicolon |
R | newline terminated [4] | semicolon [4] |
Raku | semicolon separated | |
Red | whitespace separated | |
Ruby | newline terminated | semicolon |
Rust | semicolon terminated | comma separates expressions |
Scala | newline terminated (semicolon optional) | semicolon |
Seed7 | semicolon separated (semicolon termination is allowed) | |
Simula | semicolon separated | |
S-Lang | semicolon separated | |
Smalltalk | period separated | |
Standard ML | semicolon separated | |
Swift | semicolon separated (inserted by compiler) | |
V (Vlang) | newline terminated | comma or semicolon separated |
Visual Basic | newline terminated | colon separated |
Visual Basic .NET | newline terminated | colon separated |
Wolfram Language | semicolon separated | |
Xojo | newline terminated | |
Zig | semicolon terminated | |
Language | Statement separator-terminator | Secondary separator-terminator [1] |
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.)This section needs expansion. You can help by adding to it. (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,...)
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-C Import["filename"]
Mathematica, Wolfram Language include'filename'
Fortran include "filename";
PHP include [filename] program
, Pick Basic #include [filename] program
Pick Basic include!("filename");
Rust load "filename"
Ruby load%filename
Red require('filename')
Lua require "filename";
Perl, PHP require"filename"
Ruby source(""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 *
Python extern crate libname;
, Rust extern crate libname as altname;
Rust mod modname;
, Rust library("package")
R:IMPORT module
Oberon import altname "package/name"
Go:import package.module;
, D import altname = package.module;
D import Module
, Haskell import qualified Module as M
Haskell import package.*
Java, MATLAB, Kotlin import "modname";
JavaScript:import altname from "modname";
, JavaScript:import package
Scala import package._
, Scala import module
Swift import module
V (Vlang) import module
, Python require('modname')
Lua:require"gem"
, Ruby use module
, Fortran 90+use module, only : identifier
Fortran 90+use Module;
, Perl use Module qw(import options);
Perl use Package.Name
Cobra uses unit
Pascal with package
Ada @import("pkgname");
Zig from module import Class
Python import package.class
Java, MATLAB, kotlin import class from "modname";
, JavaScript import {class} from "modname";
, JavaScript import {class as altname} from "modname";
JavaScript import package.class
, Scala import package.{ class1 => alternativeName, class2 }
, Scala import package._
Scala use Namespace\ClassName;
, PHP use Namespace\ClassName as AliasName;
PHP from 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:useModule('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;
PHP 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).
import altname "package/name"
Go import altname from "modname";
JavaScript import module
Python 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.
{
... }
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 Prolog do
... 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:
Symbol | Languages |
---|---|
comment ~ ; | ALGOL 60, SIMULA |
¢ ~ ¢ ,# ~ # , co ~ co ,comment ~ comment | ALGOL 68 [14] [15] |
/* ~ */ | ActionScript, AutoHotkey, C, C++, C#, D, [16] Go, Java, JavaScript, Kotlin, Objective-C, PHP, PL/I, Prolog, Rexx, Rust (can be nested), Scala (can be nested), SAS, SASS, SQL, Swift (can be nested), V (Vlang), Visual Prolog, CSS |
#cs ~ #ce | AutoIt [17] |
/+ ~ +/ | D (can be nested) [16] |
/# ~ #/ | Cobra (can be nested) |
<# ~ #> | PowerShell |
<!-- ~ --> | HTML, XML |
=begin ~ =cut | Perl (Plain Old Documentation) |
#`( ~ ) | Raku (bracketing characters can be (), <>, {}, [], any Unicode characters with BiDi mirrorings, or Unicode characters with Ps/Pe/Pi/Pf properties) |
=begin ~ =end | Ruby |
#<TAG> ~ #</TAG> , #stop ~ EOF ,#iffalse ~ #endif , #ifntrue ~ #endif ,#if false ~ #endif , #if !true ~ #endif | S-Lang [18] |
{- ~ -} | Haskell (can be nested) |
(* ~ *) | Delphi, ML, Mathematica, Object Pascal, Pascal, Seed7, AppleScript, OCaml (can be nested), Standard ML (can be nested), Maple, Newspeak, F# |
{ ~ } | Delphi, Object Pascal, Pascal, PGN, Red |
{# ~ #} | Nunjucks, Twig |
{{! ~ }} | Mustache, Handlebars |
{{!-- ~ --}} | Handlebars (cannot be nested, but may contain {{ and }} ) |
|# ~ #| | Curl |
%{ ~ %} | MATLAB [13] (the symbols must be in a separate line) |
#| ~ |# | Lisp, Scheme, Racket (can be nested in all three). |
#= ~ =# | Julia [19] |
#[ ~ ]# | Nim [20] |
--[[ ~ ]] ,--[=[ ~ ]=] ,--[= ...=[ ~ ]= ...=] | Lua (brackets can have any number of matching = characters; can be nested within non-matching delimiters) |
" ~ " | Smalltalk |
(comment ~ ) | Clojure |
#If COMMENT Then ~ #End If [lower-alpha 1] | Visual Basic .NET |
#if COMMENT ~ #endif [lower-alpha 2] | C# |
' comment _ or REM comment _ [lower-alpha 3] | Classic Visual Basic, VBA, VBScript |
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.
Language | In-line comment | Block comment |
---|---|---|
Ada, Eiffel, Euphoria, Occam, SPARK, ANSI SQL, and VHDL | -- InlineComment | |
ALGOL 60 | comment BlockComment; | |
ALGOL 68 | ¢ BlockComment ¢
| |
APL | ⍝ InlineComment | |
AppleScript | -- InlineComment | (* BlockComment *) |
Assembly language (varies) | ; InlineComment one example (most assembly languages use line comments only) | |
AutoHotkey | ; InlineComment | /* BlockComment */ |
AWK, Bourne shell, C shell, Maple, PowerShell | # InlineComment | <# BlockComment #> |
Bash | # InlineComment | <<EOF : ' |
BASIC (various dialects): | 'InlineComment (not all dialects)
| |
C (K&R, ANSI/C89/C90), CHILL, PL/I, REXX | /* BlockComment */ | |
C (C99), C++, Go, Swift, JavaScript, V (Vlang) | // InlineComment | /* BlockComment */ |
C# | // InlineComment /// InlineComment (XML documentation comment) | /* BlockComment */ /** BlockComment */ (XML documentation comment)#if COMMENT (Compiler directive) [lower-alpha 2] |
COBOL I to COBOL 85 | * InlineComment (* in column 7) | |
COBOL 2002 | *> InlineComment | |
Curl | ||InlineComment | |# BlockComment #|
|
Cobra | # InlineComment | /# BlockComment #/ (nestable) |
D | // InlineComment /// Documentation InlineComment (ddoc comments) | /* BlockComment */ /** Documentation BlockComment */ (ddoc comments)
|
DCL | $! InlineComment | |
ECMAScript (JavaScript, ActionScript, etc.) | // InlineComment | /* BlockComment */ |
Elixir | # InlineComment | ~S""" @doc """ (Documentation, only works in modules)@moduledoc (Module documentation)@typedoc (Type documentation) |
Forth | \ InlineComment | ( BlockComment ) (single line and multiline)
|
FORTRAN I to FORTRAN 77 | C InlineComment (C in column 1) | |
Fortran 90 and later | ! InlineComment | #if 0 [lower-alpha 4] |
Haskell | -- InlineComment | {- BlockComment -} |
J | NB. | |
Java | // InlineComment | /* BlockComment */
|
Julia | # InlineComment | #=BlockComment=# |
Lisp, Scheme | ; InlineComment | #|BlockComment|# |
Lua | -- InlineComment | --[==[ BlockComment]==] (variable number of = signs, nestable with delimiters with different numbers of = signs) |
Maple | # InlineComment | (* BlockComment *) |
Mathematica | (* BlockComment *) | |
Matlab | % InlineComment | %{ Note: Both percent–bracket symbols must be the only non-whitespace characters on their respective lines. |
Nim | # InlineComment | #[BlockComment]# |
Object Pascal | // InlineComment | (* BlockComment *) { BlockComment } |
OCaml | (* BlockComment (* nestable *) *) | |
Pascal, Modula-2, Modula-3, Oberon, ML: | (* BlockComment *) | |
Perl, Ruby | # InlineComment | =begin (=end in Ruby) (POD documentation comment)
|
PGN, Red | ; InlineComment | { BlockComment } |
PHP | # InlineComment // InlineComment | /* BlockComment */ /** Documentation BlockComment */ (PHP Doc comments) |
PILOT | R:InlineComment | |
PLZ/SYS | ! BlockComment ! | |
PL/SQL, TSQL | -- InlineComment | /* BlockComment */ |
Prolog | % InlineComment | /* BlockComment */ |
Python | # InlineComment | '''BlockComment''' (Documentation string when first line of module, class, method, or function) |
R | # InlineComment | |
Raku | # InlineComment | #`{
|
Rust | // InlineComment
| /* BlockComment */ (nestable)
|
SAS | * BlockComment; /* BlockComment */ | |
Seed7 | # InlineComment | (* BlockComment *) |
Simula | comment BlockComment; ! BlockComment; | |
Smalltalk | "BlockComment" | |
Smarty | {* BlockComment *} | |
Standard ML | (* BlockComment *) | |
TeX, LaTeX, PostScript, Erlang, S-Lang | % InlineComment | |
Texinfo | @c InlineComment
| |
TUTOR | * InlineComment command $$ InlineComment | |
Visual Basic | 'InlineComment Rem InlineComment | 'BlockComment _ Rem BlockComment _ [lower-alpha 3] |
Visual Basic .NET | 'InlineComment
| #If COMMENT Then |
Visual Prolog | % InlineComment | /* BlockComment */ |
Wolfram Language | (* BlockComment *) | |
Xojo | ' InlineComment // InlineComment rem InlineComment | |
Zig | // InlineComment /// InlineComment //! InlineComment |
A "Hello, World!" program is generally a simple computer program which outputs to the screen a message similar to "Hello, World!" while ignoring any user input. A small piece of code in most general-purpose programming languages, this program is used to illustrate a language's basic syntax. A "Hello, World!" program is often the first written by a student of a new programming language, but such a program can also be used as a sanity check to ensure that the computer software intended to compile or run source code is correctly installed, and that its operator understands how to use it.
Ruby is an interpreted, high-level, general-purpose programming language. It was designed with an emphasis on programming productivity and simplicity. In Ruby, everything is an object, including primitive data types. It was developed in the mid-1990s by Yukihiro "Matz" Matsumoto in Japan.
This is a "genealogy" of programming languages. Languages are categorized under the ancestor language with the strongest influence. Those ancestor languages are listed in alphabetic order. Any such categorization has a large arbitrary element, since programming languages often incorporate major ideas from multiple sources.
A string literal or anonymous string is a literal for a string value in the source code of a computer program. Modern programming languages commonly use a quoted sequence of characters, formally "bracketed delimiters", as in x = "foo"
, where "foo"
is a string literal with value foo
. Methods such as escape sequences can be used to avoid the problem of delimiter collision and allow the delimiters to be embedded in a string. There are many alternate notations for specifying string literals especially in complicated cases. The exact notation depends on the programming language in question. Nevertheless, there are general guidelines that most modern programming languages follow.
YAML(see § History and name) is a human-readable data serialization language. It is commonly used for configuration files and in applications where data is being stored or transmitted. YAML targets many of the same communications applications as Extensible Markup Language (XML) but has a minimal syntax that intentionally differs from Standard Generalized Markup Language (SGML). It uses Python-style indentation to indicate nesting and does not require quotes around most string values.
uuencoding is a form of binary-to-text encoding that originated in the Unix programs uuencode and uudecode written by Mary Ann Horton at the University of California, Berkeley in 1980, for encoding binary data for transmission in email systems.
printf is a C standard library function that formats text and writes it to standard output.
In computer programming, glob patterns specify sets of filenames with wildcard characters. For example, the Unix Bash shell command mv *.txttextfiles/
moves all files with names ending in .txt
from the current directory to the directory textfiles
. Here, *
is a wildcard and *.txt
is a glob pattern. The wildcard *
stands for "any string of any length including empty, but excluding the path separator characters ".
The off-side rule describes syntax of a computer programming language that defines the bounds of a code block via indentation.
In computer programming, a one-liner program originally was textual input to the command line of an operating system shell that performed some function in just one line of input. In the present day, a one-liner can be
In computing, a here document is a file literal or input stream literal: it is a section of a source code file that is treated as if it were a separate file. The term is also used for a form of multiline string literals that use similar syntax, preserving line breaks and other whitespace in the text.
In computer programming, an entry point is the place in a program where the execution of a program begins, and where the program has access to command line arguments.
A foreign function interface (FFI) is a mechanism by which a program written in one programming language can call routines or make use of services written or compiled in another one. An FFI is often used in contexts where calls are made into binary dynamic-link library.
The syntax of the Python programming language is the set of rules that defines how a Python program will be written and interpreted. The Python language has many similarities to Perl, C, and Java. However, there are some definite differences between the languages. It supports multiple programming paradigms, including structured, object-oriented programming, and functional programming, and boasts a dynamic type system and automatic memory management.
Coding conventions are a set of guidelines for a specific programming language that recommend programming style, practices, and methods for each aspect of a program written in that language. These conventions usually cover file organization, indentation, comments, declarations, statements, white space, naming conventions, programming practices, programming principles, programming rules of thumb, architectural best practices, etc. These are guidelines for software structural quality. Software programmers are highly recommended to follow these guidelines to help improve the readability of their source code and make software maintenance easier. Coding conventions are only applicable to the human maintainers and peer reviewers of a software project. Conventions may be formalized in a documented set of rules that an entire team or company follows, or may be as informal as the habitual coding practices of an individual. Coding conventions are not enforced by compilers.
In computer programming, a comment is a programmer-readable explanation or annotation in the source code of a computer program. They are added with the purpose of making the source code easier for humans to understand, and are generally ignored by compilers and interpreters. The syntax of comments in various programming languages varies considerably.
JuffEd is a text editor for programmers and advanced users. It is designed to be a simple and lightweight cross-platform text editor. It uses Qt4 toolkit and QScintilla editing component.
Many programming languages and other computer files have a directive, often called include
, import
, or copy
, that causes the contents of the specified file to be inserted into the original file. These included files are called header files or copybooks. They are often used to define the physical layout of program data, pieces of procedural code, and/or forward declarations while promoting encapsulation and the reuse of code or data.
The structure of the Perl programming language encompasses both the syntactical rules of the language and the general ways in which programs are organized. Perl's design philosophy is expressed in the commonly cited motto "there's more than one way to do it". As a multi-paradigm, dynamically typed language, Perl allows a great degree of flexibility in program design. Perl also encourages modularization; this has been attributed to the component-based design structure of its Unix roots, and is responsible for the size of the CPAN archive, a community-maintained repository of more than 100,000 modules.
/* ... */
, 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.