{"id":1211,"date":"2022-08-25T20:09:16","date_gmt":"2022-08-25T14:39:16","guid":{"rendered":"https:\/\/mutesoft.com\/spaces\/software\/?p=1211"},"modified":"2022-08-25T20:34:14","modified_gmt":"2022-08-25T15:04:14","slug":"difference-between-procedure-function-and-method","status":"publish","type":"post","link":"https:\/\/mutesoft.com\/spaces\/software\/difference-between-procedure-function-and-method.html","title":{"rendered":"Difference between Procedure, Function, and Method"},"content":{"rendered":"\n<figure class=\"wp-block-image aligncenter size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"512\" src=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-1024x512.jpg\" alt=\"\" class=\"wp-image-1203\" srcset=\"https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-1024x512.jpg 1024w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-300x150.jpg 300w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-768x384.jpg 768w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-1536x768.jpg 1536w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-2048x1024.jpg 2048w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-500x250.jpg 500w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-800x400.jpg 800w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-1280x640.jpg 1280w, https:\/\/mutesoft.com\/spaces\/software\/wp-content\/uploads\/sites\/7\/2022\/08\/programming-general-1920x960.jpg 1920w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>To most programmers, procedure, function, and method are the same thing. It is a callable, reusable code block that optionally takes some input, performs one or more operations, and optionally returns some output. However, there are subtle differences and definitions vary from language to language. We&#8217;ll try to keep the comparison as generic as possible.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Procedure_Vs_Function_Vs_Method\"><\/span>Procedure Vs. Function Vs. Method<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column has-pale-cyan-blue-background-color has-background is-layout-flow wp-block-column-is-layout-flow\">\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Procedure\"><\/span>Procedure<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Reusable and callable code block<\/li><li>Does not return value<\/li><li>Intended to cause side effect<\/li><li>Dedicated keyword <em>procedure<\/em> to create a procedure in Pascal and stored procedure in SQL<\/li><\/ol>\n<\/div>\n\n\n\n<div class=\"wp-block-column has-light-green-cyan-background-color has-background is-layout-flow wp-block-column-is-layout-flow\">\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Function\"><\/span>Function<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Reusable and callable code block<\/li><li>Returns value, but that&#8217;s optional (<em>void<\/em>)<\/li><li>May or may not cause side effects<\/li><li>Programming languages have different keywords to create a function: <em>function<\/em>, <em>def<\/em>, <em>fun<\/em>, etc.<\/li><\/ol>\n<\/div>\n<\/div>\n\n\n\n<div class=\"wp-block-columns is-layout-flex wp-container-core-columns-is-layout-28f84493 wp-block-columns-is-layout-flex\">\n<div class=\"wp-block-column is-vertically-aligned-top align-center has-background is-layout-flow wp-block-column-is-layout-flow\" style=\"background-color:#f4dbab;flex-basis:50%\">\n<h4 class=\"has-text-align-center wp-block-heading\"><span class=\"ez-toc-section\" id=\"Method\"><\/span>Method<span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<ol class=\"wp-block-list\"><li>Reusable and callable code block<\/li><li>Returns value, but that&#8217;s optional (<em>void<\/em>)<\/li><li>May or may not create side effects<\/li><li>Same keywords as used in function creation<\/li><li>Associated with an object. <\/li><li>In Object-oriented languages, member functions of a class are called methods.<\/li><\/ol>\n<\/div>\n\n\n\n<div class=\"wp-block-column hidden is-layout-flow wp-block-column-is-layout-flow\" style=\"flex-basis:50%\"><\/div>\n<\/div>\n\n\n\n<p>A <strong>procedure<\/strong> is a function that does not return a value. In older programming languages such as Pascal, a procedure is defined with a dedicated keyword <code>procedure<\/code>. Procedures are meant to perform operations with supplied inputs and cause side effects (e.g. logging).<\/p>\n\n\n\n<p>A <strong>function<\/strong> is a general term used for a reusable code block. In the old days, functions were meant to perform calculations with supplied inputs and return the calculated results without causing side effects. However, in modern-day programming languages, we don&#8217;t distinguish between functions and procedures. A function may or may not return a value (<code>void<\/code>) and may cause side effects.<\/p>\n\n\n\n<p>A <strong>method<\/strong> is a function that is associated with and acts on objects in object-oriented programming languages. Methods are defined within a class and may or may not return a value (<code>void<\/code>).<\/p>\n\n\n\n<p>Let us create a reusable code block that takes principal, interest rate, and time as input parameters to calculate simple interest and return it. Here is a JavaScript <code>function<\/code> to compute simple interest:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"js\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">function computeInterest(principal, rate, time){\n    return principal * rate * time;\n}<\/pre>\n\n\n\n<p>Here is a Python <code>function<\/code> to compute simple interest:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"python\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">def computeInterest(principal, rate, time):\n    return principal * rate * time;<\/pre>\n\n\n\n<p>Here is a Java <code>method<\/code> to compute simple interest:<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"java\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">public double computeInterest(double principal, double rate, double time){\n    return principal * rate * time;\n}<\/pre>\n\n\n\n<style>\n#ez-toc-container{display:none}\n<\/style>\n","protected":false},"excerpt":{"rendered":"<p>To most programmers, procedure, function, and procedure are the same thing. It is a callable, reusable code block that optionally takes some input, performs one or more operations, and optionally returns some output.<\/p>\n","protected":false},"author":2,"featured_media":1203,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_seopress_robots_primary_cat":"none","_seopress_titles_title":"","_seopress_titles_desc":"To most programmers, procedure, function, and procedure are the same thing. It is a callable, reusable code block that optionally takes some input, performs one or more operations, and optionally returns some output.","_seopress_robots_index":"","_vp_format_video_url":"","_vp_image_focal_point":[],"footnotes":""},"categories":[6],"tags":[62,61],"class_list":["post-1211","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-programming","tag-coding","tag-programming-concepts"],"_links":{"self":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1211","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/comments?post=1211"}],"version-history":[{"count":21,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1211\/revisions"}],"predecessor-version":[{"id":1240,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/posts\/1211\/revisions\/1240"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media\/1203"}],"wp:attachment":[{"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/media?parent=1211"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/categories?post=1211"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mutesoft.com\/spaces\/software\/wp-json\/wp\/v2\/tags?post=1211"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}