{"id":10,"date":"2007-09-04T11:39:57","date_gmt":"2007-09-04T17:39:57","guid":{"rendered":"http:\/\/www.philhassey.com\/?p=10"},"modified":"2007-09-04T12:55:37","modified_gmt":"2007-09-04T18:55:37","slug":"keeping-code-small","status":"publish","type":"post","link":"https:\/\/www.philhassey.com\/blog\/2007\/09\/04\/keeping-code-small\/","title":{"rendered":"Keeping code small"},"content":{"rendered":"<p>I&#8217;ve been working on a re-write of my pygame based gui PGU.  I found, that as PGU grew larger I was less inclined to maintain it.  It became harder to add new features and harder to maintain existing ones.  At present, PGU is pretty stable, but it&#8217;s also pretty large and likely not going to change.<\/p>\n<p>While working on Galcon, I added the ability for users to add their own python mods to the game.  I wanted to give the users the ability to add their own option screens using a simple gui system, which, just for giggles, I decided to make sure it was less than 32k of code.  After I had written this system &#8220;gui.py&#8221; it occurred to me that not only was the API simpler than PGU it also had most of the features PGU had!  (As well as quite a few PGU didn&#8217;t have.)  My simple 32k gui.py was rivaling my 250k pgu.gui!<\/p>\n<p>I came up with a theory of sorts: <em>&#8220;Any useful library can be written in 64k or less.&#8221;<\/em> Of course, I wouldn&#8217;t swear by that, but I figured I&#8217;d give it a try.  I&#8217;m working on getting more functionality than PGU had into my new PUG library.  So far so well, I&#8217;m keeping the gui.py <= 32k and the theme.py <= 8k.  So far I have a cleaner API with more features than the original PGU.\n\nHowever, keeping it smaller than 32k requires me to make quite a few trade-offs.  I can't have <strong>all<\/strong> the features I included in PGU.  The real challenge now is deciding &#8220;is this feature important for almost all games, or is it a bit frivolous&#8221; &#8230; I&#8217;m sort of cheating by putting those frivolous widgets into a contrib\/ folder.  At the same time, it&#8217;s helping me keep the core small and maintainable.  Anything found in the contrib\/ folder may very well be quite useful, but I can also claim it is unsupported and not have to worry about it.<\/p>\n<p>My arbitrary rules for PUG development:<\/p>\n<ul>\n<li>the code in pug\/ must be <= 64k<\/li>\n<li>gui.py <= 32k<\/li>\n<li>theme.py <= 8k<\/li>\n<li>code must be readable<\/li>\n<li>names must be readable<\/li>\n<li>use 4 spaces for tabs<\/li>\n<li>must include complete docstrings<\/li>\n<\/ul>\n<p>A number of those rules are in place to keep me from &#8220;cheating&#8221; to get the file smaller.  I hope to wrap up a useable version today .. and then begin working on my pyweek entry!<\/p>\n<p>If anyone is brave and wants to try the alpha: svn:\/\/www.imitationpickles.org\/pug\/trunk<\/p>\n<p>-Phil<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;ve been working on a re-write of my pygame based gui PGU. I found, that as PGU grew larger I was less inclined to maintain it. It became harder to add new features and harder to maintain existing ones. At present, PGU is pretty stable, but it&#8217;s also pretty large and likely not going to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-10","post","type-post","status-publish","format-standard","hentry","category-pygame","category-python"],"_links":{"self":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/10","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/comments?post=10"}],"version-history":[{"count":0,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/posts\/10\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/media?parent=10"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/categories?post=10"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.philhassey.com\/blog\/wp-json\/wp\/v2\/tags?post=10"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}