{"id":327,"date":"2021-09-07T17:33:34","date_gmt":"2021-09-07T07:33:34","guid":{"rendered":"http:\/\/www.kernelio.com\/blog\/?p=327"},"modified":"2022-07-22T10:11:16","modified_gmt":"2022-07-22T00:11:16","slug":"why-function-become-not-pure","status":"publish","type":"post","link":"https:\/\/www.kernelio.com\/blog\/2021\/09\/07\/why-function-become-not-pure\/","title":{"rendered":"Why function becomes not pure"},"content":{"rendered":"<p>Pure function is absolute.\u00a0 It gives definite outcome on certain input. Otherwise the function is not pure.<\/p>\n<p>A function becomes not pure when its calculation depends on context other than parameters.<\/p>\n<p>Then the question rises:\u00a0 why not just pass the context in as parameters?<\/p>\n<p>Yes you can, at the level of modelling and core business logic.\u00a0 However at some stage of building software you can not do it anymore.\u00a0 A controller in MVC handles API end point is definitely not pure. input might be a URL from user, it needs to use data stored to return a html page. Although the comptroller is often written in the form of an function, it is strictly speaking a procedure. In general lower level functions are more likely to be pure than high level ones.<\/p>\n<p>What is the proper boundary where function stop being pure?<\/p>\n<p>It depends. Ideally function should not have more than 3 parameters or more than 100 lines. A chuck easier for human to understand is probably no more than 10.\u00a0 10 files in a fold, 10 functions in a class.\u00a0 Overall they are just a way of organizing.<\/p>\n<p>Following this approach we end up with well scoped chuck of code. However we break the whole product into so many pieces. Understanding the referencing relations becomes a nightmare. File naming and fold structure need to be really solid to compensate it.<\/p>\n<p>OOP Vs functional programming is not the right question.\u00a0 OOP tries to map real world object into software and is set on a layer above functional programming.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Pure function is absolute.\u00a0 It gives definite outcome on certain input. Otherwise the function is not pure. A function becomes not pure when its calculation depends on context other than parameters. Then the question rises:\u00a0 why not just pass the context in as parameters? Yes you can, at the level of modelling and core business&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[7],"tags":[],"class_list":["post-327","post","type-post","status-publish","format-standard","hentry","category-software-engineering"],"_links":{"self":[{"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/posts\/327","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/comments?post=327"}],"version-history":[{"count":4,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions"}],"predecessor-version":[{"id":451,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/posts\/327\/revisions\/451"}],"wp:attachment":[{"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/media?parent=327"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/categories?post=327"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kernelio.com\/blog\/wp-json\/wp\/v2\/tags?post=327"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}