Expression-oriented programming language
{{Notability|date=July 2022}}
An expression-oriented programming language is a programming language in which every (or nearly every) construction is an expression and thus yields a value.{{Cite web |title=Glossary - The Rust Programming Language |url=https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/glossary.html#expression-oriented-language |access-date=2022-07-06 |website=web.mit.edu}} The typical exceptions are macro definitions, preprocessor commands, and declarations, which expression-oriented languages often treat as statements.
Lisp{{Cite journal |last1=Syme |first1=Don |date=2020-06-14 |title=The early history of F# |journal=Proceedings of the ACM on Programming Languages |language=en |volume=4 |issue=HOPL |pages=1–58 |doi=10.1145/3386325 |issn=2475-1421 |doi-access=free}} and ALGOL 68 are expression-oriented languages. Pascal is not an expression-oriented language.
All functional programming languages are expression-oriented.{{Cite web |author1=Knoldus |date=2018-02-08 |title=Expression Oriented Programming |url=https://medium.com/knoldus/expression-oriented-programming-d88f621fd3a4 |access-date=2023-08-07 |website=Knoldus – Technical Insights |language=en}}
Criticism and prevention
{{Synthesis|date=July 2022}}
{{See also|Assignment (computer science)#Assignment versus equality|Relational operator#Confusion with assignment operators}}
Critics, including language designers,[https://www.oracle.com/java/technologies/javase/codeconventions-programmingpractices.html#547 Java Code Conventions "10.4 Variable Assignments"]{{Failed verification|date=July 2022}} blame expression-orientation for an entire class of programming mistakes wherein a programmer accidentally codes an assignment expression, which replaces a variable with an expression rather than testing it for equality with that expression.
The designers of Ada and Java prevent this type of mistake by restricting control expressions to those that evaluate strictly to the boolean data type.[https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.9 The Java Language Specification, Java SE 8 Edition "14.9 The if Statement"][https://www.adaic.org/learn/materials/intro/part4/ Introducing Ada]
The designers of Python implemented assignment as a statement rather than an expression, thus prohibiting assignment from nesting inside any other statement or expression.[https://docs.python.org/3/reference/simple_stmts.html#assignment The Python Language Reference "6.2. Assignment statements"] (Until version 3.8 added 'assignment expressions', with a different syntax.[https://www.python.org/dev/peps/pep-0572/ "PEP 572: Assignment Expressions"])
In some expression-oriented languages, expressions that merely cause side effects return void types.
Examples
{{More citations needed|date=July 2022}}
{{Expand section|date=February 2018}}
- ALGOL 68
- BLISS
- Icon
- Lisp
- ML
- Perl
- Rebol
- Ruby
- Elixir
- Erlang
- Haskell
- Rust{{Cite web |title=Functions - The Rust Programming Language |url=https://web.mit.edu/rust-lang_v1.25/arch/amd64_ubuntu1404/share/doc/rust/html/book/first-edition/functions.html#expressions-vs-statements |access-date=2022-07-06 |website=web.mit.edu}}
- Scala
- Smalltalk
- Kotlin
- OCaml{{Cite web |title=COS 326: Functional Programming |url=https://www.cs.princeton.edu/~dpw/courses/cos326-12/notes/type-check.php |access-date=2022-07-06 |website=www.cs.princeton.edu}}