{"id":26020,"date":"2015-02-27T05:46:02","date_gmt":"2015-02-27T10:46:02","guid":{"rendered":"http:\/\/www.shamusyoung.com\/twentysidedtale\/?p=26020"},"modified":"2019-02-11T09:03:57","modified_gmt":"2019-02-11T14:03:57","slug":"a-new-programming-language-for-games-annotated-part-2","status":"publish","type":"post","link":"https:\/\/www.shamusyoung.com\/twentysidedtale\/?p=26020","title":{"rendered":"A new programming language for games, Annotated: Part 2"},"content":{"rendered":"<p>The annotation continues&#8230;<\/p>\n<p><table class='nomargin' cellspacing='0' width='100%' cellpadding='0' align='center' border='0'><tr><td><iframe loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/www.youtube.com\/embed\/TH9VCN6UkyQ\" frameborder=\"0\" allowfullscreen class=\"embed\"><\/iframe><br\/><small><a href='http:\/\/www.youtube.com\/watch?v=TH9VCN6UkyQ'>Link (YouTube)<\/a><\/small><\/td><\/tr><\/table><\/p>\n<h3>6:00 Garbage collection.<\/h3>\n<p>In C++, you have manual memory management. You need to request enough memory to hold all your space marines. If you need more marines<span class='snote' title='1'>Who doesn&#8217;t?<\/span> you have to allocate more memory. When you&#8217;re done with a marine, you have to tell the system you don&#8217;t need that chunk of memory anymore. You can&#8217;t ever make a mistake, because using memory you&#8217;ve freed causes a crash. Using memory you haven&#8217;t yet obtained causes a crash. Trying to free the same bit of memory more than once causes a crash. And forgetting to free memory causes a memory leak where your program will consume more and more until it crashes. <\/p>\n<p>And by &#8220;crash&#8221; I mean, &#8220;It might crash or it might malfunction badly somewhere later and you&#8217;ll have NO IDEA where it all went wrong.&#8221;<\/p>\n<p><!--more-->Garbage collection is where the language itself manages your memory for you. When you&#8217;re done with a space marine, you just forget about him. At some unknown point in the future, the garbage collector will run. It will eat some processor cycles and figure out what bits of memory you&#8217;ve allocated but are no longer using, and it will free them for you. But you don&#8217;t control when GC runs, and it has some performance cost. So, right in the middle of your high-performance game you might have this random process kick off at an inopportune moment. <\/p>\n<p>This is the stuff of flame wars. I&#8217;ve seen people claim that garbage collection is terrible and slow, and I&#8217;ve seen people claim that it&#8217;s super-fast and complaining about GC performance problems is merely ignorance and superstition. I strongly suspect it depends on what you&#8217;re trying to do and how your program uses memory.<\/p>\n<p>I don&#8217;t know personally. The only GC language I&#8217;ve used is Java, and I wasn&#8217;t doing anything resource-heavy at the time. <\/p>\n<p>I&#8217;ve often wondered how feasible it would be to offer a language with garbage collection, but have the GC only run when you allow it. Something like, &#8220;Here&#8217;s five milliseconds&#8221;, do as much as you can in that time.&#8221;<\/p>\n<p>I don&#8217;t know enough about how garbage collection works under the hood to know if that even makes sense, but I think it would be a really attractive compromise between &#8220;manage memory yourself&#8221; and &#8220;have the program devour an unknown number of CPU cycles at an unknown point in time&#8221;.<\/p>\n<p>The game Continue?9876543210 is all about a videogame character who is no longer in use and is trying to escape the garbage collector. I didn&#8217;t play it, but Chris did:<\/p>\n<p><table class='nomargin' cellspacing='0' width='100%' cellpadding='0' align='center' border='0'><tr><td><iframe loading=\"lazy\" width=\"1024\" height=\"576\" src=\"https:\/\/www.youtube.com\/embed\/t8O8GvPwXvo\" frameborder=\"0\" allowfullscreen class=\"embed\"><\/iframe><br\/><small><a href='http:\/\/www.youtube.com\/watch?v=t8O8GvPwXvo'>Link (YouTube)<\/a><\/small><\/td><\/tr><\/table><\/p>\n<h3>13:00 I think making a compiler is easier than making a AAA game.<\/h3>\n<p>A compiler is a program that will take your code&#8230;<\/p>\n<pre lang=\"basic\" line=\"1\">\r\n100 REM BASIC WAS A FANTASTIC EARLY LANGUAGE.\r\n110 PRINT \"Shamus Young's BASIC program of text-spewing.\"\r\n120 PRINT \"For best results, direct the output to a printer\"\r\n130 PRINT \"that belongs to someone else. Screw trees!\"\r\n140 GOTO 100\r\n<\/pre>\n<p>&#8230;and turn it into an executable that anyone can run. It&#8217;s a program that takes source code as input and other programs as output. Blow is suggesting that making a AAA program is much harder than making a program that makes other programs.<\/p>\n<p>On one hand, this sounds sort of audacious. On the other hand: Given the amazing number of programmer-hours that go into these games, it stands to reason that they would have to be more time-consuming than a compiler. In the old days, compilers were often one-person projects.<\/p>\n<p>Having said that, I suspect (with no experience to back it up) that the trick of making a good compiler isn&#8217;t in getting it to work, but getting it to work well. It&#8217;s not that you need a lot of hours, it&#8217;s that you need lots of iteration. You release it, people use it, find problems or ambiguities, you make improvements. Repeat. Forever. <\/p>\n<p>I don&#8217;t feel any big need to make my own language, but I&#8217;ve often thought it would be a very good self-educational project to make a compiler.<\/p>\n<h3>17:00 Joy of programming.<\/h3>\n<p>Blow makes the case that a good language will be fun to use and that we&#8217;ll be more productive simply because there will be fewer days when you get demoralized by confusion. Writers get writer&#8217;s block. Programmers get daunted by complexity and the dread of untangling something incomprehensible. <\/p>\n<p>And I think he&#8217;s basically right: There really are &#8220;quality of life&#8221; issues when it comes to dealing with difficult code and unsatisfying solutions. Can a new language fix this? Making a new language to make programming more comfortable is like a writer that stops working on his book to remodel the room where he does his writing, in hopes that the new setting will make him feel &#8220;more motivated&#8221;. It&#8217;s probably not actually worth the trade-off in terms of time, but it can sound really appealing if you find yourself stuck<span class='snote' title='2'>And if you ARE stuck, it&#8217;s probably a good way to fill the time.<\/span>. And I often find myself stuck. <\/p>\n<p>He says this new language should be &#8220;designed for good programmers&#8221;, which touches on a long-standing debate we have in language design. Programmers make mistakes. Most of our mistakes fall into a very small number of different categories. The same mistakes pop up again and again, and so sometimes languages are designed to protect us from making those blunders. But protection is often restrictive in some way. I don&#8217;t care if you&#8217;re talking about body armor, training wheels, airport security, speed limits, or bounds checking on arrays, when you&#8217;re being protected you&#8217;re usually also being hindered in some way. This doesn&#8217;t mean that protection is bad. It just means that in some cases you might prefer to live dangerously and go without the protection. We wouldn&#8217;t want to replace all scissors with safety scissors, and in the world of videogame programming, we might not want to hinder our good coders to help our bad (or inexperienced) ones. <\/p>\n<h3>24:00 Productivity<\/h3>\n<p>There&#8217;s a bit of an interruption in the presentation here when Blow realizes he labeled the graph wrong and he feels the need to fix it. (Which I totally understand.) But I don&#8217;t want that to distract from the point he&#8217;s making, which is something too many young programmers don&#8217;t grasp. Heck, I think old programmers have trouble with this concept. The problem he&#8217;s talking about is that program complexity takes a massive toll on productivity. In the first two days of a project you&#8217;ll feel like a miracle worker who can do anything, and in the last two days of the project as the codebase sails over the event horizon of human understanding, you&#8217;ll struggle to change even simple things without creating a dozen bugs.  It&#8217;s the reason so many projects ship late<span class='snote' title='3'>This is why programmers have the adage, &#8220;The first 90% of the project takes 90% of the time, and the last 10% of the project takes the other 90% of the time.<\/span>. We tend to make our time estimates in those early days before things get out of hand.<\/p>\n<p>This is based entirely on my own gut feeling, but I have the sense that if you could actually plot the complexity \/ cost dynamic on a graph for real, you&#8217;d see the cost rise on an exponential curve. As you approach the limits of the programmers ability, the time cost shoots up drastically. If this is true (and not just my own bitterness over too many projects that got away from me) then any change that can bring the complexity down a couple of notches could have a huge payoff.<\/p>\n<p>Again, I&#8217;m not endorsing his language<span class='snote' title='4'>I haven&#8217;t even caught up on his later presentations to know what his language is like.<\/span>. I&#8217;m just saying that runaway complexity is a real problem and that the payoff might be bigger than it seems. A 5% reduction in complexity might result in more than 5% reduction in cost. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>The annotation continues&#8230; Link (YouTube) 6:00 Garbage collection. In C++, you have manual memory management. You need to request enough memory to hold all your space marines. If you need more marinesWho doesn&#8217;t? you have to allocate more memory. When you&#8217;re done with a marine, you have to tell the system you don&#8217;t need that [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[66],"tags":[],"class_list":["post-26020","post","type-post","status-publish","format-standard","hentry","category-programming"],"_links":{"self":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/26020","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26020"}],"version-history":[{"count":1,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/26020\/revisions"}],"predecessor-version":[{"id":45743,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=\/wp\/v2\/posts\/26020\/revisions\/45743"}],"wp:attachment":[{"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26020"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26020"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.shamusyoung.com\/twentysidedtale\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26020"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}