{"id":166,"date":"2013-06-30T22:22:52","date_gmt":"2013-06-30T20:22:52","guid":{"rendered":"http:\/\/neurons.dk\/?p=166"},"modified":"2013-06-30T22:22:52","modified_gmt":"2013-06-30T20:22:52","slug":"model-building-for-10-000","status":"publish","type":"post","link":"http:\/\/neurons.dk\/?p=166","title":{"rendered":"Model building for 10.000"},"content":{"rendered":"<p>When I started working on the 10.000 game, I had some ideas and concepts I wanted to try out when building the model. I&#8217;d like to share some of my thoughts on the process and the product.<\/p>\n<p><strong>What is the objective of the model?<\/strong><br \/>\nMy goal with the model was to make a clear separation between the logic and state of the game and the user interface. The benefits I was hoping to achieve was first and foremost a division of the task at hand, by dividing the application into a user interface part and a model part. Secondly making it easier to swap UIs, by decoupling it from the model, in case I&#8217;d redesign the UI later on. Thirdly I wanted to encapsulate the variables that stored the state of the game, thereby making sure rules would be enforced and thus keeping the model in a valid state all the time.<br \/>\nA lot of this stems from the teachings and common programming practices like the <a href=\"http:\/\/en.wikipedia.org\/wiki\/Model%E2%80%93view%E2%80%93controller\" title=\"MVC\" target=\"_blank\">MVC architectural pattern<\/a> and I saw no reason why this solution couldn&#8217;t be applied to the task at hand.<\/p>\n<p><em>What is the tradeoff?<\/em><br \/>\nAll of these benefits comes at a cost of course. During the development of the game I kept track of how much time I spent on the different tasks. I&#8217;ve given a short list below of the time allocated to different tasks (this only covers the initial version).<\/p>\n<ul>\n<li>Designing the solution: 24% (~16 hrs)<\/li>\n<li>Graphics: 5% (~3 hrs)<\/li>\n<li>Programming UI: 37% (~25 hrs)<\/li>\n<li>Programming model: 28% (~19 hrs)<\/li>\n<li>Testing and debugging: 4% (~2 hrs)<\/li>\n<li>Publishing: 3% (2 hrs)<\/li>\n<\/ul>\n<p>I can&#8217;t say for sure, but I guess that if I had merged the model and UI and didn&#8217;t care about the benefits that the seperation gives, I could probably have saved 10 hours divided evenly between designing and programming, which equates to something like a 15% reduction. This is of course my ad hoc estimate based on the size and complexity of the game and it&#8217;s rules. I don&#8217;t think you could use this as a generic rule \ud83d\ude42<\/p>\n<p><em>Encapsulation vs. performance<\/em><br \/>\nAnother thing to consider is the fact that the encapsulation adds a layer of method calls that could be removed, if variables where directly accessed in the code. I <a href=\"http:\/\/developer.android.com\/training\/articles\/perf-tips.html#GettersSetters\" title=\"Performance tips\" target=\"_blank\">read<\/a> that internal getter\/setter methods should be avoid, due to performance overhead. I&#8217;m guessing merging classes and then accessing variables directly would yield the same benefits.<br \/>\nI haven&#8217;t tried profiling the game, to see if there are any performance drops. The tests I&#8217;ve done on the UI haven&#8217;t had any issues so far, like an <a href=\"http:\/\/developer.android.com\/training\/articles\/perf-anr.html\" title=\"Keeping your App responsive\" target=\"_blank\">ANR<\/a> for example.<\/p>\n<p><strong>What benefits did this give after release?<\/strong><br \/>\nAfter the first release I&#8217;ve made some improvements to the game. These have been bundled in three new versions. All of these have been rather fast to develop and I contribute a lot of this to the initial investment in time spent on design and model programming. Again, if I where to venture a guess I&#8217;d say that the time I could have saved on the initial release I&#8217;ve gained in the latter releases.<\/p>\n<p>So I think my bottom line is; Solid design and good programming practices saves time in the long run.<br \/>\nIt has certainly saved me a lot of frustration \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I started working on the 10.000 game, I had some ideas and concepts I wanted to try out when building the model. I&#8217;d like to share some of my thoughts on the process and the product. What is the &hellip; <a href=\"http:\/\/neurons.dk\/?p=166\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[8,16,25,28],"class_list":["post-166","post","type-post","status-publish","format-standard","hentry","category-tech","tag-10-000","tag-encapsulation","tag-model-building","tag-mvc"],"_links":{"self":[{"href":"http:\/\/neurons.dk\/index.php?rest_route=\/wp\/v2\/posts\/166"}],"collection":[{"href":"http:\/\/neurons.dk\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/neurons.dk\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/neurons.dk\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/neurons.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=166"}],"version-history":[{"count":0,"href":"http:\/\/neurons.dk\/index.php?rest_route=\/wp\/v2\/posts\/166\/revisions"}],"wp:attachment":[{"href":"http:\/\/neurons.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/neurons.dk\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=166"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/neurons.dk\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}