{"id":1083,"date":"2019-01-17T01:14:20","date_gmt":"2019-01-16T15:14:20","guid":{"rendered":"http:\/\/www.moneystock.net\/wp_e\/?p=1083"},"modified":"2019-01-17T01:14:20","modified_gmt":"2019-01-16T15:14:20","slug":"functional-principles-in-c-method-should-be-honest","status":"publish","type":"post","link":"https:\/\/moneystock.net\/wp_e\/2019\/01\/17\/functional-principles-in-c-method-should-be-honest\/","title":{"rendered":"Functional Principles in C# &#8211; method should be honest"},"content":{"rendered":"<p>Below are the key ideas of how to apply functional principles in C# explained in Pluralsight course by\u00a0Vladimir Khorikov.<\/p>\n<ol>\n<li>Immutable Architecture<br \/>\nSeparate domain logic, Infrastructure(Persister), Service logic. Make the domain logic immutable and functional(input -&gt; output) so as to easily\u00a0unit test it. Make the infrastructure and service logic as simple as possible.<\/li>\n<li>Exception<br \/>\nUse return value over an exception if it&#8217;s a known exception.<br \/>\nFail Fast<br \/>\nGeneral exception catch should be in a single place to catch all unexpected exception.<\/li>\n<li>Avoid primitive obsession<br \/>\nUtilize value object which may contain validation logic as a single place to check input data.<\/li>\n<li>Avoid null<br \/>\nUse &#8216;NullGuard&#8217;\u00a0library with\u00a0[assembly: NullGuard(ValidationFlags.All)] option to check not only public method but also private method and properties.<br \/>\nUse Maybe&lt;T&gt; around a domain model which is separated from the presentation layer.<\/li>\n<li>\u00a0Handling Failures and Input Errors<br \/>\nUse value object<br \/>\nTry catch at the lowest level<br \/>\nUse Railway-oriented Programming =&gt; Result&lt;T&gt; and Maybe&lt;T&gt; =&gt; Monad.<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Below are the key ideas of how to apply functional principles in C# explained in Pluralsight course by\u00a0Vladimir Khorikov. Immutable Architecture Separate domain logic, Infrastructure(Persister), Service logic. Make the domain logic immutable and functional(input -&gt; output) so as to easily\u00a0unit test it. Make the infrastructure and service logic as simple as possible. Exception Use return&hellip; <a class=\"more-link\" href=\"https:\/\/moneystock.net\/wp_e\/2019\/01\/17\/functional-principles-in-c-method-should-be-honest\/\">Continue reading <span class=\"screen-reader-text\">Functional Principles in C# &#8211; method should be honest<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[548],"tags":[95,550],"class_list":["post-1083","post","type-post","status-publish","format-standard","hentry","category-c","tag-c","tag-functional-programming","entry"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1083","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/comments?post=1083"}],"version-history":[{"count":2,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1083\/revisions"}],"predecessor-version":[{"id":1086,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/posts\/1083\/revisions\/1086"}],"wp:attachment":[{"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/media?parent=1083"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/categories?post=1083"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/moneystock.net\/wp_e\/wp-json\/wp\/v2\/tags?post=1083"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}