<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>hbr - hint for Branch (r-form)</title>
	<atom:link href="http://brnz.org/hbr/?feed=rss2&#038;p=437" rel="self" type="application/rss+xml" />
	<link>http://brnz.org/hbr</link>
	<description>by Jonathan Adamczewski / @twoscomplement</description>
	<lastBuildDate>Fri, 12 Apr 2013 02:45:49 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>Bugs of the day, 2013-04-11</title>
		<link>http://brnz.org/hbr/?p=1249</link>
		<comments>http://brnz.org/hbr/?p=1249#comments</comments>
		<pubDate>Fri, 12 Apr 2013 02:45:49 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1249</guid>
		<description><![CDATA[Don&#8217;t delete code that does things I got carried away while deleting some code that didn&#8217;t do anything and accidentally removed some parts that did do things &#8212; function calls with side effects that I didn&#8217;t fully understand. I make the same kind of change later to a different part of the codebase and got [...]]]></description>
				<content:encoded><![CDATA[<h2>Don&#8217;t delete code that does things</h2>
<p>I got carried away <a title="Compiler-assisted code cleaning, Thursday 2013-03-28" href="http://brnz.org/hbr/?p=1197">while deleting some code</a> that didn&#8217;t do anything and accidentally removed some parts that did do things &#8212; function calls with side effects that I didn&#8217;t fully understand. I make the same kind of change later to a different part of the codebase and got it right there. I didn&#8217;t think to go back and look for the possibility of this problem in my earlier change.</p>
<p>This one got checked in and caused problems for others later. It would have been caught by better testing on my part. (I&#8217;m convinced that I did test this and saw no problems, so either I didn&#8217;t actually test a build with the change or I my testing wasn&#8217;t really testing of the code affected)</p>
<h2>Unravel the whole garment</h2>
<p>In a related deletion, I managed to break another piece of code connected to one that I was modifying. I broke one of the assumptions of the other piece of code, which was far less obvious to me because they interacted via a mechanism that I was not familiar with.</p>
<p>Again, this would have been caught by better testing on my part.</p>
<p>My apologies to those affected. Clearly, I suck.</p>
<p>(On the upside, I&#8217;ve now learned a little bit more about another part of the codebase. This is a good thing.)</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1249</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bug review, 2013-04-10</title>
		<link>http://brnz.org/hbr/?p=1243</link>
		<comments>http://brnz.org/hbr/?p=1243#comments</comments>
		<pubDate>Thu, 11 Apr 2013 05:24:37 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1243</guid>
		<description><![CDATA[A fairly quiet two weeks compared to the one before. The main reasons being a week of illness (I find fever and an ability to concentrate to be mutually exclusive :\) and a change in work focus to a time of information gathering and planning for a different project, which has resulted in less opportunity [...]]]></description>
				<content:encoded><![CDATA[<p>A fairly quiet two weeks compared to the one before. The main reasons being a week of illness (I find fever and an ability to concentrate to be mutually exclusive :\) and a change in work focus to a time of information gathering and planning for a different project, which has resulted in less opportunity for writing new bugs.</p>
<h2>Summary of the weeks</h2>
<p><a title="Photograph of the day, Wednesday 2013-03-27" href="http://brnz.org/hbr/?p=1192">Wednesday 2013-03-27</a></p>
<p>An optimistic beginning to the new week: no bugs to write about, so I posted a photograph.</p>
<p><a title="Compiler-assisted code cleaning, Thursday 2013-03-28" href="http://brnz.org/hbr/?p=1197">Thursday 2013-03-28</a></p>
<p>An example of using the compiler to help identify particular code patterns that I wanted to eliminate.</p>
<p><a title="Bugs of the day, Friday 2013-03-29" href="http://brnz.org/hbr/?p=1199">Friday 2013-03-29</a></p>
<p>An actual bug, and worse than a runtime bug: checked-in build breaker. Shameful.</p>
<p><a title="Bug of the day, Tuesday 2013-04-02" href="http://brnz.org/hbr/?p=1210">Tuesday 2013-04-02</a></p>
<ul>
<li><span style="line-height: 13.993056297302246px;">Implicitly finding bugs in other people&#8217;s code</span></li>
</ul>
<p><a title="Studios, twenty and over." href="http://brnz.org/hbr/?p=1214">Sunday 2013-04-07</a></p>
<p>Not at all bug related, but a point of curiosity that (thanks to a lot of input from others) turned into a interesting list of studios that have been around for more than twenty years.</p>
<h2>Trends</h2>
<p>Not a many bugs in the list this time, so doesn&#8217;t seem like there&#8217;s a lot to say about these two weeks &#8212; except that the rate of bugs does go down when you&#8217;re not writing any code&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1243</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Studios, twenty and over.</title>
		<link>http://brnz.org/hbr/?p=1214</link>
		<comments>http://brnz.org/hbr/?p=1214#comments</comments>
		<pubDate>Sat, 06 Apr 2013 23:54:51 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1214</guid>
		<description><![CDATA[With recent news of studio closures and layoffs, I was curious about the number of game studios that have been running continuously for more than a (fairly arbitrary) twenty years. I put the question on twitter and was able to gather this list: HAL Laboratory (1980) Falcom (1981) EA Canada (1983) Nintendo Entertainment Analysis and [...]]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">With recent news of studio closures and layoffs, I was curious about the number of game studios that have been running continuously for more than a (fairly arbitrary) twenty years. I put the question on twitter and was able to gather this list:</span></p>
<ul>
<li><a style="line-height: 1.714285714; font-size: 1rem;" href="http://en.wikipedia.org/wiki/HAL_Laboratory">HAL Laboratory (1980)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Nihon_Falcom">Falcom (1981)</a></li>
<li><a style="line-height: 1.714285714; font-size: 1rem;" href="http://en.wikipedia.org/wiki/EA_Canada">EA Canada (1983)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Nintendo_Entertainment_Analysis_and_Development">Nintendo Entertainment Analysis and Development (1983)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Naughty_Dog">Naughty Dog (1984)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Ubisoft_Reflections">Ubisoft Reflections (1984)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Rockstar_San_Diego">Rockstar San Diego (1984)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Rare_Ltd.">Rare (1985)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Bethesda_Softworks">Bethesda Softworks (1986)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Codemasters">Codemasters (1986)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Bitmap_Brothers">The Bitmap Brothers (1987)</a></li>
<li><a href="http://en.wikipedia.org/wiki/The_Creative_Assembly">Creative Assembly (1987)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Eutechnyx">Eutechnyx (1987)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Maxis">Maxis (1987)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Dma_design">Rockstar North (1988)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Blue_Byte">Ubisoft Blue Byte (1988)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Climax_Group">Climax Group (1988)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Ubisoft_Montpellier">Ubisoft Montpellier (1989)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Toys_for_bob">Toys For Bob (1989)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Vicarious_Visions">Vicarious Visions (1990)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Team_17">Team 17 (1990)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Blitz_Games_Studios">Blitz Game Studios (1990)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Edge_Games">Edge Games (1990)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Raven_Software">Raven Software (1990)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Blizzard_Entertainment">Blizzard Entertainment (1991)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Epic_Games">Epic Games (1991)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Id_software">id Software (1991)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Bungie">Bungie (1991)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Radical_Entertainment">Radical Entertainment (1991)</a></li>
<li><a href="http://en.wikipedia.org/wiki/EA_Digital_Illusions_CE"><span style="line-height: 1.714285714; font-size: 1rem;">DICE (1992)</span></a></li>
<li><a href="http://en.wikipedia.org/wiki/Rebellion_Developments">Rebellion (1992)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Crystal_Dynamics">Crystal Dynamics (1992)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Treasure_(company)">Treasure (1992)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Digital_Extremes">Digital Extremes (1993)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Volition,_Inc.">Volition (1993)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Funcom">Funcom (1993)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Stainless_Games">Stainless Games (1993)</a></li>
<li><a href="http://en.wikipedia.org/wiki/Criterion_Games">Criterion Games (1993)</a></li>
<li><a href="http://en.wikipedia.org/wiki/High_Voltage_Software">High Voltage Software (1993)</a></li>
</ul>
<p>(Current count: 39)</p>
<p>There are other game companies (including publishers) such as <a href="http://en.wikipedia.org/wiki/Square_enix">Square Enix (2003)</a>, <a href="http://en.wikipedia.org/wiki/Ubisoft">Ubisoft (1986)</a>, <a href="http://en.wikipedia.org/wiki/Capcom">Capcom (1983)</a>, <a href="http://en.wikipedia.org/wiki/Ea">EA (1982)</a>, <a href="http://en.wikipedia.org/wiki/Activision">Activision (1979)</a>, <a href="http://en.wikipedia.org/wiki/Taito_Corporation">Taito (1973)</a>, <a href="http://en.wikipedia.org/wiki/Konami">Konami (1969)</a>, <a href="http://en.wikipedia.org/wiki/Namco">NAMCO (1955)</a>, and <a href="http://en.wikipedia.org/wiki/Nintendo">Nintendo (1889)</a> that have been around for more than twenty years, but I don&#8217;t know if they have [other] studios that have been running that long.</p>
<h2>What is the significance of a short list of game studios?</h2>
<p>A couple of things happened recently that got me thinking:</p>
<ol>
<li><span style="line-height: 1.714285714; font-size: 1rem;">I watched <a href="http://www.imdb.com/title/tt0113243">Hackers</a>. The movie features a scene with footage from a prototype of Wipeout, and the movie credits Sony Psygnosis. <a href="http://en.wikipedia.org/wiki/SCE_Studio_Liverpool">Psygnosis</a> was founded in 1984, acquired by SCE in 1993, became Studio Liverpool in 1999, and was closed in 2012. (and plenty of other things &#8212; go read the linked article)</span></li>
<li><a href="http://en.wikipedia.org/wiki/LucasArts">LucasArts</a> (Lucasfilm Games), formed in 1982, was closed down.</li>
</ol>
<p>Were they to be continuing, these two names would appear near the top of the list above. LucasArts was one of the longest running game development studios in existence at the time of its closure, behind only to HAL Laboratory and Falcom.</p>
<p>The closure of a long-lived studio is a significant thing. Foremost, it has a huge impact on the lives of its employees. But it is a loss, I believe, to the industry as a whole.</p>
<p>(I&#8217;m not looking to make a judgement about whether LucasArts should have been closed or not. Whatever the reasons for the closure &#8212; and I know nothing of them &#8212; it has happened.)</p>
<h2>The passage of time</h2>
<p>There are clearly some benefits to a little bit of age.</p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">Top of my list is experience. The ability to reflect on a long sequence of games &#8212; as a team. To learn from that experience, and to try to make better decisions for future ones. Having a group of people who have worked together over an extended period of time, who may not always agree (or who may rarely agree) but who continue in their commitment to working together to make the best games they can make together. The evidence of investment.</span></p>
<p>Experience making games is one thing. Experience making games with largely the same group of people over many years is another. To know who to ask about a particular ancient system. To know some of the history that has led to otherwise inexplicable artifacts in the technology, tools, and processes of a studio. To have a shared understanding and investment in the company&#8217;s accrued building blocks of game development.</p>
<p>And it&#8217;s not all shiny pony rainbows &#8212; not only good things accrue over time. Investments are made based on decisions that once may have made sense but now may not. Finding agreement and goodwill on all things across any company is nigh impossible. And so there is much effort required to continually move an organization forward.</p>
<p><span style="font-size: 1rem; line-height: 1.714285714;">The list of studios older than twenty years seems pretty short to me, but they&#8217;re all evidence of companies that have been able to grow, change, adapt (in some cases shrink), to move forward in response to outside pressures: changes in technology, changes to the market, to distribution models, and more. There is the possibility of endurance within the industry.</span></p>
<p>But does this endurance matter? Is it important that we have companies that can endure, and change over time? Or is it enough that teams can come together for a time, make a game and disband again only to reform for another project?</p>
<p>One consequence of persistence is the development of a shared identity &#8212; a team culture. The establishment of trajectories, good and bad, that are hard to break. These identities become crystallized in the games we make: the passions, the neuroses, the striving for technical excellence, the pursuit of new experiences, the desire to improve upon the existing, the decisions in the face of so many limitations, these things are reflected in the character of the games produced by a team.</p>
<p>Another consequence is an often implicit snapshot of shared history. Few game developers and publishers seem interested in preserving or enhancing the games they&#8217;ve made beyond a short period of profitability. Archiving &#8212; particularly, providing a public archive of games &#8212; is almost unheard of. A small number of companies release source code. Some interested parties <a href="http://archive.org/details/tosec">attempt to archive older games</a>, to preserve some part of our gaming history. But there are many more games that are created for a time and live only at the whim of their operators, with essential servers lasting a year or less. And just today I see a case where <a href="http://www.bluesnews.com/s/140550">publishers are unable to identify the owner of a game</a>.</p>
<p>In the absence of a widespread commitment to preserving our developing history, longer lived studios are at least some visible evidence that we have that history captured in some form, good or bad.</p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">And there is financial benefit in being a studio that has persisted. Especially one that has made popular products :) An established identity is a valuable thing &#8212; no small part of my motivation to write about this comes from the fact that I have a lot of good memories associated with both LucasArts and Psygnosis.</span></p>
<h2>Is it important?</h2>
<p>I don&#8217;t know. Maybe it doesn&#8217;t matter if there are many &#8220;older&#8221; game studios.</p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">What I do know is that I want studios thrive and live long, productive lives. I want the existence of older game studios to matter. I want games to be more than just one-time projects worked by a group that has come together for a short time only. I want teams of game developers persisting, struggling, wrestling to go beyond what they can do on their own. To inspire one another and to achieve unimagined heights.</span></p>
<p>I want game development to take itself seriously. To record and preserve its history. To provide a the shoulders for later developers to stand upon. I want there to be companies that persist, to be a foundation for the industry. To invest in talent and technology, and to make it available for the benefit of the industry (<a href="ftp://ftp.idsoftware.com/idstuff/source/">one way</a> or <a href="http://www.unrealengine.com/">another</a>).</p>
<p>I want an industry with substance and depth, with studios capable of investing in long-haul projects, able and motivated to be looking long years into the future to consider what they might yet achieve and how to get there.</p>
<p>Selfishly, I want to make games, and I want a secure, reliable job to be able to work for the well-being of my family. I want there to be workplaces that I can commit to, invest in, and that I can trust to be around for years to come. I want to work with experienced, exceptional people. I want to be in that struggle to make great games, with others, for a long time.</p>
<p>I am convinced that the presence of long-lived studios is a good thing for this industry. It is my hope that the list of twenty-and-overs will grow.</p>
<p>&#8212;<br />
While not a gamedev, SN Systems has been providing tools for game development since 1988 :)</p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">&#8212;<br />
</span><em id="__mceDel">Please let me know of any corrections or additions to the list &#8212; it&#8217;s based on wikipedia entries and tweets from people I do and don&#8217;t know.</em></p>
<p>My thanks to twitterers 666uille, JanDavidHassel, SamuelePanzeri, Mimus_, brett_douville, girayozil, Nshk, Allagash, pthiben, RonPieket, and michaelellerman for their suggestions, and to my dear wife for listening to me ramble through some of these thoughts.</p>
<p><strong>Update 2013-04-07-6:</strong> Added Namco, Falcom and Treasure. Thanks to @janvanvalburg</p>
<p><strong>Update 2013-04-07-5:</strong> Added Radical and High Voltage Software. Thanks to @TheJare</p>
<p><strong>Update 2013-04-07-4:</strong> Added Criterion, Eutechnyx, Edge, Raven, Maxis. Thanks to @SebHillaire, @choddlander, @ChristerEricson, and @BrianKaris.</p>
<p><strong>Update 2013-04-07-3:</strong> Added Blitz Game Studios, Rebellion, Climax, Stainless, Crystal Dynamix, Taito. Thanks to @zebrabox, @ggatheral, @HazelMcKendrick, @wuffles, @thinkinggamer, and @jasperbekkers.</p>
<p>Not sure about <a href="http://en.wikipedia.org/wiki/Square_enix">Square Enix</a> &#8211; merger of Square (1983) and Enix (making games since 1982) in 2003.</p>
<p><strong style="line-height: 1.714285714; font-size: 1rem;">Update 2013-04-07-2:</strong><span style="line-height: 1.714285714; font-size: 1rem;"> Added Codemasters. Thanks to @Poita_.</span></p>
<p><strong>Update 2013-04-07:</strong> Added Funcom. Thanks to fred r.</p>
<p><strong>Update 2013-04-06-2:</strong> Added EA Canada, Ubisoft Blue Byte. Thanks to @h4kr and @p1xelcoder.</p>
<p><strong style="line-height: 1.714285714; font-size: 1rem;">Update 2013-04-06:</strong><span style="line-height: 1.714285714; font-size: 1rem;"> Added Bungie, Digital Extremes, HAL Laboratory, Nintendo EAD, Rockstar North, Rockstar San Diego, Team 17 and Volition to The List. Thanks to @alexr, @msinilo, @chrisjrn, @flawe, @morten_skaaning and @fahickman.</span></p>
<p>Added SN Systems as an addendum, thanks @gregbedwell.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1214</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Bug of the day, Tuesday 2013-04-02</title>
		<link>http://brnz.org/hbr/?p=1210</link>
		<comments>http://brnz.org/hbr/?p=1210#comments</comments>
		<pubDate>Sat, 06 Apr 2013 18:01:13 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1210</guid>
		<description><![CDATA[Implicitly finding bugs in other people&#8217;s code A crash was reported with a call stack leading to some code I&#8217;d been making changes to a week ago (code that previously featured in Unexpected use of class and Initialized, but not in the right order). The code I&#8217;d changed now looks something like this: struct Foo : public [...]]]></description>
				<content:encoded><![CDATA[<h3>Implicitly finding bugs in other people&#8217;s code</h3>
<p><span style="line-height: 1.714285714; font-size: 1rem;">A crash was reported with a call stack leading to some code I&#8217;d been making changes to a week ago (code that previously featured in </span><a style="line-height: 1.714285714; font-size: 1rem;" title="Bugs of the day, Friday 2013-03-22" href="http://brnz.org/hbr/?p=1139">Unexpected use of class</a><span style="line-height: 1.714285714; font-size: 1rem;"> and </span><a style="line-height: 1.714285714; font-size: 1rem;" title="Bugs of the day, Monday 2013-03-25" href="http://brnz.org/hbr/?p=1159">Initialized, but not in the right order</a><span style="line-height: 1.714285714; font-size: 1rem;">).</span></p>
<p>The code I&#8217;d changed now looks something like this:</p>
<pre escaped="true" lang="cpp">struct Foo : public Baz {
  Bar* m_Bar;
  Foo() : m_Bar(NULL) {}
  void SetBar(Bar* bar) { m_Bar = bar; }

  virtual void Destroy() override;
};</pre>
<p>The cause of the crash was something trying to make use of a null <strong>m_Bar</strong> member of a <strong>Foo</strong> object.</p>
<p>With regard to the previous crashes I&#8217;d encountered, my first suspicion that this was an object that was somehow being created in a way that had not correctly initialized the <strong>m_Bar</strong>. Checking the circumstances of the crash (the reporter was able to find a specific cause, which was a great help), I was unable to see a way that this object could have been created with <strong>m_Bar</strong> remaining null.</p>
<h3>Sidebar: A way in which my debugging skills have improved in the last year</h3>
<p>I have identified the following tendency in my thinking: see a bug, take a guess at the cause, and then look for that cause in the following way:</p>
<p>1. Examine some part of the codebase.<br />
2. If expected cause not found, goto 1.</p>
<p>So if I guessed the wrong cause, I get stuck in a loop: &#8220;It must be X, but I haven&#8217;t yet found how X could happen &#8212; I must look harder!&#8221;</p>
<p>Part of this came, I think, from a degree of insecurity about my own ability to read and understand code: &#8220;the bug is in here, but I must have missed something&#8221;</p>
<p>What I&#8217;ve realized in the past year is that my code reading skills aren&#8217;t that bad &#8212; if I haven&#8217;t found the cause I&#8217;m looking for, it&#8217;s more likely that I&#8217;m looking for the wrong cause. Particularly, I am now able to approach a problem with a hypothesis about the cause, and can more clearly identify when I&#8217;ve found some information that invalidates that hypothesis and I should be looking for a different cause.</p>
<p>In the context of this bug, validating how the object was being created and seeing that the codepath would always validly initialize <strong>m_Bar</strong> meant that the bug was not in the initialization &#8212; it must be somewhere else.</p>
<h3>The other nuller</h3>
<p>So something else was setting <strong>m_Bar</strong> to null after the initialization. There is one other place where that happens&#8230;</p>
<pre escaped="true" lang="cpp">  virtual void Destroy() {
    if( m_Bar != NULL) {
      m_Bar-&gt;Destroy();
      m_Bar = NULL;
    } else
      HARD_TO_MISS_NOTIFICATION( USEFUL_WARNING_37 );
  }</pre>
<p>So, it looks like there&#8217;s a good chance that this object has had its <strong>Destroy()</strong> called, and looking through the code, it becomes clear that this is indeed what has happened.</p>
<ul>
<li><span style="line-height: 1.714285714; font-size: 1rem;">There was a <strong>Validate()</strong> function called on our object that checked certain things about that object&#8217;s state, calling <strong>Destroy()</strong> if it did not meet certain conditions.</span></li>
<li><strong>Validate()</strong> was called before attempting to make use of <strong>m_Bar</strong>.</li>
<li>The bool returned by <strong>Validate()</strong> is ignored by the calling code.</li>
<li><span style="line-height: 1.714285714; font-size: 1rem;">The circumstances that lead to the crash are such that <strong>Validate()</strong> will always call <strong>Destroy()</strong>.</span></li>
</ul>
<p><span style="line-height: 1.714285714; font-size: 1rem;">One <strong>if(!Validate()) return;</strong> later, the crash no longer occurs.</span></p>
<p>This bug came from a combination of circumstances:</p>
<ul>
<li><span style="line-height: 1.714285714; font-size: 1rem;">existing code that ignored the logical (? I guess that&#8217;s the right word&#8230;) validity of the object &#8212; it had been destroyed, but still contained valid data, and</span></li>
<li><span style="line-height: 1.714285714; font-size: 1rem;">my change with caused the logical state to be reflected in actual state.</span></li>
</ul>
<p>I did examine all the other callers of the <strong>Validate()</strong> function &#8212; none of these exhibited the same type of problem.</p>
<p>&nbsp;</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1210</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bugs of the day, Friday 2013-03-29</title>
		<link>http://brnz.org/hbr/?p=1199</link>
		<comments>http://brnz.org/hbr/?p=1199#comments</comments>
		<pubDate>Sat, 06 Apr 2013 06:53:17 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1199</guid>
		<description><![CDATA[This wasn&#8217;t a runtime bug, but two(!!) compile-time bugs that I checked in for others to find :\ Not all code is compiled with the same warning levels everywhere, so something that compiles without warning in one application with a lower warning level may not compile in another with a higher warning level (assuming warnings-as-errors). [...]]]></description>
				<content:encoded><![CDATA[<p>This wasn&#8217;t a runtime bug, but two(!!) compile-time bugs that I checked in for others to find :\</p>
<p>Not all code is compiled with the same warning levels everywhere, so something that compiles without warning in one application with a lower warning level may not compile in another with a higher warning level (assuming warnings-as-errors).</p>
<p>After finding <a title="Compiler-assisted code cleaning, Thursday 2013-03-28" href="http://brnz.org/hbr/?p=1197">no-longer-needed uses of a particular macro</a>, I did not delete my finder code. But taking the address of a class&#8217; member function and not doing anything with it can be warning-inducing. Bah.</p>
<p>And one of the former users of the macro was left with a no-longer-used variable after my changes,  This was code I had failed to delete on the first pass. I am disappointed with myself to have not deleted more code when I first had the chance.</p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">How should I avoid such problems in the future? Compile code I change for all targets/configurations/applications that matter.</span></p>
<p><span style="line-height: 1.714285714; font-size: 1rem;">Sometimes one can be too lazy.</span></p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1199</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Compiler-assisted code cleaning, Thursday 2013-03-28</title>
		<link>http://brnz.org/hbr/?p=1197</link>
		<comments>http://brnz.org/hbr/?p=1197#comments</comments>
		<pubDate>Sat, 06 Apr 2013 06:37:07 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1197</guid>
		<description><![CDATA[This was another day of no runtime bugs. Instead of a picture, I&#8217;ll describe a specific(ish) case of using the compiler to catch all uses of a particular pattern in the code. class Foo {}; // Bar is one of many classes that inherit from Foo class Bar : public Foo {}; // Baz is [...]]]></description>
				<content:encoded><![CDATA[<p>This was another day of no runtime bugs. Instead of a picture, I&#8217;ll describe a specific(ish) case of using the compiler to catch all uses of a particular pattern in the code.</p>
<pre escaped="true" lang="cpp">class Foo {};

// Bar is one of many classes that inherit from Foo
class Bar : public Foo {};

// Baz is one of many classes that inherit from Bar
class Baz : public Bar {};

DECLARE_EXTRA_STUFF_FOR_CLASS(Baz);</pre>
<p><span style="line-height: 1.714285714; font-size: 1rem;">So we have something like the above. The <strong>DECLARE_EXTRA_STUFF_FOR_CLASS()</strong> macro is used for some but not all classes that inherit directly or indirectly from <strong>Foo</strong>.</span></p>
<p>There have recently been changes within a system that means that <strong>DECLARE_EXTRA_STUFF_FOR_CLASS()</strong> is now never needed for any class that inherits from <strong>Bar</strong> &#8212; but it is not invalid for it to remain used in the codebase. Anything that makes use of the <strong>EXTRA_STUFF</strong> that the macro provides will still work, it&#8217;s just extra unneeded code which I&#8217;d like to clean up.</p>
<p>I could audit this by hand &#8212; find every class inheriting from <strong>Bar</strong>, check to see if there&#8217;s a macro definition for that class somewhere and perform the subsequent clean up, but I&#8217;m lazier than that.</p>
<p>I could write a script that finds classes that inherit from <strong>Bar</strong>, and then search for that class name with the macro, but that also seems like to much work. (A simple regex sweep through the codebase won&#8217;t trivially identify <strong>class Asd : public Baz {}</strong> as inheriting from <strong>Bar</strong>). I&#8217;m lazier than this.</p>
<p>What I can do is break the code expanded by the macro if it is passed a subclass of <strong>Bar</strong>. To do that, I can do something like the following:</p>
<pre escaped="true" lang="cpp">class Foo              { <strong>public:  static void Foo(){}</strong> };
class Bar : public Foo { <strong>private: static void Foo();</strong> };
// Add a line to the macro...
DECLARE_EXTRA_STUFF_FOR_CLASS(class_name) \
    extra_stuff; \
    <strong>class_name::Foo(); \</strong>
    more_extra_stuff</pre>
<p>Done. Anywhere where the macro is invoked for a class inheriting from <strong>Bar</strong> will trigger a compile error. Walk through the errors, delete calls to that macro, rewrite (i.e. delete) code as necessary.</p>
<p>End result: less code. I count that as a win.</p>
<p>(In my specific case, I made an already existing public method declared in <strong>Foo</strong> private in <strong>Bar</strong> because there is no need to call it from or for classes in that part of the hierarchy. This has the added advantage of not polluting the list of <strong>Foo</strong>&#8216;s members with no functionality of the class. Additionally, I didn&#8217;t call the function within the macro but instead took it&#8217;s address.)</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1197</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Photograph of the day, Wednesday 2013-03-27</title>
		<link>http://brnz.org/hbr/?p=1192</link>
		<comments>http://brnz.org/hbr/?p=1192#comments</comments>
		<pubDate>Thu, 28 Mar 2013 05:01:37 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[imagery]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1192</guid>
		<description><![CDATA[Between wrestling with changelists and other matters, I experienced none of my own runtime bugs today. So here&#8217;s a photograph.]]></description>
				<content:encoded><![CDATA[<p>Between wrestling with changelists and other matters, I experienced none of my own runtime bugs today. So here&#8217;s a photograph.</p>
<div class="wp-caption aligncenter" style="width: 693px"><a href="http://www.flickr.com/photos/adamczewski/7079097859/in/photostream/"><img alt="" src="http://farm6.staticflickr.com/5342/7079097859_cb29dc8c3d_b.jpg" width="683" height="1024" /></a><p class="wp-caption-text">Dusk, looking south on Old Surrey Road Burnie, Tasmania, December 2011</p></div>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1192</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Can C++11&#8242;s final qualifier affect codegen?</title>
		<link>http://brnz.org/hbr/?p=1181</link>
		<comments>http://brnz.org/hbr/?p=1181#comments</comments>
		<pubDate>Wed, 27 Mar 2013 18:27:57 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1181</guid>
		<description><![CDATA[To satisfy my curiosity, I compiled this struct A { void f(); }; struct B { virtual void f(); }; struct C { virtual void f() final; }; void a(A&#38; a) { a.f(); } void b(B&#38; b) { b.f(); } void c(C&#38; c) { c.f(); } like this g++ call.cpp -std=c++11 -O3 -S -o- -masm=intel [...]]]></description>
				<content:encoded><![CDATA[<p><span style="line-height: 1.714285714; font-size: 1rem;">To satisfy my curiosity, I compiled this</span></p>
<pre escaped="true" lang="cpp">struct A { void f(); };
struct B { virtual void f(); };
struct C { virtual void f() final; };
void a(A&amp; a) { a.f(); }
void b(B&amp; b) { b.f(); }
void c(C&amp; c) { c.f(); }</pre>
<p><span style="line-height: 1.714285714; font-size: 1rem;">like this</span></p>
<pre escaped="true" lang="">g++ call.cpp -std=c++11 -O3 -S -o- -masm=intel # gcc-4.7.2 i686-pc-cygwin</pre>
<p>which produced [output that included] this</p>
<pre escaped="true" lang="asm">__Z1aR1A:
    jmp __ZN1A1fEv

__Z1bR1B:
    mov eax, DWORD PTR [esp+4]
    mov edx, DWORD PTR [eax]
    mov eax, DWORD PTR [edx]
    jmp eax

__Z1cR1C:
    jmp __ZN1C1fEv</pre>
<p>What does it mean? Because <strong>C::f()</strong> is marked <strong>final</strong>, calls to it can be devirtualized by the compiler, so there is no extra indirection when calling it in the above case.</p>
<p>(Trying the same code with VS2012&#8242;s cl.exe, the call to <strong>C::f()</strong> does not appear to be devirtualized)</p>
<p><strong>struct C</strong> does still appear to have a virtual function table pointer: <strong>(sizeof(C) == sizeof(B) == 4)</strong>, whereas <strong>(sizeof(A) == 1)</strong>. It seems to me that the vtable pointer could be omitted in this case&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1181</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bug review, 2013-03-26</title>
		<link>http://brnz.org/hbr/?p=1173</link>
		<comments>http://brnz.org/hbr/?p=1173#comments</comments>
		<pubDate>Wed, 27 Mar 2013 06:38:08 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[general]]></category>
		<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1173</guid>
		<description><![CDATA[Last week, I started writing about runtime bugs that I&#8217;ve encountered in my own code, for my own interest and potential benefit. This post contains a summary of the issues I noticed, and a brief self-review of the week. Summary of the week Tuesday Changed virtual function prototype results in correct function not being called [...]]]></description>
				<content:encoded><![CDATA[<p>Last week, I started writing about runtime bugs that I&#8217;ve encountered in my own code, for my own interest and potential benefit. This post contains a summary of the issues I noticed, and a brief self-review of the week.</p>
<h2><span style="font-size: 1.285714286rem; line-height: 1.6;">Summary of the week</span></h2>
<p><a title="Bugs of the day,  Tuesday 2013-03-19" href="http://brnz.org/hbr/?p=1114">Tuesday</a></p>
<ul>
<li>Changed virtual function prototype results in correct function not being called</li>
<li>memcpy() into an uninitialized pointer variable</li>
<li>Bad loop counting</li>
<li>Failing to store updated state</li>
</ul>
<p><a title="Bugs of the day, Wednesday 2013-03-20" href="http://brnz.org/hbr/?p=1124">Wednesday</a></p>
<ul>
<li>Uninitialized class member</li>
<li>Sliced inheritance</li>
<li>Undesired printf() output</li>
</ul>
<p><a title="Bugs of the day, Thursday 2013-03-21" href="http://brnz.org/hbr/?p=1135">Thursday</a></p>
<ul>
<li>Failed to initialize instance-specific member variable correctly because I was calling the wrong constructor</li>
<li>Use of uninitialized system</li>
<li>Yet another uninitialized member variable crash</li>
</ul>
<p><a title="Bugs of the day, Friday 2013-03-22" href="http://brnz.org/hbr/?p=1139">Friday</a></p>
<ul>
<li>Unexpected use of class</li>
<li>Hard-coded array size, no checking</li>
<li>General disaster</li>
</ul>
<p><a title="Bugs of the day, Monday 2013-03-25" href="http://brnz.org/hbr/?p=1159">Monday</a></p>
<ul>
<li>Initialized, but not in the right order (fallout from Unexpected use of class)</li>
</ul>
<p><a title="Bugs of the day, Tuesday 2013-03-26" href="http://brnz.org/hbr/?p=1167">Tuesday</a></p>
<ul>
<li>Local static state is local, static</li>
<li>Redux: Changed virtual function prototype results in correct function not being called</li>
</ul>
<h2>Trends</h2>
<p>Looking back over the week, failure to initialize, failure to init at the right time or in the right order stands out as a primary source of bugs. Maybe I need to be asking myself questions like &#8220;where did this variable&#8217;s state come from&#8221; to try and prompt more consideration of this.</p>
<p>Broadly, there is also what appears to be insufficient familiarity with various of C++&#8217;s OO features, resulting in silly mistakes. I don&#8217;t generally write much OO-style code &#8212; this week has been unusual in that way. It is a problem if I can&#8217;t use them reliably.<em><br />
</em></p>
<p>I&#8217;m pretty happy with <a title="Bugs of the day, Tuesday 2013-03-26" href="http://brnz.org/hbr/?p=1167">the solution</a> to the &#8220;<a title="Bugs of the day,  Tuesday 2013-03-19" href="http://brnz.org/hbr/?p=1114">Changed version prototype</a>&#8220; situation. Finding ways to prevent possible runtime bugs at compile-time always feels like a worthy achievement.</p>
<h2>Meta</h2>
<p>Thus far, I&#8217;ve found the process of logging these bugs to be worthwhile &#8212; attempting to explain the bugs helps me to understand them more clearly. I have found myself thinking about the bugs: the solutions I&#8217;ve attempted, and how to try to avoid writing the same bugs in the future.</p>
<p>My plan for now is to continue to write these posts. Hopefully, it leads to fewer bugs.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1173</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Bugs of the day, Tuesday 2013-03-26</title>
		<link>http://brnz.org/hbr/?p=1167</link>
		<comments>http://brnz.org/hbr/?p=1167#comments</comments>
		<pubDate>Wed, 27 Mar 2013 05:55:17 +0000</pubDate>
		<dc:creator>jonathan</dc:creator>
				<category><![CDATA[programming]]></category>

		<guid isPermaLink="false">http://brnz.org/hbr/?p=1167</guid>
		<description><![CDATA[One bug, and one better solution to a previous bug. Local static state is local, static int Foo() { static int timeout = kTimeoutLimit; bool polled_condition = CheckExternalCondition(); if( !polled_condition ) --timeout; if( timeout == 0 ) { printf("condition not set before timeout"); return kTaskFailed; } if( polled_condition ) return kTaskComplete; else return kTaskIncomplete; } [...]]]></description>
				<content:encoded><![CDATA[<p>One bug, and one better solution to a previous bug.</p>
<h2>Local static state is local, static</h2>
<pre escaped="true" lang="cpp">int Foo() {
  static int timeout = kTimeoutLimit;
  bool polled_condition = CheckExternalCondition();
  if( !polled_condition )
    --timeout;
  if( timeout == 0 ) { 
    printf("condition not set before timeout");
    return kTaskFailed;
  }
  if( polled_condition )
    return kTaskComplete;
  else
    return kTaskIncomplete;
}
void Bar() { 
  while( Foo() == kTaskIncomplete );
}</pre>
<p><span style="line-height: 1.714285714; font-size: 1rem;">Sometimes a local static variable is a useful thing &#8212; conveniently quick to add to any piece of code, and localized to a particular scope. You know everything about what can happen to it during its entire lifetime &#8212; assuming you know about how the scope it is contained within operates. (and I&#8217;m disregarding the returning of references to local static variables from a function. That&#8217;s a whole different bag of fun&#8230;)</span></p>
<p>Quickly rewriting some code today, I added a local static counter &#8212; counting down each time a desired condition was not met, and triggering a <strong>printf()</strong> should the count ever reach zero. I was using this to diagnose that something unexpected had happened, and that some event had not taken place.</p>
<p>The above code should work adequately well &#8212; if <strong>Bar()</strong> is only ever run once (and only from one thread at a time &#8212; but that&#8217;s not the issue here). <strong>timeout</strong> is never reset, so unless <strong>CheckExternalCondition()</strong> returns true, first time, every time, the value in <strong>timeout</strong> will continue to decrease with each run of <strong>Bar()</strong>. If it drops below zero, there will no longer be a limit on the on how long <strong>Foo()</strong> can loop.</p>
<p>A fix here is to make sure timeout is reset each time <strong>Foo()</strong> &#8220;completes&#8221; i.e. when it returns <strong>kTaskComplete</strong> or <strong>kTaskFailed</strong>.</p>
<p>More generally, this does not seem like a good use of a static local variable &#8212; relevant context for the function is not readily apparent within the function, so it seems better to store the timeout value outside of <strong>Foo()</strong>.</p>
<p>(The actual code is more convoluted than the example above, so it&#8217;s not quite as simple as adding a local timeout var in <strong>Bar()</strong>, but only just)</p>
<h2>Redux: <a title="Bugs of the day,  Tuesday 2013-03-19" href="http://brnz.org/hbr/?p=1114">Changed virtual function prototype results in correct function not being called</a></h2>
<p><span style="line-height: 1.714285714; font-size: 1rem;">This was a bug where I changed the prototype for a virtual function, but that classes with the old prototype would not be detected at compile time and would silently do nothing should the virtual function be called. Read the details via the link above.</span></p>
<p>I had added an assert to catch any classes that didn&#8217;t have the new version of the function, but that only worked at runtime, and only when the function was actually called. What I really wanted for this was a compile-time check that was more reliable than the inheriting programmer remembering to use <strong>override</strong>. I discovered that there is a way to do this with C++11: <strong>final</strong>.</p>
<pre escaped="true" lang="c++">class Base {
public:
  virtual void Foo(int some_param, WhatsitType some_other_param)  {  }
private:
  virtual void Foo(int) <strong>final</strong> { }
};</pre>
<p>With this, anything that inherits from <strong>Base</strong> and attempts to define its own <strong>void Foo(int)</strong> method will result in a compile error. I&#8217;m much happier with this, and making this change revealed some extra instances of the old function that I&#8217;d missed in my previous sweep. Huzzah.</p>
]]></content:encoded>
			<wfw:commentRss>http://brnz.org/hbr/?feed=rss2&#038;p=1167</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
