Comparison of programming languages

Last updated

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

Contents

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.

Most programming languages are not standardized by an international (or national) standard, even widely used ones, such as Perl or Standard ML (despite the name). Notable standardized programming languages include ALGOL, C, C++, JavaScript (under the name ECMAScript), Smalltalk, Prolog, Common Lisp, Scheme (IEEE standard), ISLISP, Ada, Fortran, COBOL, SQL, and XQuery.

General comparison

The following table compares general and technical information for a selection of commonly used programming languages. See the individual languages' articles for further information.

Type systems

Failsafe I/O and system calls

Most programming languages will print an error message 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 programmers explicitly add checks for these kinds of errors. Psychologically, different cognitive biases (e.g., optimism bias) may affect novices and experts alike and lead them to skip these checks. This can lead to erroneous behavior.

Failsafe I/O is a feature of 1C:Enterprise, Ada (exceptions), ALGOL (exceptions or return value depending on function), Ballerina, C#, Common Lisp ("conditions and restarts" system), Curry, D (throwing on failure), [44] Erlang, Fortran, Go (unless result explicitly ignored), Gosu, Harbour, Haskell, ISLISP, Java, Julia, Kotlin, LabVIEW, Mathematica, Objective-C (exceptions), OCaml (exceptions), OpenLisp, PHP, Python, Raku, Rebol, Rexx (with optional signal on... trap handling), Ring, Ruby, Rust (unless result explicitly ignored), Scala, [45] Smalltalk, Standard ML [ citation needed ], Swift ≥ 2.0 (exceptions), Tcl, Visual Basic, Visual Basic .NET, Visual Prolog, Wolfram Language, Xojo, XPath/XQuery (exceptions), and Zeek.

No Failsafe I/O: AutoHotkey (global ErrorLevel must be explicitly checked), C, [46] COBOL, Eiffel (it actually depends on the library and it is not defined by the language), GLBasic (will generally cause program to crash), RPG, Lua (some functions do not warn or throw exceptions), and Perl. [47]

Some I/O checking is built in C++ (STL iostreams throw on failure but C APIs like stdio or POSIX do not) [46] and Object Pascal, in Bash [48] it is optional.

Expressiveness

LanguageStatements ratio [49] Lines ratio [50]
C11
C++2.51
Fortran20.8
Java2.51.5
Perl66
Smalltalk66.25
Python66.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. [51] 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. [52]

Benchmarks

Barplot of log-time to produce a 16002 Mandelbrot as reported in The Benchmarks Game Barplot language speeds (Benchmarks Game Mandelbrot).svg
Barplot of log-time to produce a 1600² Mandelbrot as reported in The Benchmarks Game

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. [55]

Timeline of specific language comparisons

See also

To display all pages, subcategories and images click on the "►":

Related Research Articles

<span class="mw-page-title-main">Ada (programming language)</span> High-level programming language first released in 1980

Ada is a structured, statically typed, imperative, and object-oriented high-level programming language, inspired by Pascal and other languages. It has built-in language support for design by contract (DbC), extremely strong typing, explicit concurrency, tasks, synchronous message passing, protected objects, and non-determinism. Ada improves code safety and maintainability by using the compiler to find errors in favor of runtime errors. Ada is an international technical standard, jointly defined by the International Organization for Standardization (ISO), and the International Electrotechnical Commission (IEC). As of May 2023, the standard, called Ada 2022 informally, is ISO/IEC 8652:2023.

C is a general-purpose computer programming language. It was created in the 1970s by Dennis Ritchie, and remains very widely used and influential. By design, C's features cleanly reflect the capabilities of the targeted CPUs. It has found lasting use in operating systems, device drivers, and protocol stacks, but its use in application software has been decreasing. C is commonly used on computer architectures that range from the largest supercomputers to the smallest microcontrollers and embedded systems.

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.

In computer programming, operator overloading, sometimes termed operator ad hoc polymorphism, is a specific case of polymorphism, where different operators have different implementations depending on their arguments. Operator overloading is generally defined by a programming language, a programmer, or both.

Pascal is an imperative and procedural programming language, designed by Niklaus Wirth as a small, efficient language intended to encourage good programming practices using structured programming and data structuring. It is named after French mathematician, philosopher and physicist Blaise Pascal.

In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

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.

Programming languages can be grouped by the number and types of paradigms supported.

<span class="mw-page-title-main">Conditional (computer programming)</span> Control flow statement that executes code according to some condition(s)

In computer science, conditionals are programming language commands for handling decisions. Specifically, conditionals perform different computations or actions depending on whether a programmer-defined Boolean condition evaluates to true or false. In terms of control flow, the decision is always achieved by selectively altering the control flow based on some condition . Although dynamic dispatch is not usually classified as a conditional construct, it is another way to select between alternatives at runtime. Conditional statements are the checkpoints in the programme that determines behaviour according to situation.

<span class="mw-page-title-main">History of programming languages</span> History of languages used to program computers

The history of programming languages spans from documentation of early mechanical computers to modern tools for software development. Early programming languages were highly specialized, relying on mathematical notation and similarly obscure syntax. Throughout the 20th century, research in compiler theory led to the creation of high-level programming languages, which use a more accessible syntax to communicate instructions.

In computer programming, a statement is a syntactic unit of an imperative programming language that expresses some action to be carried out. A program written in such a language is formed by a sequence of one or more statements. A statement may have internal components.

In computer science, the Boolean is a data type that has one of two possible values which is intended to represent the two truth values of logic and Boolean algebra. It is named after George Boole, who first defined an algebraic system of logic in the mid 19th century. The Boolean data type is primarily associated with conditional statements, which allow different actions by changing control flow depending on whether a programmer-specified Boolean condition evaluates to true or false. It is a special case of a more general logical data type—logic does not always need to be Boolean.

In computer science, a relational operator is a programming language construct or operator that tests or defines some kind of relation between two entities. These include numerical equality and inequalities.

In computer programming, a nested function is a named function that is defined within another, enclosing, block and is lexically scoped within the enclosing block – meaning it is only callable by name within the body of the enclosing block and can use identifiers declared in outer blocks, including outer functions. The enclosing block is typically, but not always, another function.

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.

This comparison of programming languages compares the features of language syntax (format) for over 50 computer programming languages.

This article compares a large number of programming languages by tabulating their data types, their expression, statement, and declaration syntax, and some common operating-system interfaces.

References

  1. As of May 2006 Diarmuid Pigott's Encyclopedia of Computer Languages Archived 2011-02-20 at the Wayback Machine hosted at Murdoch University, Australia lists 8512 computer languages.
  2. Ada Reference Manual, ISO/IEC 8652:2005(E) Ed. 3, 3.9 Tagged Types and Type Extensions
  3. Ada Reference Manual, ISO/IEC 8652:2005(E) Ed. 3, Section 6: Subprograms
  4. Ada Reference Manual, ISO/IEC 8652:2005(E) Ed. 3, Section 12: Generic Units
  5. Ada Reference Manual, ISO/IEC 8652:2005(E) Ed. 3, Section 9: Tasks and Synchronization
  6. Ada Reference Manual, ISO/IEC 8652:2005(E) Ed. 3 Annex E: Distributed Systems
  7. "Vak.ru" (PDF). Archived from the original (PDF) on 2017-03-30. Retrieved 2008-08-09.
  8. ISO 1538:1984
  9. "Vak.ru" (PDF). Archived from the original (PDF) on 2017-03-24. Retrieved 2008-08-09.
  10. IEEE 694-1985
  11. Objects - Definition & Usage
  12. "Ballerina Language Specification" (PDF). WSO2. 2018-05-01. Archived from the original (PDF) on 2018-05-04. Retrieved 2018-05-03.
  13. 1 2 3 POSIX.2, Shell and Utilities, Command Interpreter (IEEE Std 1003.2-1992.)
  14. JSR 274
  15. bell-labs.com
  16. ANSI C89, ISO/IEC 9899:1990, 1999, 2011, 2018
  17. ISO/IEC 14882:1998, 2003, 2011, 2014, 2017, 2020
  18. Codeproject.com: Functional Programming in C# 3.0 using Lambda Expression
  19. ECMA-334; ISO/IEC 23270:2006
  20. Softvelocity.com
  21. "Crystal". GitHub . 2 November 2021.
  22. "Crystal Generics". crystal-lang.org. 13 April 2024.
  23. "Concurrency - Crystal". crystal-lang.org. Retrieved 2024-04-02.{{cite web}}: CS1 maint: url-status (link)
  24. Basic Eiffel language mechanisms
  25. Closure (computer programming)
  26. ECMA-367; ISO/IEC 25436:2006
  27. The Go Programming Language (FAQ)
  28. JSR 241
  29. "The Haskell 2010 Language Report" . Retrieved 2011-12-07. Most Haskell implementations extend the Haskell 2010 standard.
  30. "M8 is out!". 2 July 2014. As a first peek into the future reflective capabilities of Kotlin, you can now access properties as first-class objects in Kotlin
  31. Halcyon (Inworldz) and Open Sims propose compatible implementations with additional functions.
  32. Lua does not have explicit "object" type (more general type of "table" is used for object definition), but does have explicit syntax for object method calling
  33. Version releases are accompanied with a definitive Lua Reference Manual showing full syntax and semantics; a reference implementation, and a test suite. These are used to generate other Lua VM implementations and compilers such as Kahlua and LLVM-Lua.
  34. ISO/IEC 10514-1:1996
  35. ISO 7185
  36. PHP Manual, Chapter 19. Classes and Objects (PHP 5),
  37. PHP Manual, Chapter 17. Functions
  38. "PostScript Language Reference Manual" (PDF). Archived from the original (PDF) on 2017-02-18. Retrieved 2017-02-18.
  39. Is Rust an Object-Oriented Programming Language?
  40. Klabnik, Steve; Nichols, Carol. "Macros". The Rust Programming Language.
  41. R3RS, R4RS, R5RS, R6RS, R7RS Small Edition
  42. R0RS, R1RS, R2RS
  43. SMLNJ.org
  44. "STD.stdio - D Programming Language".
  45. Scala runs on the Java Virtual Machine from which it inherits the runtime exception handling.
  46. 1 2 gcc can warn on unchecked errno. Newer versions of Visual Studio usually throw exceptions on failed I/O when using stdio.
  47. Considerable error checking can be enabled optionally, but by default Perl is not failsafe.
  48. set -e enables termination if any unchecked exit status is nonzero.
  49. Data from McConnell, Steve (30 November 2009). Code Complete. Microsoft Press. p. 100. ISBN   9780735636972. 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.
  50. The ratio of line count tests won by each language to the number won by C when using the Compare to feature at McLoone, Jon (November 14, 2012). "Code Length Measured in 14 Languages". Archived from the original on 2012-11-19. 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.
  51. Felleisen, Matthias. On the Expressive Power of Programming Languages. ESOP '90 3rd European Symposium on Programming. CiteSeerX   10.1.1.51.4656 .
  52. "How programs are measured". Computer Language Benchmarks Game. Retrieved 2018-05-29.
  53. Mandelbrot, Benoit B. (1982). The fractal geometry of nature (Revised ed.). San Francisco. ISBN   0-7167-1186-9. OCLC   7876824.{{cite book}}: CS1 maint: location missing publisher (link)
  54. "Mandelbrot". Computer Language Benchmarks Game. Retrieved 2021-07-09.
  55. "The Ultimate Benchmark". The Computer Language Benchmarks Game. Retrieved 2018-05-29.
  56. Valentine, S. H. (November 1974). "Comparative Notes on Algol 68 and PL/I". The Computer Journal. 17 (4): 325–331. doi: 10.1093/comjnl/17.4.325 .
  57. "Vrije Universiteit Amsterdam" (PDF).

Further reading