====== 2.1.3.3 Functional Programming ====== [[dido:public:s_cli:05_contents:01_prt:02_basics:03_paradigim:start| Return to Programming Paradigm ]] The [[dido:public:ra:xapend:xapend.a_glossary:f:functionalprogramming]] methodology focuses on results, not the process. Therefore, there can be many different ways to achieve the desired results and none of the different approaches are right or wrong. This is ideal when trying to integrate multiple existing technologies and/or products together when they are providing the same or very similar __**Function**__. Therefore, a key aspect of the Functional Programming methodology is the decomposition of the domain problem space (i.e., DIDOs) into a set of well defined, deterministic functions, in other words, the same set of inputs always produce the same set of outputs regardless of when it is run or the the order the functions are run in. The Functions are self contained and do not create any side effects or depend on any side effects. Simplistically it means that there is no interaction with external data from within the function. This is very similar to the mathematical definition of a function which uses relational expressions and recursion to do perform the calculations. It does not support iteration like loop statements and conditional statements like If-Else. The data that is passed into the function is [[dido:public:ra:xapend:xapend.a_glossary:i:immutable|immutable]] (it can not be changed).(( Guru99, Accessed: 13 April 2021, [[https://www.guru99.com/functional-programming-tutorial.html]] )) Some examples of Functional [[dido:public:ra:xapend:xapend.a_glossary:p:programlang|Programming Languages]] are: * Clean * Clojure * Erlang * F# * Haskell * Make * Mathematica * ML/OCaml [[dido:public:ra:xapend:xapend.a_glossary:l:lisp]] / Scheme * Scala * SML * SQL * XSLT In Figure {{ref>funcproglang}}, the green boxes represent functions and the blue cylinders represent the data that flows into the function. Note, there is no data other than the data passed into the function used by the function. There are no decision points (i.e., diamonds) on the diagram.
{{ dido:public:s_cli:05_contents:01_prt:02_basics:screen_shot_2021-04-12_at_10.44.36_pm.png?600 |}} Function Programming - Data Flows
The DIDO [[dido:public:ra:xapend:xapend.a_glossary:c:cli|Command Line Interface]] (DIDO-CL) is a hybrid of [[dido:public:ra:xapend:xapend.a_glossary:f:functionallanguage]] and a [[dido:public:ra:xapend:xapend.a_glossary:p:procedurallanguage]]. The Functional aspects are built around operations that are similar to mathematical functions. For example, the summation of a column of numbers, the insertion, update or deletion of data into a RDBMS. In Functional languages the action comes first and the the thing the action is to be applied to: ^ CLI ^ Function ^ Data ^ Description ^ | SQL | INSERT | DbTable | Insert data into DbTable | | SQL | UPDATE | DbTable | Update data of DbTable | | SQL | DELETE | DbTable | Delete data from DbTable | | POSIX | ls | Filespec | list the files in Filespec directory | | POSIX | rm | Filespec | remove files in the Filespec directory | | POSIX | ps | Owner | Process Status (ps) for processes belonging to Owner | | MAKE | clean | programs | Removes all the object files that had been created for for the | | MAKE | install | programs | Compile the program and copy the executables, libraries, etc to the designated area | | MAKE | all | programs | Compile the entire program |
Examples of mapping of Functions in SQL, POSIX and MAKE.
The Elixir language is also a functional language. The development of a Math Library is demonstrates of how a function based constructs are done. The following is an example of a Math Module: defmodule Math do def sum(a, b) do a + b end end The use of a Functional Programming approach used in a traditional Procedural Programming language like C/C++ would be some of the reusable libraries such as string, stderr, locale, etc. See __C Standard Library Reference Tutorial__(( TutorialsPoint, Accessed: 15 April 2021, __C Standard Library Reference Tutorial__, [[https://www.tutorialspoint.com/c_standard_library/index.htm]] )). /**=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- /* To add a discussion page to this page, comment out the line that says ~~DISCUSSION:off~~ */ ~~DISCUSSION:on|Outstanding Issues~~ ~~DISCUSSION:off~~