{"id":2841,"date":"2010-03-29T23:01:58","date_gmt":"2010-03-30T03:01:58","guid":{"rendered":"http:\/\/blogs.n1zyy.com\/n1zyy\/?p=2841"},"modified":"2010-03-29T23:01:58","modified_gmt":"2010-03-30T03:01:58","slug":"programming-tip","status":"publish","type":"post","link":"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/03\/29\/programming-tip\/","title":{"rendered":"Programming Tip"},"content":{"rendered":"<p>This is probably so ludicrously obvious that it goes without saying but, in my experience, it really needs to be said:<\/p>\n<p><em>When building your architecture, you should design it so that things you do every day are easy.<\/em><\/p>\n<p>For example, if you have an often-used object, don&#8217;t split it into two halves and require that you join on them. There are lots of arguments for not having a 50-column table, and there was a clear distinction between the public side of a user and the private site of a user, but splitting one simple concept in half has caused lots and lots of pain. If it&#8217;s a core &#8220;thing&#8221; on your site, make it easy to manipulate. For example, the question, &#8220;How many users signed up today?&#8221; should not require joining two tables, nor should finding out whether a user on the site is active or not.<\/p>\n<p>When complexity doesn&#8217;t come under the guise of optimization, it sometimes creeps in as permitting new capabilities. On another product we moved the &#8220;email&#8221; column out and created an Email object, allowing users to have multiple emails. In more than a year&#8217;s time, nothing has ever been done to actually assign additional emails. All it means is that instead of User.find_by_email(&#8216;abc@example.com&#8217;), I need to do Email.find_by_email(&#8216;abc@example.com).user.<\/p>\n<p>And here&#8217;s what got me annoyed enough to start this post: you shouldn&#8217;t need lots of conditions to show your base case of things. Right now I&#8217;m working on a bit of code to pull back all the posts on the blogs. It seems I need to check a whole bunch of columns: WHERE post_status=&#8217;publish&#8217; AND post_password IS NULL OR post_password = &#8221; AND post_date < NOW()<\/p>\n<p>Sorry, but that&#8217;s dumb. Sure, you can bundle it away and give a nice simple method that does all that stuff for you, but hiding insane designs behind simple methods doesn&#8217;t actually fix them. It all comes down to the premise I began with:<\/p>\n<p><em>When building your architecture, you should design it so that  things you do every day are easy.<\/em><\/p>\n<p>Displaying all the posts on a blog is a thing you do every day. So is getting the number of members who signed up today. So is looking up a user by email. So don&#8217;t make them hard.<\/p>","protected":false},"excerpt":{"rendered":"<p>This is probably so ludicrously obvious that it goes without saying but, in my experience, it really needs to be said: When building your architecture, you should design it so that things you do every day are easy. For example, &hellip; <a href=\"https:\/\/blogs.n1zyy.com\/n1zyy\/2010\/03\/29\/programming-tip\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2841","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2841","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/comments?post=2841"}],"version-history":[{"count":0,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/posts\/2841\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/media?parent=2841"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/categories?post=2841"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.n1zyy.com\/n1zyy\/wp-json\/wp\/v2\/tags?post=2841"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}