Category:Programming paradigm/Functional: Difference between revisions

Broken link repaired
(Moved content from paradigms page)
(Broken link repaired)
 
(One intermediate revision by one other user not shown)
Line 1:
{{feature|Programming paradigm}}'''Functional programming''' treats functions as the fundamental first-class objects of the programming language. That hasIn several consequencesaddition:
 
*# It'sState notchanges possibleare toencapsulated updatein variablesfunction (orresults, otherin ''state'')this inparadigm, arather step-by-stepthan fashionin side effects, as in [[imperative programming]].
*# Hence,This allmakes dependencies must be made explicit.
*# ThatThis leads to [http://www.haskell.org/haskellwiki/Referential_transparency referential transparency] -- given the same arguments, a piece of code will always behave identically.
*# Coding is '''compositional''' -- any two pieces of code with a matching 'interface', as specified by thefunction typedomains, can be combined, because no hidden side-effects can intervene. (See [httphttps://www.stanfordthocp.edunet/classbiographies/cs242papers/readings/backusbackus_turingaward_lecture.pdf ''Can Programming Be Liberated from the von Neumann Style? A Functional Style and Its Algebra of Programs''] by John Backus, 1977 Turing Award Lecture).
*# It's easy to '''refactor''' similar pieces of code, because any subexpression can be replaced by a variable bound at the outside.
 
This leads to a coding style which is very different from more traditional languages. [[Iteration]] ismay typicallybe replaced by [[:Category:Recursion|tail-recursion]] or delegated to other functions. Lists become a very important datatype. Code often consists of a composition of simpler blocks, which makes it look similar to [[declarative programming]].
 
Most functional programming languages (FPLs) are related to the [[wp:Lambda_Calculus|lambda calculus]], which makes the specification of their formal semantics simpler.
Anonymous user