{"id":126,"date":"2016-01-04T05:04:34","date_gmt":"2016-01-04T05:04:34","guid":{"rendered":"http:\/\/paleyontology.com\/cheaperthanrogaine\/?p=126"},"modified":"2016-01-04T05:04:34","modified_gmt":"2016-01-04T05:04:34","slug":"what-is-the-difference-between-functions-and-procedures","status":"publish","type":"post","link":"https:\/\/paleyontology.com\/cheaperthanrogaine\/2016\/01\/04\/what-is-the-difference-between-functions-and-procedures\/","title":{"rendered":"What is the Difference Between Functions and Procedures?"},"content":{"rendered":"<p>[Note: Hadi Partovi and Baker Franke of Code.org contributed a lot of this and Emmanuel Schanzer offered ideas. \u00a0I don&#8217;t really know how to assign credit to specific pieces, but I want to make sure to acknowledge their efforts. \u00a0Editorial comments about possible implications of the vocabulary issues are mine. \u00a0&#8212; JEP]<\/p>\n<p>In mathematics, the word &#8220;function&#8221; means this:<\/p>\n<p><strong><em>For a consistent set of inputs, a function returns a single, consistent output.<\/em><\/strong><\/p>\n<p>Notationally, a function is typically a single letter such as f, g, or h, followed by parentheses containing parameters\u00a0such as x, y, and z. \u00a0The parameters are generally\u00a0referred to as variables in a high school math class.<\/p>\n<p>For example, if f(x) = 2x + 3, then f(5) = 13. \u00a0Always.<\/p>\n<p>If g(x, y) = x * y, then g(4, 5) = 20. \u00a0Always.<\/p>\n<p>If h() = 5, then h() = 5. \u00a0Always.<\/p>\n<p>Mathematical functions need not take any inputs. \u00a0But they do need to be consistent. \u00a0Students are taught the vertical line test for graphs where y = f(x) to verify that consistency of output.<\/p>\n<p><span style=\"font-weight: 400;\">In computer science, programming languages allow people to give functions more descriptive names. \u00a0For example, if you want to write a function that takes a number as an input and returns the square of that number, you could name\u00a0that function <code>square<\/code>. \u00a0In the programming language JavaScript, that would look like:<\/span><\/p>\n<pre>function square(x) {\r\n \u00a0return x * x;\r\n}<\/pre>\n<p><span style=\"font-weight: 400;\">(Isn\u2019t that much nicer than f(x) = x<sup>2<\/sup>? \u00a0Isn&#8217;t it nice to see the name &#8220;square&#8221; and not think that it means to multiply s*q*u*a*r*e?)<\/span><\/p>\n<p>In computer science, we have procedures. \u00a0A procedure is like a function in that it takes any number of inputs. \u00a0It is different in that it need not produce consistent outputs.<\/p>\n<p><strong>All functions are procedures. \u00a0Not all procedures are functions.<\/strong><\/p>\n<p>Here is a JavaScript procedure that is not a mathematical function:<\/p>\n<pre>function notReallyaFunction(x) {\r\n  return random();\r\n}<\/pre>\n<p><code>notReallyaFunction<\/code> returns a random number between 0 and 1, regardless of x. \u00a0That&#8217;s not a problem for procedures in programming languages. \u00a0There is no requirement to return\u00a0consistent outputs.<\/p>\n<p>Note that the word <code>function<\/code> does not imply that a function is being created in the mathematical sense. It is a keyword in the JavaScript language used to create a procedure.<\/p>\n<p>From the teacher&#8217;s point of view, this\u00a0seems like a simple vocabulary fix, and it would likely be just that if math teachers could reliably be aware that the word <code>function<\/code> is being used in a non-mathematical way by programmers and if computer science teachers had the depth and breadth of knowledge to be aware that this should be discussed at least briefly with their students. \u00a0To their credit, Code.org does address this in their curriculum, even if it is an issue in this <a href=\"https:\/\/www.youtube.com\/watch?v=8T5acEwfJbw\">widely viewed\u00a0video<\/a>.<\/p>\n<p>Vocabulary frustration can be a reason for students to tune out of programming. The AP Computer Science curriculum demands knowledge of the Java programming language. Explaining <code>public static void main<\/code> to the intellectually curious student is quite a challenge for teachers and problematic for some. \u00a0I&#8217;ve seen students who were very capable mathematicians tune out on day one of class because this vocabulary is intimidating. \u00a0I&#8217;ve had a parent, who works at Google, express frustration about expecting novices\u00a0to deal with the overhead of getting started with the simplest program in Java. \u00a0It can be intimidating. \u00a0Minimizing and eliminating unnecessary duplication and conflation of terms can make a difference between a child participating and a child opting out of learning CS. (It might also help the child learning mathematics after programming to be less confused.)<\/p>\n<p>The JavaScript programming language isn&#8217;t going to be changed. It is a widely used tool for creating all kinds of wonderful programs. It&#8217;s too bad that the designers chose the word <code>function<\/code> as a keyword, but that ship has sailed.<\/p>\n<p>Still, my objection to the Code.org video remains. The topic is good, Chris Bosh is a tremendous messenger, and\u00a0I still wish they would go back and change the word &#8220;FUNCTIONS&#8221; to &#8220;PROCEDURES&#8221;.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[Note: Hadi Partovi and Baker Franke of Code.org contributed a lot of this and Emmanuel Schanzer offered ideas. \u00a0I don&#8217;t really know how to assign credit to specific pieces, but I want to make sure to acknowledge their efforts. \u00a0Editorial comments about possible implications of the vocabulary issues are mine. \u00a0&#8212; JEP] In mathematics, the &hellip; <a href=\"https:\/\/paleyontology.com\/cheaperthanrogaine\/2016\/01\/04\/what-is-the-difference-between-functions-and-procedures\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">What is the Difference Between Functions and Procedures?<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"nf_dc_page":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-126","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/posts\/126","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/comments?post=126"}],"version-history":[{"count":1,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/posts\/126\/revisions"}],"predecessor-version":[{"id":127,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/posts\/126\/revisions\/127"}],"wp:attachment":[{"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/media?parent=126"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/categories?post=126"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/paleyontology.com\/cheaperthanrogaine\/wp-json\/wp\/v2\/tags?post=126"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}