Functional programming is a programming paradigm that treats computation as the evaluation of mathematical functions and avoids state and mutable data. It emphasizes the application of functions, in contrast to the imperative programming style, which emphasizes changes in state with assignments and loops. In functional languages, the only way a function can "change something" is by returning a new value. As a result, there are no assignment statements or loops in functional languages such as Clojure. Instead, side effects occur by returning new values from functions. Because functional languages do not have looping constructs, the statements they contain are usually denoted by indentation. Many functional programming concepts are used in other paradigms, most notably object-oriented programming. Functional programming advocates advocate for the use of immutable data structures throughout core programs. This results in an application that is fast, uses less memory and avoids having to manage database connections. Some individual programs may require mutable state for certain industry or commercial rules. Other languages, such as Scala or Clojure also provide mutable state encapsulation features that allow the programmer to define immutable data structures that can be mutated without affecting the whole application program. Scala also provides additional features that support functional programming, including pattern matching and ADT that seamlessly allows for the creation of persistent data structures, which are later saved to database. Functional language implementations are not necessarily compiled into machine language. Instead, they are translated into an intermediate form called bytecode or an abstract form called bytecode. This is akin to Java's Java Virtual Machine or Microsoft's Common Language Runtime. There is a functional virtual machine for .NET available as well as an interpreter for Python 3. Data in functional languages may not have mutable fields, but the actual program state can be changed by returning new states from functions. This is called "side effects". Functional programming languages often create immutable data structures for the programmer to use, but the full program state (objects, arrays etc.) can be changed. Each function must act on its own arguments and return new values, or return some kind of "void" or null value so that no new state is created. Functional programming languages are often eager by default (i.e., each function is executed as it is encountered in the program text). This means that if a function calls itself directly or indirectly then execution will enter an infinite loop. Functional programming languages usually require all functions to terminate execution by explicitly returning a value, by throwing an exception, or by diverging (which may cause side-effects). In some functional languages, such as Clojure, this restriction on use of recursion is relaxed as an optional feature. In some other functional programming languages, such as F#, recursion is entirely supported within the language. Functional programs frequently perform data processing in parallel. This is particularly advantageous when changing input data or computing output data based on multiple inputs. The prevalent ways of achieving high performance parallelism are multithreading and arrays of threads. These techniques are commonplace in many other languages, but they are not typically found in functional languages. 8eeb4e9f32 20
broominunmacmistre
Comentários