{"id":2780,"date":"2016-01-03T10:24:50","date_gmt":"2016-01-03T17:24:50","guid":{"rendered":"http:\/\/www.sheer.us\/weblogs\/?p=2780"},"modified":"2016-01-20T02:06:26","modified_gmt":"2016-01-20T09:06:26","slug":"when-to-class-when-to-table","status":"publish","type":"post","link":"http:\/\/www.sheer.us\/weblogs\/uncategorized\/when-to-class-when-to-table","title":{"rendered":"When to class \/ when to table"},"content":{"rendered":"<p>So, there&#8217;s a related issue in database design and in object oriented programming, and it surrounds the question of when do I break this type of data off into a new table \/ new class?<\/p>\n<p>Fully normalized data is a pain in the ass to work with. You have to join to find anything you care about, and there&#8217;s a performance cost to doing joins, especially outer joins. On the other paw, fully denormalized data is also a pain in the ass to work with. It can be very expensive to search that enormous haystack for that tiny needle, ALTER TABLEs take forever to run, etc.<\/p>\n<p>In the programming world, if you create too many object classes, it&#8217;s a royal pain in the ass to find anything, your executable size is going to go up, and unless you do a very good job of inheretince you&#8217;re going to be doing cut &#038; paste coding every time you add a good feature. On the other paw, if you create too few object classes, you&#8217;re going to find they get large and cumbersome as you have to add many methods to them for the varying sorts of data they&#8217;re carrying. Again, maintainability goes down, readability goes down.<\/p>\n<p>So, how do you decide when it&#8217;s time to tack on a table or a class? I don&#8217;t really know how I make this decision &#8211; there&#8217;s some sort of intuitive leap that happens inside my mind that says &#8216;now would be a good time for another table \/ another object&#8217;. Sometimes there are clear data bounderies &#8211; a map coordinate probably doesn&#8217;t belong in the same table as a phone number, because it&#8217;s a very different type of data. Sometimes external APIs suggest a path, because of the way their interfaces are defined. And so forth.<\/p>\n<p>I don&#8217;t have a good answer to write down here yet. I&#8217;m still thinking about this. But if anyone wants to comment, I&#8217;d be happy to hear your thoughts on the matter. (I think I have about 3 readers at this point, although my web traffic statistics would suggest that&#8217;s not correct)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So, there&#8217;s a related issue in database design and in object oriented programming, and it surrounds the question of when do I break this type of data off into a new table \/ new class? Fully normalized data is a pain in the ass to work with. You have to join to find anything you [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,1],"tags":[],"_links":{"self":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/2780"}],"collection":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/comments?post=2780"}],"version-history":[{"count":1,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/2780\/revisions"}],"predecessor-version":[{"id":2781,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/posts\/2780\/revisions\/2781"}],"wp:attachment":[{"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/media?parent=2780"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/categories?post=2780"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.sheer.us\/weblogs\/wp-json\/wp\/v2\/tags?post=2780"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}