{"id":562,"date":"2010-01-05T15:17:46","date_gmt":"2010-01-05T22:17:46","guid":{"rendered":"http:\/\/thesmithfam.org\/blog\/?p=562"},"modified":"2019-08-12T07:15:32","modified_gmt":"2019-08-12T13:15:32","slug":"functional-is-not-procedural","status":"publish","type":"post","link":"https:\/\/thesmithfam.org\/blog\/2010\/01\/05\/functional-is-not-procedural\/","title":{"rendered":"Functional is not Procedural"},"content":{"rendered":"<p>I&#8217;ve recently seen some confusion about the terms <b>functional<\/b> and <b>procedural<\/b> in the software development community. Let me spend a moment trying to clear things up for (both of) my readers.<\/p>\n<p>First of all, just because a programming language has <b>functions<\/b>, that does not mean it is <b>functional<\/b>. In fact, its confusing name has nothing to do with functions. The history of the term <b>function<\/b>, as used in the computation world, hails back to the 1930&#8217;s when Alonzo Church created Lambda Calculus to be able to use and define mathematical algorithms on paper. Later, when computers arrived on the scene, programmers adopted the term <b>function<\/b> to describe a chunk of code that could be re-used by other chunks of code. Functions, in this context, have been adopted by every programming language I know of, including assembly language. Functions are commonly referred to as &#8220;routines&#8221;, &#8220;subroutines&#8221;, or &#8220;procedures&#8221;. Some might even argue that a &#8220;method&#8221; is pragmatically identical to a function.<\/p>\n<p>Here&#8217;s where the confusion begins.<\/p>\n<p>This is hard to explain rigorously, but here goes anyway.<\/p>\n<p>Some languages, like C, tend to encourage computer programmers to make use of functions. Programs written in these languages tend to consist of a set of functions, and a &#8220;main&#8221; function that kicks everything off. Such a language is often referred to as &#8220;procedural&#8221;, but really the term &#8220;procedural&#8221; refers to a style of programming, and does not really describe a language, per se. It is often used incorrectly as an antonym to the concept of &#8220;object oriented&#8221;.<\/p>\n<p>Other languages, like Scheme and Haskell, tend to encourage computer programmers to write code with functions that avoid internal state changes and produce no side effects when called. For example, these language discourage global variables, and particularly the calling of functions that would mutate global variables (that would be a side effect).<\/p>\n<p>To sum up.<\/p>\n<p>Procedural programming languages can be functional or not. Functional programming languages can be procedural or not.<\/p>\n<p>Here&#8217;s a table:<\/p>\n<style><!--\ntable { border: 1px solid black; border-collapse: collapse; }\ntable td, table th { padding: 3px; border: 1px solid black; }\n--><\/style>\n<table>\n<tr>\n<th>Language<\/th>\n<th>Functional<\/th>\n<th>Procedural<\/th>\n<\/tr>\n<tr>\n<td>C<\/td>\n<td>No<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Haskell<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<tr>\n<td>Python<\/td>\n<td>Can be<\/td>\n<td>Can be<\/td>\n<\/tr>\n<tr>\n<td>C++<\/td>\n<td>No<\/td>\n<td>Can be (if you write it like C)<\/td>\n<\/tr>\n<tr>\n<td>Java<\/td>\n<td>No<\/td>\n<td>Usually not<\/td>\n<\/tr>\n<tr>\n<td>OCaml<\/td>\n<td>Yes<\/td>\n<td>Yes<\/td>\n<\/tr>\n<\/table>\n<p>If you take nothing else away from this article, take this: The C programming language is <b>not<\/b> a functional language. It&#8217;s not bad, it&#8217;s just not functional.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve recently seen some confusion about the terms functional and procedural in the software development community. Let me spend a moment trying to clear things up for (both of) my readers. First of all, just because a programming language has functions, that does not mean it is functional. In fact, its confusing name has nothing [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2],"tags":[],"class_list":["post-562","post","type-post","status-publish","format-standard","hentry","category-code-and-cruft"],"_links":{"self":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/562","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/comments?post=562"}],"version-history":[{"count":19,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/562\/revisions"}],"predecessor-version":[{"id":1385,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/posts\/562\/revisions\/1385"}],"wp:attachment":[{"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/media?parent=562"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/categories?post=562"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thesmithfam.org\/blog\/wp-json\/wp\/v2\/tags?post=562"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}