Comparison of programming languages

This is an old revision of this page, as edited by 220.225.78.66 (talk) at 04:42, 2 July 2015 (General comparison). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Programming languages are used for controlling the behavior of a machine (often a computer). Like natural languages, programming languages conform to rules for syntax and semantics.

There are thousands of programming languages[1] and new ones are created every year. Few languages ever become sufficiently popular that they are used by more than a few people, but professional programmers may use dozens of languages in a career.

Type systems

Brief definitions

  • A nominal type system means that the language decides whether types are compatible and/or equivalent based on explicit declarations and names.
  • A structural type system means that the language decides whether types are compatible and/or equivalent based on the definition and characteristics of the types.
  • Type checking determines whether and when types are verified. Static checking means that type errors are reported based on a program's text (source code). Dynamic checking means that type errors are reported based on a program's dynamic (run-time) behavior.
Language Type safety Type expression Type compatibility and equivalence Type checking
ActionScript 3.0 safe implicit with optional explicit typing static
Ada safe[TS 1] explicit nominal static
Aldor unsafe implicit static
ALGOL 58 safe explicit static
ALGOL 60 safe explicit static
ALGOL 68 safe explicit structural static & tagged unions
APL safe dynamic
AutoHotkey typeless n/a n/a n/a
Ateji PX safe explicit nominal static
Bash ? ? ? ?
BASIC safe explicit nominal static
BLISS typeless n/a n/a n/a
BeanShell safe nominal dynamic
Boo safe implicit with optional explicit typing static with optional dynamic typing
Bro safe implicit with optional explicit typing nominal static
C unsafe explicit nominal static
C++ (ISO/IEC 14882) unsafe explicit nominal static[TS 2]
C# unsafe[TS 3] implicit with optional explicit typing nominal static[TS 4]
Clean safe implicit static
Clojure safe implicit with optional explicit typing dynamic
COBOL safe explicit nominal static
ColdFusion (CFML) safe implicit dynamic
Common Lisp safe implicit with optional explicit typing dynamic
Curl safe nominal
Cython safe implicit with optional explicit typing nominal (extension types) and structural (Python) dynamic with optional static typing
D unsafe[TS 3] explicit nominal static
Dylan safe dynamic
Eiffel safe nominal static
Erlang safe implicit dynamic
Euphoria safe explicit, implicit with objects nominal static, dynamic with objects
F# safe implicit nominal static
Falcon safe implicit structural dynamic
Forth typeless n/a n/a n/a
Fortran safe explicit[TS 5] nominal static
Gambas safe explicit nominal
GLBasic safe explicit. Non-explicit declarations available through project options nominal static
Go[2] safe implicit with optional explicit typing structural static
Gosu safe partially implicit (local type inference) nominal (subclassing) and structural (structural) static
Groovy safe implicit with optional explicit typing dynamic with optional static typing
Harbour safe implicit with optional explicit typing dynamic
Haskell safe implicit with optional explicit typing structural static
Haxe safe implicit with optional explicit typing nominal (subclassing) and structural (structural) static with optional dynamic typing
Io safe implicit dynamic
ISLISP safe dynamic
J safe dynamic
Java safe[3] explicit nominal static
JavaScript safe implicit structural dynamic
Julia safe implicit with optional explicit typing[4]
Joy safe dynamic
Kotlin safe partially implicit (local type inference) nominal static
LabVIEW safe
Lua safe implicit dynamic
Maple safe dynamic
Mathematica safe dynamic
MATLAB M-code safe dynamic
Modula-2 unsafe[TS 3] explicit nominal static
Modula-3 unsafe[TS 3] explicit structural static
MUMPS (M) typeless n/a n/a n/a
Oberon safe explicit nominal static and partially dynamic[TS 6]
Objective-C safe explicit nominal dynamic with optional static typing[5]
OCaml safe implicit with optional explicit typing structural (records are nominal) static
Object Pascal (Delphi) safe explicit nominal static
Opa safe implicit with optional explicit typing structural static
Oxygene unsafe implicit static
Oz safe implicit structural dynamic
Pascal unsafe[TS 3] explicit nominal static
Perl 5 implicit dynamic
Perl 6 partially implicit[TS 7] dynamic with optional static typing
PHP implicit dynamic
Plus safe explicit structural static, dynamic (optional)
Prolog dynamic
Pure dynamic
Python safe implicit structural dynamic
REBOL safe implicit dynamic
Rexx typeless n/a, implicit wrt numbers n/a static+dynamic wrt numbers
RPG unsafe static
Ruby safe implicit structural dynamic
Rust safe implicit with optional explicit typing static with optional dynamic typing
S dynamic
S-Lang safe implicit dynamic
Scala safe partially implicit (local type inference) nominal (subclassing) and structural (structural) static
Scheme safe implicit dynamic (latent)
Seed7 safe explicit nominal static
Simula safe static[TS 8]
Smalltalk safe implicit dynamic
Swift safe partially implicit (local type inference) nominal (subclassing) and structural (structural) static
Standard ML safe implicit with optional explicit typing structural static
Tcl dynamic
Visual Basic safe implicit with optional explicit typing nominal static
Visual Basic .NET unsafe[TS 3] explicit static
Visual Prolog safe partially implicit nominal static
Windows PowerShell safe implicit dynamic
XL safe nominal static
Xojo safe explicit nominal static
Language Type safety Type expression Type compatibility among composites Type checking
  1. ^ Unsafe operations are well isolated by a "Unchecked_" prefix.
  2. ^ with optional dynamic type casting (see dynamic cast)
  3. ^ a b c d e f It is almost safe, unsafe features are not commonly used.
  4. ^ with optional dynamic type (see dynamic member lookup)
  5. ^ Optionally, typing can be explicitly implied by the first letter of the identifier (known as implicit typing within the Fortran community).
  6. ^ dynamic checking of type extensions i.e. inherited types
  7. ^ explicit for static types
  8. ^ optional for formal and virtual procedures

Failsafe I/O and system calls

Most programming languages will print an error message and/or throw an exception if an input/output operation or other system call (e.g., chmod, kill) fails, unless the programmer has explicitly arranged for different handling of these events. Thus, these languages fail safely in this regard.

Some (mostly older) languages require that the programmer explicitly add checks for these kinds of errors. Psychologically, different cognitive biases (e.g., optimism bias) may affect novice and experts alike and these omissions can lead to erroneous behavior.

Language Failsafe I/O
Ada Yes (exceptions)
ALGOL Yes (exceptions or return value depending on function)
AutoHotkey No (global ErrorLevel must be explicitly checked)
Bash ?
Bro Yes
C No[FSIO 1]
C++ No[FSIO 2]
C# Yes
COBOL No
Common Lisp Yes
D Yes[citation needed]
Eiffel No – It actually depends on the library and it is not defined by the language
Erlang Yes
Falcon Yes
Fortran Yes
GLBasic No – Will generally cause program to crash
Go Yes (unless result explicitly ignored)
Gosu Yes
Harbour Yes
Haskell Yes
ISLISP Yes
Java Yes
Julia Yes
Kotlin Yes
LabVIEW Yes
Lua No (some functions do not warn or throw exceptions)
Mathematica Yes
Object Pascal (Delphi) Some
Objective-C Yes (exceptions)
OCaml Yes (exceptions)
Perl No[FSIO 3]
Perl 6 Yes
PHP Yes
Python Yes
REBOL Yes
Rexx Yes (with optional signal on… trap handling)
RPG No
Ruby Yes
Rust Yes (unless result explicitly ignored)
S Un­known
Smalltalk Yes
Scala Yes[6]
Standard ML Yes[citation needed]
Tcl Yes
Visual Basic Yes
Visual Prolog Yes
Xojo Yes
Language Failsafe I/O
  1. ^ gcc can warn on unchecked error status. Newer versions of Visual Studio usually throw exceptions on failed I/O when using stdio.
  2. ^ g++ can warn on unchecked error status. Newer versions of Visual Studio usually throw exceptions on failed I/O when using stdio.
  3. ^ Considerable error checking can be enabled optionally, but by default Perl is not failsafe.

Expressiveness

Language Statements ratio[7] Lines ratio[8]
C 1 1
C++ 2.5 1
Fortran 2 0.8
Java 2.5 1.5
Perl 6 6
Smalltalk 6 6.25
Python 6 6.5

The literature on programming languages contains an abundance of informal claims about their relative expressive power, but there is no framework for formalizing such statements nor for deriving interesting consequences.[9] This table provides two measures of expressiveness from two different sources. An additional measure of expressiveness, in GZip bytes, can be found on the Computer Language Benchmarks Game.

Benchmarks

Benchmarks are designed to mimic a particular type of workload on a component or system. The computer programs used for compiling some of the benchmark data in this section may not have been fully optimized, and the relevance of the data is disputed. The most accurate benchmarks are those that are customized to your particular situation. Other people's benchmark data may have some value to others, but proper interpretation brings many challenges. The Computer Language Benchmarks Game site warns against over-generalizing from benchmark data, but contains a large number of micro-benchmarks of reader-contributed code snippets, with an interface that generates various charts and tables comparing specific programming languages and types of tests.

Timeline of specific language comparisons

See also

References

  1. ^ As of May 2006 Diarmuid Pigott's Encyclopedia of Computer Languages hosted at Murdoch University, Australia lists 8512 computer languages.
  2. ^ The Go Programming Language Specification
  3. ^ Sheng Liang, Gilad Bracha. Dynamic class loading in the Java virtual machine. Volume 33, Issue 10 of ACM SIGPLAN Notices, October 1998.
  4. ^ http://julia.readthedocs.org/en/latest/manual/types/
  5. ^ Developer.apple.com
  6. ^ Scala runs on the Java Virtual Machine from which it inherits the runtime exception handling.
  7. ^ Data from Code Complete, p. 100. The Statements ratio column "shows typical ratios of source statements in several high-level languages to the equivalent code in C. A higher ratio means that each line of code in the language listed accomplishes more than does each line of code in C.
  8. ^ The ratio of line count tests won by each language to the number won by C when using the Compare to feature at benchmarksgame.alioth.debian.org. Last updated May, 2006. C gcc was used for C, C++ g++ was used for C++, FORTRAN G95 was used for FORTRAN, Java JDK Server was used for Java, and Smalltalk GST was used for Smalltalk.
  9. ^ Felleisen, Matthias. On the Expressive Power of Programming Languages. ESOP '90 3rd European Symposium on Programming. CiteSeerx10.1.1.51.4656 .
  10. ^ http://dare.ubvu.vu.nl/bitstream/1871/2609/1/11054.pdf

Further reading