{"id":8437,"date":"2021-04-26T09:04:50","date_gmt":"2021-04-26T09:04:50","guid":{"rendered":"https:\/\/prwatech.in\/blog\/?p=8437"},"modified":"2024-04-13T06:18:57","modified_gmt":"2024-04-13T06:18:57","slug":"scala-procedures","status":"publish","type":"post","link":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/","title":{"rendered":"Scala &#8211; Procedures"},"content":{"rendered":"\r\n<h2><span data-sheets-root=\"1\" data-sheets-value=\"{&quot;1&quot;:2,&quot;2&quot;:&quot;Scala procedure and function differences&quot;}\" data-sheets-userformat=\"{&quot;2&quot;:6145,&quot;3&quot;:{&quot;1&quot;:0,&quot;3&quot;:1},&quot;14&quot;:{&quot;1&quot;:3,&quot;3&quot;:1},&quot;15&quot;:&quot;Arial&quot;}\">Scala procedure and function differences<\/span><\/h2>\r\n<p>&nbsp;<\/p>\r\n<p>A <strong>Function<\/strong>, that doesn&#8217;t return anything can <a href=\"https:\/\/prwatech.in\/blog\/#\">return<\/a> a <strong>Unit<\/strong> <a href=\"http:\/\/scala-lang.org\">that<\/a> is comparable to void in Java and shows that function doesn&#8217;t return anything back. The functions which don&#8217;t return anything in<a href=\"https:\/\/prwatech.in\/blog\/scala\/scala-a-quick-overview\/\"> Scala<\/a>, they are <strong>procedures<\/strong>.<\/p>\r\n<div class=\"flex-1 overflow-hidden\">\r\n<div class=\"react-scroll-to-bottom--css-kloqy-79elbk h-full\">\r\n<div class=\"react-scroll-to-bottom--css-kloqy-1n7m0yu\">\r\n<div class=\"flex flex-col text-sm pb-9\">\r\n<div class=\"w-full text-token-text-primary\" dir=\"auto\" data-testid=\"conversation-turn-166\">\r\n<div class=\"px-4 py-2 justify-center text-base md:gap-6 m-auto\">\r\n<div class=\"flex flex-1 text-base mx-auto gap-3 juice:gap-4 juice:md:gap-6 md:px-5 lg:px-1 xl:px-5 md:max-w-3xl lg:max-w-[40rem] xl:max-w-[48rem] group final-completion\">\r\n<div class=\"relative flex w-full flex-col agent-turn\">\r\n<div class=\"flex-col gap-1 md:gap-3\">\r\n<div class=\"flex flex-grow flex-col max-w-full\">\r\n<div class=\"min-h-[20px] text-message flex flex-col items-start gap-3 whitespace-pre-wrap break-words [.text-message+&amp;]:mt-5 overflow-x-auto\" dir=\"auto\" data-message-author-role=\"assistant\" data-message-id=\"30e52d6c-839d-40e7-a57e-96c75d94860c\">\r\n<div class=\"markdown prose w-full break-words dark:prose-invert light\">\r\n<p>In Scala, procedures and functions are closely related concepts but have distinct characteristics based on their definitions and usage within the language.<\/p>\r\n<p>A <strong>function<\/strong> in Scala is a name block of code that takes zero or more input parameters and produces a result when invoked. Functions are defined using the <code>def<\/code> keyword and explicitly specify a return type.\u00a0 Functions in Scala always return a value, even if it&#8217;s <code>Unit<\/code> (similar to <code>void<\/code> in other languages).<\/p>\r\n<p>On the other hand, a <strong>procedure<\/strong> in Scala is a special kind of function that does not return a value explicitly. Procedures are defined using the <code>def<\/code> keyword without specifying a return type (or specifying <code>Unit<\/code> explicitly).\u00a0<\/p>\r\n<p>The distinction between functions and procedures highlights Scala&#8217;s functional programming capabilities and emphasizes the importance of clarity in side-effecting versus pure computations. While functions focus on producing results based on input parameters, procedures emphasize performing actions without necessarily returning a value. Understanding these differences is crucial for writing expressive and idiomatic Scala code.<\/p>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n<\/div>\r\n\r\n\r\n\r\n<p><strong>use case 1:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>scala&gt; def rect_area(length:Float, breadth:Float) {val area = length*breadth; println(area)}<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8438\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png\" alt=\"\" width=\"814\" height=\"87\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png 606w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72-300x32.png 300w\" sizes=\"auto, (max-width: 814px) 100vw, 814px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>use case 2:<\/strong><\/p>\r\n\r\n\r\n\r\n<p>scala&gt; def circle_area(radius:Float) {val area = 3.14*radius*radius; println(area)}<\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8439\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-73.png\" alt=\"\" width=\"840\" height=\"73\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-73.png 606w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-73-300x26.png 300w\" sizes=\"auto, (max-width: 840px) 100vw, 840px\" \/><\/figure>\r\n\r\n\r\n\r\n<p><strong>use case 3:<\/strong><\/p>\r\n\r\n\r\n\r\n<figure class=\"wp-block-image size-large is-resized\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-8440\" src=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-74.png\" alt=\"\" width=\"834\" height=\"66\" srcset=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-74.png 606w, https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-74-300x24.png 300w\" sizes=\"auto, (max-width: 834px) 100vw, 834px\" \/><\/figure>\r\n\r\n\r\n\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Scala procedure and function differences &nbsp; A Function, that doesn&#8217;t return anything can return a Unit that is comparable to void in Java and shows that function doesn&#8217;t return anything back. The functions which don&#8217;t return anything in Scala, they are procedures. In Scala, procedures and functions are closely related concepts but have distinct characteristics [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[565,1698],"tags":[1132,1134,1135,1128,1130,1136,1129,1131,1133,1138],"class_list":["post-8437","post","type-post","status-publish","format-standard","hentry","category-scala","category-scala-modules-scala","tag-function-procedures-scala","tag-procedure-example-of-scala","tag-procedure-example-program","tag-procedures","tag-procedures-in-scala","tag-scala-procedure-definition","tag-scala-procedures","tag-scala-procedures-example","tag-scala-procedures-use-cases","tag-what-is-procedure-in-scala"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v25.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Scala Procedure and Function Differences - Prwatech<\/title>\n<meta name=\"description\" content=\"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta name=\"robots\" content=\"noindex, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Scala Procedure and Function Differences - Prwatech\" \/>\n<meta property=\"og:description\" content=\"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/\" \/>\n<meta property=\"og:site_name\" content=\"Prwatech\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/prwatech.in\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-04-26T09:04:50+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-04-13T06:18:57+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png\" \/>\n<meta name=\"author\" content=\"Prwatech\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:site\" content=\"@Eduprwatech\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Prwatech\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/\",\"url\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/\",\"name\":\"Scala Procedure and Function Differences - Prwatech\",\"isPartOf\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png\",\"datePublished\":\"2021-04-26T09:04:50+00:00\",\"dateModified\":\"2024-04-13T06:18:57+00:00\",\"author\":{\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\"},\"description\":\"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.\",\"breadcrumb\":{\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage\",\"url\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png\",\"contentUrl\":\"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png\",\"width\":606,\"height\":65},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/prwatech.in\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Scala &#8211; Procedures\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/prwatech.in\/blog\/#website\",\"url\":\"https:\/\/prwatech.in\/blog\/\",\"name\":\"Prwatech\",\"description\":\"Share Ideas, Start Something Good.\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/prwatech.in\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3\",\"name\":\"Prwatech\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g\",\"caption\":\"Prwatech\"},\"url\":\"https:\/\/prwatech.in\/blog\/author\/prwatech123\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Scala Procedure and Function Differences - Prwatech","description":"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.","robots":{"index":"noindex","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"og_locale":"en_US","og_type":"article","og_title":"Scala Procedure and Function Differences - Prwatech","og_description":"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.","og_url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/","og_site_name":"Prwatech","article_publisher":"https:\/\/www.facebook.com\/prwatech.in\/","article_published_time":"2021-04-26T09:04:50+00:00","article_modified_time":"2024-04-13T06:18:57+00:00","og_image":[{"url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png","type":"","width":"","height":""}],"author":"Prwatech","twitter_card":"summary_large_image","twitter_creator":"@Eduprwatech","twitter_site":"@Eduprwatech","twitter_misc":{"Written by":"Prwatech","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/","url":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/","name":"Scala Procedure and Function Differences - Prwatech","isPartOf":{"@id":"https:\/\/prwatech.in\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage"},"image":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage"},"thumbnailUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png","datePublished":"2021-04-26T09:04:50+00:00","dateModified":"2024-04-13T06:18:57+00:00","author":{"@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3"},"description":"Master Scala Procedure and Function Differences - Dive deep with our expert instructors and comprehensive curriculum.","breadcrumb":{"@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#primaryimage","url":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png","contentUrl":"https:\/\/prwatech.in\/blog\/wp-content\/uploads\/2021\/04\/image-72.png","width":606,"height":65},{"@type":"BreadcrumbList","@id":"https:\/\/prwatech.in\/blog\/scala\/scala-modules-scala\/scala-procedures\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/prwatech.in\/blog\/"},{"@type":"ListItem","position":2,"name":"Scala &#8211; Procedures"}]},{"@type":"WebSite","@id":"https:\/\/prwatech.in\/blog\/#website","url":"https:\/\/prwatech.in\/blog\/","name":"Prwatech","description":"Share Ideas, Start Something Good.","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/prwatech.in\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/db90baff7744090b2288bbc98fea87f3","name":"Prwatech","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/prwatech.in\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/c00bafc1b04045f31eda917de39891456c44fa47c092b9bb6be0f860a3a30a2f?s=96&d=mm&r=g","caption":"Prwatech"},"url":"https:\/\/prwatech.in\/blog\/author\/prwatech123\/"}]}},"_links":{"self":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8437","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/comments?post=8437"}],"version-history":[{"count":6,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8437\/revisions"}],"predecessor-version":[{"id":11418,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/posts\/8437\/revisions\/11418"}],"wp:attachment":[{"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/media?parent=8437"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/categories?post=8437"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/prwatech.in\/blog\/wp-json\/wp\/v2\/tags?post=8437"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}