{"id":4938,"date":"2014-03-30T17:09:22","date_gmt":"2014-03-30T17:09:22","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/when-are-predicates-appropriate-and-what-is-the-best-pattern-for-usage-collection-of-common-programming-errors\/"},"modified":"2014-03-30T17:09:22","modified_gmt":"2014-03-30T17:09:22","slug":"when-are-predicates-appropriate-and-what-is-the-best-pattern-for-usage-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/03\/30\/when-are-predicates-appropriate-and-what-is-the-best-pattern-for-usage-collection-of-common-programming-errors\/","title":{"rendered":"When are predicates appropriate and what is the best pattern for usage-Collection of common programming errors"},"content":{"rendered":"<p>When are predicates appropriate and what is the best pattern for usage? What are the advantages of predicates?<\/p>\n<p>It seems to me like most cases where a predicate can be employed a tight loop would accomplish the same functionality?<\/p>\n<p>I don&#8217;t see a reusability argument given you will probably only implement a predicate in one method right?<\/p>\n<p>They look and feel nice but besides that they seem like you would only employ them when you need a quick hack on the collection classes?<\/p>\n<p><strong>UPDATE<\/strong><\/p>\n<p>But why would you be rewriting the tight loop again and again?<\/p>\n<p>In my mind\/code when it comes to collections I always end up with something like<\/p>\n<pre><code>Class Person\nEnd Class\n\nClass PersonList\n    Inherits List(Of Person)\n\n    Function FindByName(Name) as Person\n         tight loop....\n    End Function\nEnd Class\n<\/code><\/pre>\n<p>@Ani<\/p>\n<p>By that same logic I could implement the method as such<\/p>\n<pre><code>Class PersonList\n    Inherits List(Of Person)\n\n    Function FindByName(Name) as PersonList\n    End Function\n\n    Function FindByAge(Age) as PersonList\n    End Function\n\n    Function FindBySocialSecurityNumber(SocialSecurityNumber) as PersonList\n    End Function\nEnd Class\n<\/code><\/pre>\n<p>And call it as such<\/p>\n<pre><code>Dim res as PersonList = MyList.FindByName(\"Max\").FindByAge(25).FindBySocialSecurityNumber(1234)\n<\/code><\/pre>\n<p>and the result along with the amount of code and its reusability is largely the same, no?<\/p>\n<p><strong>I am not arguing just trying to understand.<\/strong><\/p>\n","protected":false},"excerpt":{"rendered":"<p>When are predicates appropriate and what is the best pattern for usage? What are the advantages of predicates? It seems to me like most cases where a predicate can be employed a tight loop would accomplish the same functionality? I don&#8217;t see a reusability argument given you will probably only implement a predicate in one [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-4938","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4938","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=4938"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/4938\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=4938"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=4938"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=4938"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}