<?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:series="http://unfoldingneurons.com/"
	>

<channel>
	<title>Strides Interactive</title>
	<atom:link href="http://www.stridesdev.org/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.stridesdev.org</link>
	<description></description>
	<pubDate>Tue, 17 Aug 2010 01:51:41 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>I need a break!</title>
		<link>http://www.stridesdev.org/2010/08/i-need-a-break/</link>
		<comments>http://www.stridesdev.org/2010/08/i-need-a-break/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 01:51:41 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=927</guid>
		<description><![CDATA[Dear all,
I&#8217;m taking a short hiatus for the following 4 weeks due to personal commitments as well as the articles themselves running out of steam. I haven&#8217;t been bottling things up enough for me to rant the way I used to and therefore perhaps it&#8217;s time for me to take a break for a while.
I&#8217;ll [...]]]></description>
			<content:encoded><![CDATA[<p>Dear all,</p>
<p>I&#8217;m taking a short hiatus for the following 4 weeks due to personal commitments as well as the articles themselves running out of steam. I haven&#8217;t been bottling things up enough for me to rant the way I used to and therefore perhaps it&#8217;s time for me to take a break for a while.</p>
<p>I&#8217;ll definitely return with more interesting articles and possibly more rants as well.</p>
<p>Many thanks for reading my articles!</p>
<p>Regards,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/08/i-need-a-break/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Applications, Static Libraries and DLLs</title>
		<link>http://www.stridesdev.org/2010/08/applications-static-libraries-and-dlls/</link>
		<comments>http://www.stridesdev.org/2010/08/applications-static-libraries-and-dlls/#comments</comments>
		<pubDate>Tue, 10 Aug 2010 00:13:20 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=908</guid>
		<description><![CDATA[Hi all,
This week I&#8217;ll talk about the 3 main types of projects that are created with C/C++. We&#8217;ve perhaps heard of the term library, framework and engine. However, for this post, we&#8217;re talking about a low level set of articles which defined a certain development strategy.
Not everything is built directly as an application. Some applications [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>This week I&#8217;ll talk about the 3 main types of projects that are created with C/C++. We&#8217;ve perhaps heard of the term <em><strong>library</strong></em>, <em><strong>framework</strong></em> and <strong><em>engine</em></strong><em>. </em>However, for this post, we&#8217;re talking about a low level set of articles which defined a certain development strategy.</p>
<p>Not everything is built directly as an application. Some applications have dependencies, some have extensions during run time, while others have a mix of both.</p>
<p>Whatever it is - there&#8217;s a need to understand what their differences are so that we know when to use what. Read on the find out more.<span id="more-908"></span></p>
<h2>Introduction</h2>
<p>So why are there applications (.exe), static libraries (.lib or .a) and Dynamic-linked library (.dll or .so)? The reason is simple - some information is known before execution, some information <strong>can only be available during execution.</strong></p>
<p>In Windows, a DLL is also an application indirectly. Which is why sometimes you see a DLL runner known as <strong>rundll.exe</strong>. This file allows you to run a DLL alike an application.</p>
<p>In Linux or Solaris, a DLL equivalent is known as a <strong>Shared Object</strong> thus having the extension of  (.so).</p>
<p>Static Libraries on the other hand, are programs that are pre-defined and pre-declared for an application to use. They cannot run on their own and usually require an application to fill up the rest of the blanks.</p>
<h2>Applications (.exe)</h2>
<p>The first thing we were taught in schools when building applications in C is to include this header file known as <strong>stdio.h</strong>.</p>
<p>Most people will understand that this is a requirement, but will not fully understand <strong>why</strong> is it a requirement.</p>
<p>Reason is very simple. All applications need a <strong>starting point</strong>. This starting pointer is usually offered by runtime libraries such as the CRT. Thus if you attempt to build any applications without defining a <strong>main()</strong> for example, the linker will complain that there&#8217;s something unresolved.</p>
<p>This is how the CRT works. It&#8217;ll call your <strong>main() </strong>to kick start the whole process.</p>
<h2>Static Libraries</h2>
<p>These guys on the other hand, are functionalities that are built in. For one, CRT itself is a static library as well even though it uses some dynamic libraries during runtime (for Windows).</p>
<p>A static library usually comes in a package as follows:</p>
<p>1) A single .lib or .a file<br />
2) A bunch of header files</p>
<p>Static libraries also have several special characteristics. I&#8217;ll list 2 below:</p>
<p>1) They do not need to <strong>link</strong>.<br />
2) They allow <strong>declarations without definitions.</strong></p>
<p>What are <em>declarations</em> and what are <em>definitions</em>? Well&#8230; I guess that&#8217;s up to you to find out right? After all, if you do not know this 2 terms, you&#8217;ll probably have a hard time reading this article as well.</p>
<h2>DLLs(Dynamically-Linked Libraries)/Shared Objects</h2>
<p>Although it sounds as though as it&#8217;s a static library loaded during run time, the truth is far from it. A DLL is essentially an application by itself. It may share a heap based on the CRT used for compilation, ie, (Multi-threaded Debug DLL, Multi-threaded DLL), but there&#8217;re a few things that they&#8217;ll definitely have on their own.</p>
<p>For example: <strong>private heap</strong>.</p>
<p>Thus the notion of a singleton that exists one and only in an application is only as true as the application itself. If the application <strong>extends </strong>by loading other dynamic modules during run time, that module <strong>does not have inherent access</strong> to the application&#8217;s private heap.</p>
<p>That means, don&#8217;t expect to access the <strong>same singleton instance</strong> when you call <strong>getInstance()</strong>.</p>
<p>This however, is usually ignored since we&#8217;re encouraged not to put any data attributes into singletons due to its non-deterministic order of destruction.</p>
<p>Dynamic libraries however, have the distinct advantage of quick builds and deployment. Since the DLL needs only what it needs during linking, yes DLL needs to be linked, the overall build time is usually much shorter than the static library or the application. Subjected to project size of course.</p>
<p>Since the DLL is only linked during runtime, there&#8217;s no need to link into the main application everytime a change is made.</p>
<p>However so, DLLs have its disadvantages as well. In particular to the <strong>versioning</strong> of the DLL. If one or more DLL uses the <strong>same set of base classes</strong> and that the application&#8217;s base class binaries are <strong>newer</strong> than the ones linked onto the DLLs, then there&#8217;s a chance of a <strong>code misalignment.</strong></p>
<p>When that happens, even if functions like <strong>GetProcAddress</strong>() works, any calls to the base classes will have an undefined behavior. Reason is because, the memory address of the code memory is <strong>mapped</strong>. Every function or method has an absolute code address. This mapping is changing <strong>whenever a method/function is added or removed.</strong></p>
<p>This causes the expected function/method address to go off alignment and illegal memory access thus causes the application to crash unexpected without any clues.</p>
<p>The second level of impact is when the codes of the base classes were <strong>changed</strong>. This change may reflect a change of logic and thus produce erroneous results. The results can range between just a weird value to a wild or dangling pointer, in which will lead to a crash as well.</p>
<p>All these problems are associated with the symptom known as <strong>DLL HELL</strong>.</p>
<p>And such problems are extremely hard to fix unless there&#8217;s a strong technical lead to highlight the possibilities. On top of that, if the DLLs are from <strong>third party libraries, </strong>good luck!</p>
<h2>Misuse</h2>
<p>I don&#8217;t know if it&#8217;s just me or what but I usually encounter a few companies who tend to claim that they <strong>link to the DLL </strong>during the main build process.</p>
<p>As far as my limited knowledge can tell me, it doesn&#8217;t make any sense to link to any DLLs during the main build process.</p>
<p>If that&#8217;s the case, the DLL should just be a static LIB instead.</p>
<p>It&#8217;ll be a shame however, if these people continue to believe that they&#8217;re linking to a DLL during the build and then <strong>continue to load the DLL </strong>during runtime.</p>
<p>That&#8217;ll end up having <strong>two separate sets </strong>of binaries loaded and they&#8217;ll not even know exactly which piece of code is used! In short, isn&#8217;t this a recipe for disaster?</p>
<h2>Conclusion</h2>
<p>Finally, I&#8217;ll just like to round up the use of the 3 different types of build outputs.</p>
<p>An <strong>application</strong> is what it is, a standalone and executable application. It requires all compilation to work (except for template codes that are not used) and requires all symbols to be <strong>linked</strong> before it can be produced as an executable.</p>
<p>A <strong>static library</strong> is a collection of preprocessed object files which contains usually, logic and workflow. It may not necessary have all the symbols defined even when there&#8217;s declaration for it. A static library requires all codes involved to be compilable <strong>but doesn&#8217;t require any linking.</strong></p>
<p>Finally, a <strong>dynamic linked library</strong> is <strong>also an application</strong> by itself but allows itself to be loaded as part of an application as a <strong>module</strong>. It requires all codes to be compilable as well as all symbols to be <strong>linked</strong> as well.</p>
<p>A DLL is extremely suited to be implemented with the <strong>Bridge Pattern</strong> in OO, where <strong>GetProcAddress</strong> retrieves a function that creates an instance of itself and returns a pointer of its <strong>interface</strong> to the caller.</p>
<p>The caller will then access all available functionalities based on the promise of the interface.</p>
<p>This allows multiple DLLs to implement the same interface without having the application to know of their existence at all. However, I won&#8217;t go into details on how to implement this just yet.</p>
<p>Anyway, I have a plane to catch! Have a nice week ahead and yeah - to all Singaporeans (as well as myself), <strong>Happy National Day!</strong></p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/08/applications-static-libraries-and-dlls/feed/</wfw:commentRss>
		</item>
		<item>
		<title>So cool, it&#8217;s frozen!</title>
		<link>http://www.stridesdev.org/2010/08/so-cool-its-frozen/</link>
		<comments>http://www.stridesdev.org/2010/08/so-cool-its-frozen/#comments</comments>
		<pubDate>Tue, 03 Aug 2010 01:48:12 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=865</guid>
		<description><![CDATA[Dear all,
This week I&#8217;ll address an issue that is common in developers who have the power to decide what goes in and what doesn&#8217;t in an application.
While many developers have lamented at the technical ignorance of their managers who had made certain decisions beyond technical comprehension and always seemingly appears to be an act of [...]]]></description>
			<content:encoded><![CDATA[<p>Dear all,</p>
<p>This week I&#8217;ll address an issue that is common in developers who have the power to decide what goes in and what doesn&#8217;t in an application.</p>
<p>While many developers have lamented at the technical ignorance of their managers who had made certain decisions beyond technical comprehension and always seemingly appears to be an act of stupidity, technical naivete or even worse, a decision taken on their behalf; if something goes wrong, the developer is responsible.</p>
<p>So&#8230; what has this gotta do with &#8220;cool&#8221;?</p>
<p>Well, let&#8217;s begin with looking at developers who make the decisions. To know more, read on&#8230;<span id="more-865"></span></p>
<h2>Introduction</h2>
<p>First of all, we need to understand how decision makers think in order to anticipate the likely actions they&#8217;re going to take. Of course, there&#8217;ll be exceptions, special cases or even illogical or unexplainable decisions made from time to time but there&#8217;re a few things that always happen.</p>
<p>When we talk about &#8220;cool&#8221;, it&#8217;s usually associated with the &#8220;coolness&#8221; of a particular feature, be it graphical, audio, input, network or anything that is on the technical side of things.</p>
<h2>Definition of &#8220;cool&#8221;</h2>
<p>We have to ask ourselves, why does a particular feature appear to be &#8220;cool&#8221;?</p>
<p>The answer lies in the characteristic, role and mind set of the decision maker. If the decision maker is a technical person, then very likely, the definition of &#8220;cool&#8221; would be one that can make his/her technical capabilities shine and proven due to the success of implementing this feature.</p>
<p>However, if the decision maker is a management person, then the definition of &#8220;cool&#8221; will be probably refer to the ability to better manage his/her team.</p>
<p>Lastly, if the decision maker is a sales person, then the definition of &#8220;cool&#8221; will be the ability of this feature to increase the sales revenue.</p>
<p>In short, everybody has a different perspective when it comes to &#8220;cool&#8221;. The crux is whether this notion is applied correctly so that the project doesn&#8217;t freeze.</p>
<p>A project freeze refers to issues, bugs, regression errors and other related errors that causes the project to <strong>stall</strong> for an indefinite amount of time until those problems are resolved. This of course, isn&#8217;t good for the technical, management and sales people.</p>
<h2>Constant truths</h2>
<p>Before we even think of adding a cool feature into an application, we need to know several constant truths. Here&#8217;s a few of them in general:</p>
<p>1) You or your company is running a <strong>business</strong>.<br />
2) You&#8217;re working on a project which has a <strong>finite scope and time frame</strong>.<br />
3) Your company needs <strong>funding</strong> to survive and pay you.<br />
4) Your company will eventually need to sell a <strong>finished product</strong>. Whether it&#8217;s a product to be given to a client or in-house developed product for general consumers.<br />
5) Your project must be <strong>workable</strong>, <strong>deploy-able</strong> and <strong>usable.</strong></p>
<p>So, does your cool feature have the potential to disrupt any of the above-mentioned points? If the answer is yes, then you&#8217;ll better think thrice before committing the changes.</p>
<h2>Does size of role matter?</h2>
<p>The quick answer is - <strong>no!</strong> Size does not matter in roles that help develop the application. The reason is very simple. If everyone has the power to affect the outcome of the project, then everybody is responsible.</p>
<p>If a developer is given the power to introduce any features or libraries as he pleases, then this developer must be <strong>matured </strong>and <strong>rational</strong> enough to consider the impact factors before committing the changes.</p>
<p>Let me give you an example.</p>
<p>Traditionally, C++ programs mostly use standard libraries and near-standard or de-facto libraries such as <strong>boost</strong> to help, in fact, boost the productivity of the whole team.</p>
<p>However, there&#8217;re cases where such libraries are not used due to specific reasons.</p>
<p>In this particular case, a developer actually introduced the use of <strong>boost</strong> library in the middle of a project which has its own capabilities. While the intentions are good, this developer forgot to measure the costs of linking the application to such a huge library.</p>
<p>As we know, boost is not a trivial static library. It&#8217;s alive with templates as well as other preprocessors to start up the entire library.</p>
<p>As a result, the application&#8217;s final execution binary size shot up to nearly 200%. On top of that, compilation of the entire application now takes twice as long. Worst of all, he only used like 1% of the boost library&#8217;s functionalities.</p>
<p>Although this isn&#8217;t a case where it&#8217;s cool but it froze the project, it&#8217;s a good example to demonstrate that such careless and reckless change or addition will inevitably affect the project progress.</p>
<p>When progress is affected, all the truths I&#8217;ve mentioned will be affected as well.</p>
<p><strong>Boost</strong> library is cool as long as it&#8217;s used right from the start. It may not be suitable if an existing boost-like framework/library already existed. You&#8217;ll probably end up with 2 copies of similar functionalities instead.</p>
<h2>Conclusion</h2>
<p>Finally, I&#8217;d just like to say that the only thing that is <strong>cool</strong> is when the application is developed, finished, polished and <strong>published</strong>.</p>
<p>If a team even reaches a stage where their application reaches the stage of publication, then it&#8217;s a big step forward because by selling the product, it gives the team the extension required to build even better, greater and more efficient applications.</p>
<p>Otherwise, if a developer decides to selfishly fall back on his/her own comfort zone by introducing features that are familiar only to him/her, the project progress may suffer badly or even <strong>stall </strong>in the process of fixing the issues created by this decision.</p>
<p>Some may argue that they can rollback with a source control. Agreed, however it&#8217;s still <strong>not a trivial task</strong>. Don&#8217;t forget that you need to test as well. Regression testing, stability testing, coding standards and so on. How do you even know that the rollback itself was done correctly?</p>
<p>Therefore, a feature, no matter how big or small, simple or complicated, must go through a proper process of identifying<strong> potential impact issues,</strong> <strong>design issues</strong> and <strong>effort estimation</strong> in order to frame this feature up into something that can be contained.</p>
<p>While I&#8217;d want to continue, which I&#8217;ll probably do in the next few articles, it&#8217;ll probably be best for me to sign off for now.</p>
<p>Therefore, have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
<p><strong><br />
</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/08/so-cool-its-frozen/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Do you know your limits?</title>
		<link>http://www.stridesdev.org/2010/07/do-you-know-your-limits/</link>
		<comments>http://www.stridesdev.org/2010/07/do-you-know-your-limits/#comments</comments>
		<pubDate>Tue, 27 Jul 2010 06:28:14 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=911</guid>
		<description><![CDATA[Hi all,
This week&#8217;s post came late due to my hectic schedule and I suspect that I might have to even go for a miss for next week&#8217;s post.
In any case, I&#8217;ll try my best to post an article every tuesday.
This week&#8217;s post is very simple - limits.
A lot of people don&#8217;t know theirs. Do you [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>This week&#8217;s post came late due to my hectic schedule and I suspect that I might have to even go for a miss for next week&#8217;s post.</p>
<p>In any case, I&#8217;ll try my best to post an article every tuesday.</p>
<p>This week&#8217;s post is very simple - limits.</p>
<p>A lot of people don&#8217;t know theirs. Do you know yours? Read on&#8230;<span id="more-911"></span></p>
<h2>Introduction</h2>
<p>The limits we&#8217;re referring to are actually very simple things such as native types. For example <strong>char, short, int, long, float, double, </strong>etc&#8230;</p>
<p>So, most of us roughly know what are the limits of these types.  But do we really know?</p>
<p>Most of the time we&#8217;ll see the compiler throwing out warnings, telling us not to mix <em>signed </em>and <em>unsigned </em>types. I&#8217;m very sure that this is one of the warnings that is almost certainly ignored totally.</p>
<p>In the following paragraphs, I&#8217;ll talk about these limits and how they affect our daily applications and development decisions.</p>
<h2>Signed and Unsigned</h2>
<p>So what&#8217;s the difference? Irritating isn&#8217;t it? Well &#8230; not really if you know what to do with it.</p>
<p>First of all, unsigned types <strong>do not apply to floating point types.</strong> They&#8217;re already tied up with storing the mantissa and decimals.</p>
<p>Secondly, unsigned types <strong>cannot be negative.</strong></p>
<p>Thirdly, unsigned types <strong>have twice the limit range </strong>in terms of maximum positive number than their signed variants.</p>
<p>Lastly, in most cases, <strong>bit shifting is safe</strong> across most platforms for unsigned types compared to signed types.</p>
<p>As for signed types, there&#8217;re a few characteristics that one should know.</p>
<p>Firstly, they have a <strong>negative range</strong>. Based on <strong>1&#8217;s compliment</strong>, their negative range is always 1 numeric more than their positive range.</p>
<p>That is, for example, signed char, or simply <strong>char</strong>, positive range is <strong>0 - 127</strong>, the negative range is <strong>-1 to -128</strong>.</p>
<p>Secondly, their <strong>first most significant bit </strong>is used as the <strong>sign indicator.1 </strong>for positive, <strong>0 </strong>for negative. See <a href="http://en.wikipedia.org/wiki/Most_significant_bit">here</a> for more information.</p>
<p>Lastly, this - I&#8217;m not so sure but I&#8217;ve heard that <strong>bit shifting</strong> doesn&#8217;t work properly on some platforms. We&#8217;ve tried it on Visual Studio 2005 without any issues. Basically, the sign bit is first taken out, then the rest of the bits are shifted without the sign bit. Then the sign bit is set back to the most significant bit after it&#8217;s done.</p>
<h2>Limitations</h2>
<p>Every primitive type has a limitation in terms of how far they go. Going beyond these limitations <strong>doesn&#8217;t lead to a crash. </strong>At least not for C++.</p>
<p>Instead, when the maximum limit of a primitive type is reached and that the limit is crossed, the type simply <strong>rolls over</strong> and start all over again.</p>
<p>For example, let&#8217;s take a look at the <strong>unsigned char</strong> type again. It has 8 bits and thus looks like:</p>
<pre>0000 0000</pre>
<p>When it&#8217;s full, it looks like:</p>
<pre>1111 1111</pre>
<p>And that&#8217;s 255 in value. (Consider 0 as a number as well).</p>
<p>What happens when you add 1 into the unsigned char? Let&#8217;s find out:</p>
<pre> 1111 1111
+0000 0001
 ---------
 0000 0000</pre>
<p>Do note - this is <strong>not an OR operation. OR operations </strong>always appear to behave like &#8220;add&#8221; operations. But it&#8217;s not true.</p>
<p>In this case, the bits will simply flow over and. The expected answer was supposed to be:</p>
<pre>1 0000 0000</pre>
<p>But, since unsigned char only has 8 bits to hold all the data, that 1 last most significant bit is truncated and thus resetting the value to <strong>zero!</strong></p>
<h2>Live Example</h2>
<p>Let&#8217;s take a look at live example. The following example that I&#8217;m about to share is based on an <strong>signed short</strong>.</p>
<p>We know that short is usually <strong>2 bytes</strong> long and since it&#8217;s signed, the ranges are:</p>
<p><strong>0  to 32767<br />
-1 to -32768</strong></p>
<p>So what happens when I set <strong>-1</strong> as the amount of credits for the game below?</p>
<div class="wp-caption aligncenter" style="width: 272px"><img title="-1 as credits" src="http://www.stridesdev.org/wp-content/uploads/2010/07/out_of_range_1.jpg" alt="-1 as credits works in Dune 2" width="262" height="116" /><p class="wp-caption-text">-1 as credits works in Dune 2</p></div>
<p>But, do you know what&#8217;s binary state of -1 in a signed short type?</p>
<pre>It's <strong>1111 1111 1111 1111</strong> !!!</pre>
<p>So what happens when I reduce credits for building structures?</p>
<div id="attachment_913" class="wp-caption aligncenter" style="width: 255px"><a href="http://www.stridesdev.org/wp-content/uploads/2010/07/out_of_range_2.jpg"><img class="size-full wp-image-913" title="out_of_range_2" src="http://www.stridesdev.org/wp-content/uploads/2010/07/out_of_range_2.jpg" alt="out_of_range_2" width="245" height="129" /></a><p class="wp-caption-text">When you use credits, the number goes up instead even when it&#39;s negative due to the bit arrangement.</p></div>
<p>Let&#8217;s take a look at the binary state of<strong> -321</strong>:</p>
<pre>1111 1110 1011 1111</pre>
<p>So, there&#8217;re plenty of bits to spend before reaching:</p>
<pre>0111 1111 1111 1111 = 32767</pre>
<p>Thus, you&#8217;ll have as much as <strong>65536</strong> credits to build your army. The hack is really simple. You&#8217;ll only need to <em>modify </em>the file <strong>scenario.pak</strong> in the game directory without modifying the format of the file (best done via a hex editor) and you&#8217;ll get what you want!</p>
<p>I won&#8217;t go into details though <img src='http://www.stridesdev.org/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> </p>
<p>The <em><strong>reverse, </strong></em>however, happens as well. This is when the <strong>harvester</strong> collects enough spice, which I think it&#8217;s around <strong>600 credits</strong> per bulk and returns to the refinery.</p>
<p>So &#8230; if you take -321 credits and add it with 600 credits, what happens?</p>
<p>You&#8217;ll get <strong>279 credits!</strong> In binary this is how it looks like:</p>
<pre><strong>0000 0001 0001 0111</strong></pre>
<p>In terms of binary operations, it&#8217;s correct because the bits have overflowed at the last possible bit, which is,</p>
<p><strong>1111 1111 1111 1111 = -1</strong></p>
<p>Thus, as much as the hack has promised you, it&#8217;ll also take it all away from you in an instant. It&#8217;s just like karma man&#8230; especially when you&#8217;re immersed in attacking the enemy base and forgot to tend to your harvesters who diligently harvest all the spice in the area, only to find that by doing so, it inadvertently causes you to lose a potential 60,000+ credits!</p>
<h2>Example in a bank</h2>
<p>I&#8217;ve once encountered a strange bug when I was working for a bank which I won&#8217;t name. Basically, this account has like 10,000,000,000 in his account. This is like 10 billion; it&#8217;s a test account by the way.</p>
<p>It&#8217;s stored nicely in the database.</p>
<p>So, the code retrieve this value and stored into an <strong>unsigned long</strong> type. But the value that&#8217;s represented in the unsigned long is wrong.</p>
<p>Note that the unsigned long in this case is <strong>32-bits long</strong>.</p>
<p>So why is the value wrong?</p>
<p>Reason is simple - the 32-bit long type can only store a number up to 2^32, which yields roughly around <strong>4.2 billion</strong>.</p>
<p>In this case, the binaries would have overflowed several times before ending up with whatever value it&#8217;s in.</p>
<p>You can try it in your IDE and see if you can get the weird result.</p>
<h2>How to tell the maximum size?</h2>
<p>Very simple. There&#8217;re 2 methods in which you can derive the maximum size.</p>
<p>1) Perform a sizeof(type) ie, <strong>sizeof(int)</strong> and get the byte size, then perform a 2 power of byte size to retrieve the maximum range.<br />
2) Read up on the specification of all the primitive types via documentation and perform the same 2 power of byte size to get the maximum range.</p>
<p>However, do note. For signed variants, always use a 1&#8217;s compliment to derive the negative side as well as to divide your results by 2 first.</p>
<p>For example, signed short range is <strong>0 to 32767, -1 to -32768.</strong> It&#8217;s unsigned variant is <strong>0 - 65535</strong>.</p>
<h2>Conclusion</h2>
<p>In conclusion, knowing your limits of your primitives will serve you a long long way in your development or programming career.</p>
<p>It&#8217;ll also arm yourself with things to look out for, especially suspicious numbers that are exceptionally large.</p>
<p>Without all these knowledge, a programmer is blind when choosing primitives and will be confusion by the range of selection available to him/her.</p>
<p>I&#8217;m sure some of you like myself, would have asked, why need <strong>short</strong> when we have <strong>int</strong> and why need <strong>int</strong> when we have <strong>long</strong>?</p>
<p>A short reason for it is - in the past, data alignment is packed to the brim. That is, unlike nowadays where struct alignment is defaulted at 8 bytes for maximum memory access efficiency, it was as low as 2 bytes during the 16-bit computing era. This help conserves memory usage per object instance and will allow an otherwise un-executable application to be run on machines with very little memory.</p>
<p>We&#8217;re talking about memory as small as <strong>640kb </strong>where RAM takes on an appearance of a multi-legged <strong>bug</strong>.</p>
<p>Yeah, those were the old days of floppy disks, small hard drives and very small RAM capacities in the 8086 era.</p>
<p>Nevertheless, the significance of primitive limits now extends to <strong>design specifications</strong> where a certain variable is limited in range for design reasons.</p>
<p>Knowing it can help save you from getting into weird logic bugs which are hard to detect unless you&#8217;re a binary genius.</p>
<p>With that, I&#8217;m signing off for this week.</p>
<p>Have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/07/do-you-know-your-limits/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Aggregation vs Composition</title>
		<link>http://www.stridesdev.org/2010/07/aggregation-vs-composition/</link>
		<comments>http://www.stridesdev.org/2010/07/aggregation-vs-composition/#comments</comments>
		<pubDate>Mon, 19 Jul 2010 17:11:49 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=873</guid>
		<description><![CDATA[Hi all,
Ok. This is really an object oriented post. Do forgive me if I&#8217;m not as guru or as strict as many OO purists out there. Remember that I do have to balance between a perfect design and a usable design.
In this article, I shall discuss about a topic taught in C++ Beginner level training.
Aggregation [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>Ok. This is really an object oriented post. Do forgive me if I&#8217;m not as guru or as strict as many OO purists out there. Remember that I do have to balance between a <strong>perfect</strong> design and a <strong>usable</strong> design.</p>
<p>In this article, I shall discuss about a topic taught in <strong>C++ Beginner level training</strong>.</p>
<p>Aggregation and Composition, what&#8217;s so different about them? Do I need have a good grasp of English in order to do it properly?</p>
<p>Read on&#8230;<span id="more-873"></span></p>
<h2>Introduction</h2>
<p>Many of us have been taught more or less in Object-Oriented Programming, which is a popular programming methodology used by many programmers and represented by several major languages including C++, Java and C# to name a few&#8230;</p>
<p>In OO, there&#8217;re many terms, some of which sounds alike, while others sound very sophisticated till it&#8217;s misunderstood.</p>
<p>The notion of K.I.S.S (keep it simple and stupid) seems to contradict many of the OO terminology in terms of understanding. Or does it?</p>
<p>We know that OO has quite a few terminologies, each representing a part of OO or a way of doing things. Today, we&#8217;re just going to take a look at Aggregation and Composition because I somewhat believe that the so-called thin line that separates them is what that confuse programmers who are not profficient in English.</p>
<h2>Composition</h2>
<p>Let&#8217;s take a look at composition first.  Now in a class, there&#8217;re several basic building blocks that we know can exists. For example:</p>
<p>1) Access level Modifiers<br />
2) Attributes<br />
3) Methods</p>
<p>I shouldn&#8217;t have to explain what are modifiers. If I do, then this article is probably not meant for you.</p>
<p>Next, we have attributes and finally methods.</p>
<p>It&#8217;s basically telling other programmers that this class is <strong>composed of</strong> the following protected, private or public <strong>attributes</strong>.</p>
<p>So what does <strong>composed of</strong> mean? It simply means that the article is described or specified explicitly as being an integral part of the class. Which means to say, whenever an instance of this class is instantiated, the specified <strong>attribute</strong> will always be <span style="text-decoration: underline;">valid</span> after construction and is part of the object.</p>
<p>&#8220;Valid&#8221; here means that the attribute itself is <strong>instantiated</strong> as well regardless of whether it&#8217;s a native, system or user-defined class type.</p>
<p>If we go deeper, this is what it&#8217;ll mean:</p>
<p>1) If the attribute is 12 bytes long (user-defined <strong>structure</strong> for example), then it <strong>must not be a pointer or reference</strong> <strong>to qualify as a composition</strong>.<br />
2) Since it&#8217;s 12 bytes long, under struct alignment, it&#8217;ll take up 16 bytes of memory.<br />
3) The object size is thus affected by the size of user-defined type.<br />
4) Since it&#8217;s not a pointer or reference, the attribute is guaranteed to be instantiated either by its <strong>default constructor</strong> or a constructor chosen by the main class&#8217; <strong>initialization list.</strong></p>
<p>In such cases, when the <strong>copy constructor</strong> or the <strong>copy assignment operator</strong> is called, the default behavior will be a <strong>deep copy</strong> and will most likely remain as long as it&#8217;s a <strong>composition</strong>.</p>
<p>So in summary, an attribute <strong>composition</strong> is one that is <strong>part of</strong> or more correctly, <strong>composed of</strong> the class and is more likely to be available after construction and by design, will be <strong>deep copied</strong>.</p>
<h2>Aggregation</h2>
<p>Next, we&#8217;ll talk about aggregation. First of all, the very first confusion we&#8217;ll encounter is that, to qualify as an <strong>aggregation</strong>, the attribute must also be part of the class as well. The second confusion is, it seems as though as <strong>all natives are composition, all classes are aggregation.</strong></p>
<p>Now, this confusion is exceptionally true for languages like Java and to some extent, C# as well. This is because, the notion of creating a <em>stack object</em> is virtually impossible in Java but somewhat possible in C#.</p>
<p>Just think, how do you create a user-defined object in Java (which is mutable)?</p>
<pre>UserClass obj; //WRONG!
obj.a = 0; //BOOM!</pre>
<p>The right way would have been:</p>
<pre>UserClass obj = new UserClass(); //instantiated
obj.a = 0; //now it's usable</pre>
<p>In C++, it&#8217;s <strong>very clear cut.</strong> In my previous <a href="http://www.stridesdev.org/2010/07/do-you-know-who-youre-pointing-at/">article</a>, if you should ever use the <strong>new</strong> operator<em> (Yeah, <strong>new</strong> is an <span style="text-decoration: underline;">operator</span>, not a <strong>special keyword</strong>) </em>the object will <strong>always be created in the heap</strong>. If not, it&#8217;s on the <strong>stack</strong> yeah? Well, it depends.</p>
<p>Here&#8217;s the brain twist:</p>
<p>1) An object and its attributes are always created in the <strong>heap</strong> if the whole object is instantiated with the <strong>new</strong> operator.<br />
2) An object and its attributes are always created in the <strong>stack </strong>if the whole object is declared in a function or method as it is.<br />
3) If an object is instantiated with the <strong>new </strong>operator and its attributes are declared <strong>as it is</strong>, then the attribute <strong>is still instantiated as part of the object in the heap.<br />
</strong></p>
<p>So, what has all these have to do with aggregation?</p>
<p>Well, basically, to qualify an attribute as an <strong>aggregation</strong>, that attribute must be a <strong>pointer</strong> or <strong>reference</strong>. <strong>We&#8217;re talking about C++ pointer and C++ reference.</strong></p>
<p>Next, if an attribute is aggregated, there&#8217;s a chance that this actual object must not even exists.</p>
<p>Last but not least, an <strong>aggregated</strong> attribute is an<strong> association</strong>, not <strong>composed of</strong>.</p>
<p>To clear up the confusion, the only part that is <strong>composed of</strong> in an aggregation is the pointer itself, this applies to references as well even though they&#8217;re just aliases with a fixed referent. You see, a pointer takes up <strong>4 bytes</strong> on a 32-bits machine. This 4 bytes must be stored somewhere right?</p>
<p>In this case, it&#8217;s stored as part of an attribute in the main object. Thus, the size of the aggregated object <strong>does not affect </strong>the final size of the main object since the size of the pointer will always remain constant <em>(4 or 8 bytes for 32-bits and 64-bits respectively)</em></p>
<p>Lastly, an aggregation object is always <strong>a foreign object</strong> or to be clear, an object that is instantiated separately in a foreign location. While the object is aggregated, it&#8217;s not part of the class&#8217; &#8220;hard&#8221; manifest.</p>
<p>Thus, an aggregated object is most likely to be <strong>shallow copied</strong> in the respective <strong>copy constructor</strong> and <strong>copy assignment operator</strong>. This of course can be changed when you override them for whatever design reasons that justify the deep copy.</p>
<p>Just note, the pointer itself is technically <strong>deep copied</strong> since the address (4 or 8 bytes) is copied over to the object copy. But do remember, it&#8217;s only the address, not the object, that is being copied over and thus should be considered in object-level, a <strong>shallow copy</strong> instead.</p>
<h2>What&#8217;s the diff?!</h2>
<p>Well, why not take a look at these 2 pictures below?</p>
<p><a href="http://www.stridesdev.org/wp-content/uploads/2010/07/composition.png"><img class="alignleft size-full wp-image-906" title="composition" src="http://www.stridesdev.org/wp-content/uploads/2010/07/composition.png" alt="composition" width="400" height="300" /></a></p>
<p>In fact, every attribute in this particular class is a composition.</p>
<p><a href="http://www.stridesdev.org/wp-content/uploads/2010/07/aggregation.png"><img class="alignleft size-full wp-image-905" title="aggregation" src="http://www.stridesdev.org/wp-content/uploads/2010/07/aggregation.png" alt="aggregation" width="400" height="300" /></a></p>
<p>In this case, the aggregation is clearly shown. Attribute C is a <strong>pointer</strong> while Object C which represents the actual object is somewhere out there in the heap. The rest are all compositions.</p>
<h2>When should I use what?</h2>
<p>It&#8217;s all in the design.</p>
<p>If the attribute is meant to be part of the class, then it should be a <strong>composition</strong>.</p>
<p>If the attribute is meant to be <strong>centralized</strong> for easy access, such a singleton that holds every single factory&#8217;s pointer, then it should be an <strong>aggregation</strong>.</p>
<p>Do note that aggregation, if abused, may lead to <strong>heavy memory fragmentation</strong>. How so? Since the object is nothing but a bunch of pointers (addresses) and the rest of the objects are somewhere out there in the heap, then yeah, the object chunk scatter will be greater (much alike an asteroid being blown into pieces). This thus lead to unusually high memory consumption for large number of small objects even when you have a projected heap size.</p>
<h2>Conclusion</h2>
<p>Unfortunately, this article doesn&#8217;t really apply completely to the Java and C# folks since you guys already have a VM to help you deal with things more or less.</p>
<p>It&#8217;s a pity though for Java in which a language that has been proclaimed as a pure Object Oriented language (better represented than C++) has the lack of ability to specify composition and aggregation explicitly. However I may be wrong, perhaps setting inner objects to be immutable may help?</p>
<p>Anyways, I do hope that this article can shed some light on these 2 seemingly confusing terminologies and as usual, please do not hesitate to correct me if you think that I&#8217;m wrong.</p>
<p>Have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/07/aggregation-vs-composition/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Do you know who you&#8217;re pointing at?</title>
		<link>http://www.stridesdev.org/2010/07/do-you-know-who-youre-pointing-at/</link>
		<comments>http://www.stridesdev.org/2010/07/do-you-know-who-youre-pointing-at/#comments</comments>
		<pubDate>Tue, 13 Jul 2010 01:33:53 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=884</guid>
		<description><![CDATA[Dear all,
This article is in response to some of the people I&#8217;ve met during interviews. I&#8217;m just kinda surprised at their level of understanding of C or C++.
One of the basic concepts of C and C++ is pointers though C++ has a stricter references (int&#38;  for example) that help to clarify things in terms [...]]]></description>
			<content:encoded><![CDATA[<p>Dear all,</p>
<p>This article is in response to some of the people I&#8217;ve met during interviews. I&#8217;m just kinda surprised at their level of understanding of C or C++.</p>
<p>One of the basic concepts of C and C++ is pointers though C++ has a stricter <strong>references</strong> (<em>int&amp; </em> for example) that help to clarify things in terms of usage, the basic understanding of pointers cannot be underestimated.</p>
<p>Why is that so? Read on&#8230;<span id="more-884"></span></p>
<h2>Introduction</h2>
<p>First of all, there&#8217;s a need to understand what exactly is a pointer. In very simple terms:</p>
<p><strong><em>A pointer is nothing but a number representing a memory address.</em></strong></p>
<p>The size of the memory address of course depends on the architecture. 32-bits, 4 bytes, 64-bits, 8 bytes. Nothing complicated.</p>
<p>However, a pointer also has a <strong>type</strong>. A type means <strong>class, struct </strong>or <strong>primitives</strong>. Which is why <em><strong>void*</strong></em> is valid. They&#8217;re simply memory addresses with no classification of types. That&#8217;s why they&#8217;re the most generic form of a full pointer.</p>
<p>Once you start to classify pointers with types, for example (C style):</p>
<p><em><strong>void* ptr = 0&#215;12345ABC;<br />
cMyClass* classPtr = (cMyClass *)ptr;</strong></em></p>
<p>By doing this, you are, in my terms, <em>casting a shadow or a net on top of the address</em>.</p>
<p>The system doesn&#8217;t understand it - neither does it perform checks on the cast validity <em>(unless it&#8217;s dynamic_cast&lt;T&gt; with terms and conditions)</em>. So why does it even work then?</p>
<h2>Classes and Structs</h2>
<p>Now we just take a short moment to pull back things a little. We all know that classes and structs are very similar with the exception that classes have methods, access modifiers and inheritance capability. Structures can do that too - with disastrous results of course - as mentioned in my previous post <a href="http://www.stridesdev.org/2010/07/inheritance-disaster/">here</a>.</p>
<p>On top of that,  a class or structure has this property, at least in Visual Studio, known as <strong>struct alignment.</strong> Under <strong>default</strong> setting, it&#8217;s 8-bytes.</p>
<p>What does it mean?</p>
<p>It means that <strong>between each attribute in the class, it&#8217;s a 8-bytes block.</strong> For example, if you have 3 booleans inside a struct, how many bytes will they take up? 1 byte because they&#8217;re just 3 booleans? No! Under struct alignment, it&#8217;ll be<strong> 24 bytes</strong>.</p>
<p>As to why it&#8217;s set at 8 bytes - that I can only <em>speculate</em>. My guess is, since the biggest data type in C/C++ is <strong>double</strong> or <strong>unsigned long long</strong> which are both 64-bits wide and thus translates to 8-bytes, it&#8217;s sort of optimized to assume that all data are 8-bytes apart rather than having to check for unaligned memory.</p>
<p>I know this is exceptionally true in assembly language though <em>(in terms of the aligned or unaligned memory)</em>.</p>
<h2>Shadow-casting</h2>
<p>Don&#8217;t get me wrong - this is not another type of casting mechanism in C or C++. It also doesn&#8217;t refer to the old shadow ROM or memory that your ancient motherboard might have as an option to turn on or off.</p>
<p>A shadow-cast is basically like this: Imagine yourself standing on a pavement and the sun is shining on you, you cast a shadow naturally. If the shadow is cast correctly, then you&#8217;ll see a complete shadow of yourself. In this sense you can take it as a <strong>valid cast</strong>.</p>
<p>In another scenario, imagine yourself standing a few steps before a cliff, the sun shines on you and you cast a shadow. Notice how the shadow disappears as it reaches the cliff? In that sense, you can take it as a <strong>wild/invalid/dangling cast.</strong> Basically, it means that the memory is shadowed incorrectly and will lead to disastrous results if it&#8217;s <strong>read from </strong>or <strong>written onto</strong>.</p>
<p>Now, knowing the <em>shadow-cast</em> <em>size</em> is important since you know that memory buffers too have such problems. Knowing your struct alignment will give you an accurate picture of whether your shadow casting is done correctly or not. In short, if you&#8217;re shadowing a piece of memory that is 24 bytes long and that your shadow specification is 32 bytes long, you&#8217;ll end up having <strong>8-bytes shadowed illegally</strong>. While that alone doesn&#8217;t cause a crash, again, accessing it in terms of read or write operations will almost certainly lead to a crash.</p>
<h2>Known Memory</h2>
<p>So, the next thing we need to refresh ourselves is the 4 basic types of memory used by C/C++. That is:</p>
<ol>
<li>Stack</li>
<li>Heap</li>
<li>Code</li>
<li>Private Heap aka Static</li>
</ol>
<p>Though they&#8217;re used at different times, it doesn&#8217;t mean that we cannot point at them anytime. Have you heard of things like <em><strong>function pointers</strong>? </em>These pointers are basically pointing to the code memory address of the function itself.</p>
<h2>Myths</h2>
<p>With the stage set, I&#8217;m going to move into the myths. But just quickly allow me to define some phrases to reduce or eliminate any confusion.</p>
<ul>
<li>Stack pointer means a pointer pointing to an address on the stack</li>
<li>Heap pointer means a pointer pointing to an address on the heap</li>
<li>Function pointer means a pointer pointing to a code memory address in the code memory</li>
<li>Singleton pointer means a pointer pointing to an address in the private heap</li>
<li>Static pointer means that a pointer is declared as static and its contents, which is the memory address is stored private heap.</li>
</ul>
<p><strong>Myth #1 - I should always delete a pointer when I&#8217;m done with it.</strong></p>
<p>In truth, this statement is technically correct in a very literal perspective. However, this statement falls apart when you&#8217;re given pointers that is pointing to any type of memory other than <strong>heap</strong>.</p>
<p>Unless you have a memory map which maps a range of memory for stack, heap, code, etc, there&#8217;s no direct way to tell, by simply reading from the pointer, whether the address is pointing towards a heap or not.</p>
<p>In this sense, this statement should only apply to <strong>your own attributes</strong>. If you&#8217;re receiving pointers from another party, always check out its contract and origins. If your design requires the pointer to be deleted nevertheless, then the caller has invoked your function wrongly by passing in the wrong type of pointers.</p>
<p><strong>Myth #2 - If I have a stack pointer, I don&#8217;t have to delete them.</strong></p>
<p>Basically, this is not a myth only if you&#8217;re absolutely sure that it&#8217;s not a <strong>heap</strong> pointer. Again, this is only possible if you know the contract and possible pointer inputs. You can also state your own contract of how things work in your class in order to deter callers from passing in the wrong type of pointers.</p>
<p>Otherwise, it&#8217;s true.</p>
<p>Not only you don&#8217;t have to delete them. It&#8217;s best to set them to NULL once you&#8217;re done with them. Don&#8217;t worry about the actual stack though; you&#8217;re just setting the pointer&#8217;s holding address to NULL that&#8217;s all.</p>
<p>Reason being that should the life of the pointer <strong>exceeds</strong> the life of the function call, then it&#8217;s almost certain that this innocent pointer will turn into a <strong>wild</strong> or <strong>dangling</strong> pointer. Reading or writing means <strong>death</strong> to the application.</p>
<p><strong>Myth #3 - I don&#8217;t have to delete static pointers because the compiler does it for me</strong></p>
<p>Again, this statement demonstrates an insufficient level of understanding for pointers. If a pointer is <strong>declared as a static variable</strong>, then the pointer itself is stored in the <strong>private heap</strong>. But if you instantiate an object and assign the new address to this static variable, where&#8217; s the object?</p>
<p>Very simple. Just ask yourself how do you instantiate your object? <strong>malloc? new?</strong> Fine. Where does these allocators draw their memory from? <strong>THE HEAP!</strong></p>
<p>So, even though your pointer is <strong>declared as a static pointer, </strong>you&#8217;re responsible for the <strong>heap</strong> <strong>address </strong>assigned to your static pointer during instantiation!</p>
<p><strong>Myth #4 - I don&#8217;t have to delete my heap pointers all the time</strong></p>
<p>Surprising this myth is actually true! However, it comes with several conditions. You see, <strong>memory leaks</strong> are not lethal by nature. It&#8217;s the accumulation of leaks that eventually lead to crashes.</p>
<p>Therefore, if you can ensure that all your pointers will only <strong>ever be instantiated once</strong>, then this statement holds true. That&#8217;s because the OS will clean up your heap for you anyway.</p>
<p>However, do note - <strong>OS handles (ie, file handles) are not released </strong>just like that. You&#8217;ll need to manually release it or else it&#8217;ll be leaked until you restart your machine!</p>
<p><strong>Myth #5 - I can control my private heap</strong></p>
<p>Sure you can control the <strong>contents </strong>in the private heap. But this control doesn&#8217;t extent itself to as far as allowing you to delete the actual private heap itself. See the next myth to understand more.</p>
<p><strong>Myth #6 - Singleton pointers must be the last pointers ever to be deleted<br />
</strong></p>
<p>Singletons are stored in the private heap as we know.  If there&#8217;s a pointer to the private heap, then so be it.</p>
<p>But know this - the CRT <strong>will </strong>eventually clean up the private heap. But the order of destruction <strong>is not known to you or can be controlled by you alike the way you control heap deletes.</strong></p>
<p>Therefore, this statement is a myth. Try it and you&#8217;ll probably get some weird errors as your program exits. Also, if you create a cross-dependency across multiple singletons, then it&#8217;s going to be a <strong>long long nightmare</strong>.</p>
<h2>Conclusion</h2>
<p>Those myths above are just some examples of insufficient understanding on C and C++ memory handling. There&#8217;re plenty more but I don&#8217;t have the luxury to post them all up here.</p>
<p>Besides, even I myself is still learning new things everyday.</p>
<p>Therefore, I hope that this article can be understood by everyone and doesn&#8217;t contain technical errors. I&#8217;m sharing from experience yes? But it doesn&#8217;t mean that my experience is flawless. <img src='http://www.stridesdev.org/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>Thus, don&#8217;t try to kill yourself by reading this post too hard. If you find it hard to swallow, take a step back. Read other posts prior to try to gain more understanding towards C/C++ memory.</p>
<p>Otherwise, if I&#8217;m wrong, please feel free to criticize by leaving a comment. I&#8217;ll be glad to receive any guidance and corrections anytime!</p>
<p>Have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/07/do-you-know-who-youre-pointing-at/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Inheritance disaster</title>
		<link>http://www.stridesdev.org/2010/07/inheritance-disaster/</link>
		<comments>http://www.stridesdev.org/2010/07/inheritance-disaster/#comments</comments>
		<pubDate>Tue, 06 Jul 2010 04:04:35 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=886</guid>
		<description><![CDATA[This entry is part 4 of 4 in the series Programming Disaster SeriesDear all,
This week&#8217;s article will be rather short because I&#8217;ll only be focusing on 1 single issue that I&#8217;ve come across. Some may think that it&#8217;s complete stupidity while others may be more sympathetic.
In any case, this is a disaster scenario caused by [...]]]></description>
			<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 4 of 4 in the series <a href="http://www.stridesdev.org/series/programming-disaster-series/" title="series-30">Programming Disaster Series</a></div><p>Dear all,</p>
<p>This week&#8217;s article will be rather short because I&#8217;ll only be focusing on 1 single issue that I&#8217;ve come across. Some may think that it&#8217;s complete stupidity while others may be more sympathetic.</p>
<p>In any case, this is a disaster scenario caused by misunderstanding or abusing the use of Object Oriented programming in C++</p>
<p>Read on to find out more&#8230;<span id="more-886"></span></p>
<h2>Introduction</h2>
<p>We all know that C++ is an OO language. Therefore we can perform many things with C++, some of which can&#8217;t even be fulfilled properly by languages like Java. I&#8217;ll explain my statement in the future.</p>
<p>One of the shining mechanisms of Object-Oriented Programming is of course, <strong>inheritance</strong>. To many it&#8217;s a feature that is widely abused to reduce the amount of codes written and also poor attempts to improve reusability.</p>
<p>If done correctly, a framework or engine can easily become popular with programmers. Otherwise, it increases <strong>coupling </strong>to very dangerous levels and can easily cause the whole system to collapse by design failures.</p>
<h2>Scenario</h2>
<p>The scenario I have here today is based on C++ only. So, sorry Java and C# folks, you may have to sit this one out this time. But still, it may be something interesting to read up.</p>
<p>Once I was asked to resolve a very weird memory issue encountered with one of my customers. Basically, this customer was trying to make this structure compatible with a linked list node.</p>
<p>Reason? So that he can add structures into a linked list!</p>
<p>Now, this is one classic example where a Java-style programmer tries to make things happen using the Java way in C++. <strong>This is suicidal.</strong></p>
<p>So we&#8217;re looking at a piece of code which looks like this:</p>
<p><strong><em>struct MyStructure : public cLinkedListNode {<br />
&#8230;</em></strong></p>
<p><strong><em>};</em></strong></p>
<p>By understanding that structs and classes are alike, this is supposed to work right?</p>
<p>Well&#8230; yeah, technically, if this is the <strong>only</strong> predicate, then yes. However, another rule or practice will easily destroy this whole thing - <em>All structures should always be <strong>memset</strong> to zero before usage.</em></p>
<p>So&#8230; I do something like this:</p>
<p><em><strong>MyStructure instance;<br />
memset(&amp;instance, 0, sizeof(MyStructure));</strong></em></p>
<p>What happens next?</p>
<p><strong>You&#8217;ll get a very tight slap on your face!</strong></p>
<p>Why? Simple, whenever you inherit another class, the first 4 or 8 bytes, depending on your system architecture and struct alignment, will contain an address to a table known as the <strong>vtable</strong>.</p>
<p>Without this table, it&#8217;s impossible for polymorphism to work and setting it to null certainly ensures that all your virtual methods will lead to disaster.</p>
<h2><strong>Conclusion</strong></h2>
<p>While it&#8217;s important to understand C++ semantics, it&#8217;s also important to know that structures are not recommended in a pure C++ environment.</p>
<p>Surely, a mixture C and C++ is possible and even things like temporary variables in C++, which in pure C environments, are illegal, can be used with proper control and understanding.</p>
<p>The problem arises when both standards are mixed wrongly as mentioned in the example above. In that case, neither can the structure be used the C-style way nor can it be added into a linked list just like that.</p>
<p>Solution?</p>
<p>Well&#8230; if C++ is to be used, either convert the structure into a class or implement a default constructor for its members. This is allowed in C++ by the way.</p>
<p>Next, the implementation of the linked list is wrong too.</p>
<p>This is C++, not Java. There&#8217;s no notion of an Object being the all generic object of every possible object out there. Thus comes this language facility known as - <strong>templates</strong>.</p>
<p>For example, Strideslib&#8217;s version of the linked list is known as <strong>cLinkedList&lt;T&gt;</strong>. Where T must be specialized in order for the template to be usable. It&#8217;s extremely type-strict, thus specializing it with a normal variable is not recommended.</p>
<p>For example: <strong>cLinkedList&lt; MyStructure &gt;</strong></p>
<p>This example above requires MyStructure to have a default constructor or else it may not compile. On top of that, it should be used in conjunction of a pointer container such as <strong>cSmartPtr&lt;T&gt;.</strong></p>
<p>For example: <strong>cLinkedList&lt; cSmartPtr&lt; MyStructure &gt; &gt;</strong></p>
<p>This way, you reduce the amount of work done by the linked list; the copy assignment operator doesn&#8217;t have to be invoked everything you get something out from the linked list.</p>
<p>Unless there&#8217;s a very strong reason for inheritance, which otherwise, fail completely in the example above, composition or aggregation should be used instead.</p>
<p>I&#8217;ll cover these few terms in one of the next few articles.</p>
<p>If not, I&#8217;m done for the week. I&#8217;ll probably be taking a brief hiatus to work on other things very soon.</p>
<p>Have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/07/inheritance-disaster/feed/</wfw:commentRss>
	
		<series:name><![CDATA[Programming Disaster Series]]></series:name>
	</item>
		<item>
		<title>&#8216;this&#8217; pointer disaster</title>
		<link>http://www.stridesdev.org/2010/06/this-pointer-disaster/</link>
		<comments>http://www.stridesdev.org/2010/06/this-pointer-disaster/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 02:00:43 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=858</guid>
		<description><![CDATA[This entry is part 3 of 4 in the series Programming Disaster SeriesHi all,
This week I&#8217;ll be talking about &#8216;this&#8216; pointer. Yeah this little pointer that points to self. Unfortunately, this article won&#8217;t really apply to Java or C# users. Nevertheless, you guys may also wanna read this article to appreciate the kind of things [...]]]></description>
			<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 3 of 4 in the series <a href="http://www.stridesdev.org/series/programming-disaster-series/" title="series-30">Programming Disaster Series</a></div><p>Hi all,</p>
<p>This week I&#8217;ll be talking about &#8216;<strong>this</strong>&#8216; pointer. Yeah this little pointer that points to self. Unfortunately, this article won&#8217;t really apply to Java or C# users. Nevertheless, you guys may also wanna read this article to appreciate the kind of things we go through writing C++.</p>
<p>So how is it possible that a &#8216;this&#8217; pointer can lead to a disaster?</p>
<p>Read on&#8230;.<span id="more-858"></span></p>
<h2>Introduction</h2>
<p>Now, we&#8217;re all very familiar with &#8216;this&#8217; pointer, so this article is likely to be short. Yes? Well, I&#8217;ll try to until my explanation gets way too long.</p>
<p>As we know, in C++, some of us if not most of us use a <em><strong>smart pointer container</strong></em> of some implementation, for example boost&#8217;s <em>shared_ptr&lt;T&gt;<strong>. </strong></em>In StridesLib, we use <em>cSmartPtr&lt;T&gt;</em> which is similar to the boost&#8217; variant with some additional important features.</p>
<p>We will not go into that now.</p>
<p>Technically, we know that <strong><em>shared_ptr&lt;T&gt;</em></strong> is always to be declared as a local attribute or a composite attribute <em>(I used to use the word &#8217;stack variable&#8217; because if the object is instantiated on the stack ,this whole object will be on the stack as well).</em></p>
<p>We only use a pointer of a pointer container for <strong>double pointer </strong>operations.</p>
<p>But in any case, here&#8217;re a few ways you can use smart pointer containers. I&#8217;m just going to promote <em>cSmartPtr&lt;T&gt; </em>a little here.</p>
<pre>cSmartPtr&lt; cVector4 &gt; vectorPtr = new cVector4(1,2,3); //to instantiate
cSmartPtr&lt; cVector4&gt; v2 = vectorPtr; //to initialize with and share
cSmartPtr&lt; cVector4&gt; v3; //to declare an empty null pointer container
v3 = v2; //to assign with and share
v3-&gt;x = 2.0f; //dereference pointer and access a member</pre>
<h2>Smart Pointer Containers are not true pointers!</h2>
<p>That&#8217;s right. As you can see in the examples above, all 3 pointer containers, <strong>vectorPtr</strong>, <strong>v2 </strong>and <strong>v3</strong> are all local instances <em>(aka stack instances)</em>.</p>
<p>If that&#8217;s the case, how can it be instantiated with a new pointer? Normally, this isn&#8217;t allowed by the compiler does it? Yes!</p>
<p>In that case, what&#8217;s the magic involved here?</p>
<p>Answer&#8230;. <strong>the big 3</strong>!!</p>
<p>Surprise, surprise! How can the big 3 be involved here? Well, basically only 2 of the 3 bigs are used as well as <strong>other operator overrides</strong>.</p>
<p>What are the bigs used here?</p>
<p>1) Copy Constructor<br />
2) Canonical Copy Assignment Operator</p>
<p>What are the others used?</p>
<p>3) Parameterized Constructor (with a T*)<br />
4) operator = (T* )<br />
5) operator == (T* )<br />
6) operator != (T *)<br />
7) operator ! ()<br />
 <img src='http://www.stridesdev.org/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> operator * even</p>
<p>There&#8217;re more but I can&#8217;t afford to explain every single one of them. Basically, when <strong>T</strong> is used, the rest of the problems are dealt with by the compiler. As you can see in the set of overrides, it allows the smart pointer container to implicitly take in a <strong>true pointer</strong> so much so that it looks hidden from the user.</p>
<p>While this is a good feature overall. It sometimes can hide dangers that might stump even the most experienced C++ programmer for a moment.</p>
<p>Now, let&#8217;s just realise that <strong><em>cSmartPtr&lt; cVector4 &gt; vectorPtr</em></strong>; is <strong>not a true pointer.</strong></p>
<p>A true pointer in this case would be <em><strong>cVector4* vectorPtr;</strong> instead.</em></p>
<h2>When disaster strikes&#8230;</h2>
<p>Here comes the ugly part.</p>
<p>Remember that a smart pointer container can take in a true pointer implicitly?</p>
<p>Here&#8217;s the catch - a <strong>this</strong> pointer is a <strong>true pointer</strong>, a smart pointer container is <strong>not a true pointer</strong>. Let&#8217;s take a look at this example:</p>
<pre>class A {
    private:
        B bObj;
    public:
        A();
};

A::A()
{
    bObj(this); //this pointer is guaranteed to be valid at this point
}

//in classB.h

//forward declaration
class A;</pre>
<pre>class B {
    public:
        B(cSmartPtr&lt;A&gt; parmPtr);
};

//so happens when I instantiate an object of type A?
cSmartPtr&lt; A &gt; aObj = new A();

//1) aObj ctor called, instantiates composite object bObj with (this) pointer
//2) this pointer is interpreted by B's ctor implicitly and is initialized as a cSmartPtr&lt;A&gt; parmPtr instead</pre>
<p>Therefore, at this juncture, there&#8217;re <strong>two smart pointer containers </strong>with different context pointing at the same pointer. Here&#8217;s how it looks like: (let&#8217;s say new A() returns a 0&#215;00001FFF)</p>
<p>aObj &#8212;-&gt; 0&#215;00001FFF , ref count = 1<br />
parmPtr &#8212;-&gt; 0&#215;00001FFF, ref count = 1</p>
<p>As you can see, there&#8217;s absolutely no communication between <strong>aObj </strong>and <strong>parmPtr</strong>. So if anyone of them sets themselves to null, thus reducing the reference count to 0, <em><strong>0&#215;00001FFF</strong></em> will be deleted with size of A. Thus the situation will be:</p>
<p>aObj &#8212;-&gt; 0&#215;00000000 , ref count = 0<br />
parmPtr &#8212;-&gt; 0&#215;00001FFF, ref count = 1 //parmPtr is now pointing to a <em><strong>dangling pointer!</strong></em></p>
<p>Can parmPtr escape?</p>
<p>Well, let&#8217;s see.<br />
1) Dereference -&gt; <strong>Crash</strong> <strong>due to dangling pointer</strong><br />
2) Check against null -&gt; <strong>Return incorrect results<br />
</strong>3) Set to null -&gt; <strong>Crash since parmPtr will attempt to delete a pointer that has already been deleted<br />
</strong>4) Pass it onto another container -&gt; <strong>Won&#8217;t crash immediately, but the consequence merely delays the inevitable from happening since one of the containers will be 0 and the same thing will happen in 3).</strong></p>
<h2>Conclusion</h2>
<p>Therefore, it&#8217;s impossible to recover from such a flop. In this case, the programmer must understand that <strong>this</strong> pointer is not a smart pointer container object. He/she must not take it for granted and pass things in just like that.</p>
<p>However, that being said - the implementation of the smart pointer can play a part as well. That is, storing a unique hash map of <em><strong>memory address</strong></em><strong><em>es</em></strong><em> </em>as the <em>key</em>, the smart pointer container as the <em>object</em>. The smart pointer container will register itself the first time for memory protection. Then subsequent smart pointer containers who are not directly related by context will access this hash map to see if there&#8217;s <em><strong>already such a container</strong></em> that manages this memory address.</p>
<p>If there&#8217;s such a container, then it&#8217;ll retrieve that container and increment its reference count, thus joining up.</p>
<p>This is how it should look like even when the pointer containers are <strong>not</strong>, i repeat, <strong>not </strong>passed around.</p>
<p>aObj &#8212;-&gt; 0&#215;00001FFF , ref count = 2<br />
parmPtr &#8212;-&gt; 0&#215;00001FFF, ref count = 2</p>
<p>The problem is - the cost of using a hash map can be expensive. Thus leading to an increased cost of using smart pointer containers afterall.</p>
<p>Bottomline is, programmers need to know their pointer basics, whether they use smart pointer containers or not. They can&#8217;t depend on these containers entirely without arming themselves with the right knowledge. Otherwise, if a disaster of such a kind strikes, nobody can save you.</p>
<p>Not even testing tools.</p>
<p>Hope that this helps! Have a great weekend ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/06/this-pointer-disaster/feed/</wfw:commentRss>
	
		<series:name><![CDATA[Programming Disaster Series]]></series:name>
	</item>
		<item>
		<title>Debugging Disasters</title>
		<link>http://www.stridesdev.org/2010/06/debugging-disasters/</link>
		<comments>http://www.stridesdev.org/2010/06/debugging-disasters/#comments</comments>
		<pubDate>Tue, 22 Jun 2010 03:09:31 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=845</guid>
		<description><![CDATA[This entry is part 2 of 4 in the series Programming Disaster SeriesHi all,
Here&#8217;s another article regarding software development disasters. However, do note that this is a fictitious story that contains certain fragments of events that are based on my own experience. I&#8217;m just using a single story to string them up. So, here it [...]]]></description>
			<content:encoded><![CDATA[<div class="seriesmeta">This entry is part 2 of 4 in the series <a href="http://www.stridesdev.org/series/programming-disaster-series/" title="series-30">Programming Disaster Series</a></div><p>Hi all,</p>
<p>Here&#8217;s another article regarding software development disasters. However, do note that this is a <em>fictitious story</em> that contains certain fragments of events that are based on my own experience. I&#8217;m just using a single story to string them up. So, here it goes:</p>
<p>A team of developers worked on a software for 12 months already. So far, there hasn&#8217;t been any issues in terms of functionalities. Everything was proceeding smoothly.</p>
<p>One day, a new user joined the team to help test for exceptional conditions. That&#8217;s where the flight to heaven fell from the sky, hit a shit mold and starts to roll into the hot depths of hell.</p>
<p>What happened? Read on&#8230;<span id="more-845"></span></p>
<h2>Introduction</h2>
<p>Basically, there&#8217;s nothing much to introduce here. Most of the introduction has already been done above. But allow me to set the stage instead for this whole mess.</p>
<p>First of all, the developers are not very experienced. They have approximately 1-3 years experience in C++ development and their project manager is purely a task and requirements management person.</p>
<p>There&#8217;s a technical leader who has around 4 years C++ experience. Their code base is approximately 400,000 lines of codes so far.</p>
<p>So what exactly happened?</p>
<h2>13th Month - Unlucky or just a plain number?</h2>
<p>On the 13th month of the project, a new young but experience user-cum-tester joined the team. As expected, his tasks were to test the project with existing requirements and come up with test plans that are exceptional in behavior to the system.</p>
<p>He&#8217;d then test the system and submit a report to the manager who will then reassign new tasks based on the report.</p>
<p>The first few days was really honeymoon. The tester heaped tons of praises on the work done so far to encourage the team. Everyone was energized and motivated.</p>
<p>But problems start to appear right after the 2nd week.</p>
<p>In certain exceptional cases, the system could not be recovered. In fact, in extreme scenarios, the team had to shut down the server and restart the machine literally.</p>
<p>This came as a big blow to the team since they were on such a smooth sailing progress since last year.</p>
<p>The developers began to rage a war against the new tester by begin very difficult to deal with. They soon question the tester&#8217;s intentions in the company and even accused the tester of sabotaging the project for other competitors.</p>
<p>It was ugly.</p>
<p>In response to that, the project manager ordered an emergency meeting and launched an investigation into the series of crashes caused by the exceptional tests.</p>
<h2>Debugger Faulty?</h2>
<p>As usual, the developers stepped into the codes, they could even identify where the point of the crash occurred. But they can&#8217;t make any sense out of it. Basically, the code look something like this:</p>
<pre>void Bank::UpdateStatus(int newStatus)
{
    m_iCurrentStatus = newStatus; // CRASH here.
}</pre>
<p>It looked as though as the debugger was faulty here. But it can&#8217;t be. They&#8217;re using Visual Studio 2005 to begin with and we know that it&#8217;s a stable and dependable.</p>
<p>Apparently, they have a clue.</p>
<p>The memory address of m_iCurrentStatus looked dubious. The address reads something like <strong>0xCCCCCCDF . </strong>But this alone doesn&#8217;t tell much of why the address was allocated this way.</p>
<h2>Naming disaster</h2>
<p>Another thing noted by the tester is that - whenever he encountered a compilation error in a sea of compiler warnings and template warnings, it&#8217;s almost impossible to look for THE compilation errors.</p>
<p>Usually, in Visual Studio, it&#8217;s easy to search for compiler errors by typing <strong>&#8220;error&#8221;</strong> in the search pop-up.</p>
<p>However, for this team, they apparently named classes with the word <strong>error</strong> as part of the name. For example:</p>
<pre>cBankingErrorException
cAccountErrorException
cErrorReport
cErrorStatus</pre>
<p>What the hell?!! For certain reasons, certain names like warning or errors should <strong>never</strong> be used as part of name of a class. This certainly leads to more work when debugging or figuring out syntax errors.</p>
<p>I mean, take a look at this. You have like 20,000 lines of warning and stuffs like that during a build and there&#8217;re like only 5 to 6 compiler errors. The compiler says, 10222 warnings 5 errors.</p>
<p>So what&#8217;s next? Look for the syntax errors right? NO.</p>
<p>You can&#8217;t because the freaking CLASSes are NAMED as errors. So now you&#8217;ll have to filter through like 2000 instances of <strong>errors</strong> in order to find that few compilation errors.</p>
<p>Worse if it&#8217;s spread evenly apart. Good luck finding them.</p>
<p><em>Note: Don&#8217;t assume that everybody&#8217;s using Visual Studio 2003 and above ok - errors don&#8217;t just pop up like that.</em></p>
<h2>Mysterious System Slowdown</h2>
<p>The system was actually ok when the standard test plans were performed. There were no glitches, bugs or crashes.</p>
<p>However, when the exceptional test set came into play, the whole system began to slow down after 2-3 days of continuous operation.</p>
<p>The so-called exceptional tests that caused the slowdown are nothing but creating bank accounts.</p>
<h2>Cause of Problems</h2>
<p>Now I&#8217;m sure you guys want to know what caused all these problems right?</p>
<p>Let&#8217;s go through them 1 by 1.</p>
<p><strong>1) Debugger Faulty?</strong></p>
<p>The debugger isn&#8217;t faulty. Neither is the address faulty.</p>
<p>The code <strong>is behaving correctly</strong>. So what&#8217;s wrong anyway? First of all, we need to understand that there&#8217;re 4 types of memory in C++. See this <a href="http://www.stridesdev.org/2010/04/memory-management-in-totality/">the memory management in totality article</a> for more information.</p>
<p>So, a few things are known after compilation. One of which is the <strong>code </strong>memory. The code memory stores a single undisputed and unique copy of your compiled source codes in it. This applies only to an application by itself - additional DLLs have their own respective code memory.</p>
<p>We&#8217;ve now established that the <strong>code itself is perfectly </strong>ok.</p>
<p>Next, let&#8217;s establish the validity of  <em>m_iCurrentStatus</em> . Based on the coding standards, it means that it&#8217;s a <strong>member attribute, type: native integer. </strong>The thing you must know about classes is, a member attribute is actually <strong>an address offset in the </strong>class.</p>
<p>And since everybody has an address of its own, let&#8217;s assume that the address of the object is <strong>0&#215;1234cccc.</strong> Based on the <strong>struct alignment of 8 bytes default</strong>, each attribute is spaced out at 8 bytes distance.</p>
<p>Therefore even if you have 10 <em>shorts</em>, it&#8217;ll still take up <strong>80 bytes</strong>.</p>
<p>So, when an member attribute is accessed, the formula is bascially:</p>
<p><strong><em>base address + offset</em></strong></p>
<p>Therefore if the base address is faulty in the first place, ie, <strong>wild</strong> or <strong>dangling, </strong>the CRT will <strong>not</strong> be able to tell unless it&#8217;s a null pointer which is <strong>zero</strong> in this case. Since it&#8217;s not able to tell, it&#8217;ll just blindly execute the line with the code, base address and offset.</p>
<p>Thus causing this weird error to occur.</p>
<p><strong>2) Naming Disaster</strong></p>
<p>By naming classes with <em><strong>error </strong></em>as part of the class name suggests a possible defect in the design itself. How could a class be created simply to represent an error?</p>
<p>While naming the class with <em><strong>error</strong></em><strong> </strong>as part of it may have its merits, it&#8217;ll certainly cause a lot of problems should the build breaks. People who&#8217;ve used VC6 before should understand. In the later versions of Visual Studio, errors are presented in a different window apart from the console, allowing developers to quickly zoom into it.</p>
<p>However, for people who&#8217;re using make files, build utilities and the old VC6, good luck to you finding the compiler error. Even if you can, it&#8217;ll not be easy and it slows you down for nothing.</p>
<p><strong>3) Mysterious System Slowdown</strong></p>
<p>If your system doesn&#8217;t crash within the same day even though there&#8217;s an obvious <strong>design-based leak </strong>going on there.</p>
<p>Even if your system doesn&#8217;t crash but if it slows down dramatically, then either <strong>design-based leak </strong>or <strong>memory hogging</strong> is responsible.</p>
<p>For more information - read this <a href="http://www.stridesdev.org/2010/03/differences-between-a-design-based-leak-and-memory-hogging/">article</a> for memory hogging, and these two articles below for design-based leaks.</p>
<p><a href="http://www.stridesdev.org/2009/12/design-based-leaks-continued/">Design-based leaks (continued)</a><br />
<a href="http://www.stridesdev.org/2009/04/legal-leaks/">Legal Leaks</a></p>
<h2>Conclusion</h2>
<p>Finally, we&#8217;ve arrived at the conclusion - it has been a long long post I believe. I hope that these lessons will help people realise potential problems early during development even though the story is fictitious, it&#8217;s based on true experiences put together to form a scenario.</p>
<p>Do read up the references I&#8217;ve linked up here. It&#8217;ll help as well.</p>
<p>Have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/06/debugging-disasters/feed/</wfw:commentRss>
	
		<series:name><![CDATA[Programming Disaster Series]]></series:name>
	</item>
		<item>
		<title>Musician wannabes that pisses me off to no end</title>
		<link>http://www.stridesdev.org/2010/06/musician-wannabes-that-pisses-me-off-to-no-end/</link>
		<comments>http://www.stridesdev.org/2010/06/musician-wannabes-that-pisses-me-off-to-no-end/#comments</comments>
		<pubDate>Tue, 15 Jun 2010 01:35:56 +0000</pubDate>
		<dc:creator>Admin</dc:creator>
		
		<category><![CDATA[Weekly Tuesday Dose of goodness]]></category>

		<guid isPermaLink="false">http://www.stridesdev.org/?p=742</guid>
		<description><![CDATA[Hi all,
This week I&#8217;m going to talk about my experiences based on my other talents. Technical people can still read this post and perhaps gain some insights for your own benefit.
Basically, I&#8217;ve met a group of so-called musicians or guitarist during a gathering in which I was invited. In that group there was one or [...]]]></description>
			<content:encoded><![CDATA[<p>Hi all,</p>
<p>This week I&#8217;m going to talk about my experiences based on my other talents. Technical people can still read this post and perhaps gain some insights for your own benefit.</p>
<p>Basically, I&#8217;ve met a group of so-called musicians or guitarist during a gathering in which I was invited. In that group there was one or two that were &#8220;certified&#8221; as a performer.</p>
<p>By right, as a musician myself, I should be happy to exchange what I know with what they know. But what happened thereafter pissed me off.</p>
<p>How so? Read on&#8230;.<span id="more-742"></span></p>
<h2>Introduction</h2>
<p>Yeah, some introduction about myself. I&#8217;m a pop pianist at core even though I play other instruments and genres from music such as Jazz, Bossa Nova, etc. I also play an er-hu and just started on a violin.</p>
<p>My main skills as a pianist isn&#8217;t with how I play or sight reading. Rather, it&#8217;s my ability to play what I hear. They may not always be accurate but it&#8217;s never too far off.</p>
<h2>Incident(s)</h2>
<p>As mentioned at the beginning, it was a gathering. Some of those guys actually brought their guitars along. My friend was actually a beginner of playing the guitar at that time. So, they were teaching him how to play a song based on the way it&#8217;s being played rather than understanding <strong>why</strong> the song was being played that way.</p>
<p>In short, these guys don&#8217;t know what they&#8217;re playing. They&#8217;re parrots, mimickers, imitators or playback machines at best.</p>
<p>I&#8217;m actually quite ok with it since everybody has their standards and talents which shouldn&#8217;t be judged against what I already knew.</p>
<p>The problem was, when I tried to explain to my friend what on earth he&#8217;s actually playing, one of those guys interrupted us and told me off. He said - &#8220;You shouldn&#8217;t teach him what&#8217;s a chord, you&#8217;ll only confuse him.&#8221;</p>
<p>I was like, (in my mind scolding the grandfather of all vulgarities) so damned pissed off. Already, the way he taught my friend was <strong>WRONG</strong> and he was there trying to be Mr Right all the way.</p>
<p>Anyway, much later I had a good talk with my friend. He too agreed that he was confused <strong>by them </strong>rather than enriched.</p>
<p>That guy moreover added : &#8220;To qualify as a rock guitarist, you need to master 5 metallica pieces&#8230;&#8221;</p>
<p>That&#8217;s the stupidest thing I&#8217;ve ever heard. Does he really think that mastering any 5 pieces makes qualifies him to be a great guitarist?</p>
<p>The same goes for piano or all other instruments! The mastery of music lies in its essence not in its instrument! An instrument is a conduit for musicians to express their emotions through the notes they play, and is not a <strong>copywriter</strong>! It&#8217;s an insult to the instrument!</p>
<p>It&#8217;s akin saying: &#8220;I need to make 5 chairs in order to be a master chair carpenter!&#8221;</p>
<p>That&#8217;s a total load of bullshit!</p>
<p>We all know that there&#8217;s more to being a master than just being a poser or recital expert. Having certified to be able to perform in the public doesn&#8217;t mean a thing if the performer doesn&#8217;t know what the hell he/she is performing!</p>
<p>I&#8217;ve seen in so many cases where a self-proclaimed <strong>maestro</strong> (ie, an accomplished musician) playing pop songs in the public.</p>
<p>You know what? They suck. They insult the song and misinterpret the song entirely by playing the classical way. Their additional cues only make matters worse.</p>
<p>It&#8217;s this kind of people that makes <strong>pop pianists</strong> look like restaurant performers.</p>
<p>Take for example, if I get an Electric Guitar to play &#8220;My Heart Will Go On&#8221; how would it sound?</p>
<p>Or if I play &#8220;Song 2&#8243; on a piano using classical methods, how would it sound?</p>
<h2>How should it be?</h2>
<p>Music is a form of description. Playing it, is a form of expressing this description (story or scenario) with a perspective.</p>
<p>Its perspective should align as closely as possible to the rationale of the piece. Why is this song composed? Who is it for? Which place does it has its moods set upon?</p>
<p>Perhaps, musicians or wannabes should ask themselves the most important question. Why are they playing this song in the first place?</p>
<p>Of course, to be fair, practice is a common answer. Practice would mean practising the song in its technicalities. Ie, which chord to play, how to play it correct. That&#8217;s important.</p>
<p>But a practice session doesn&#8217;t mean that it&#8217;s the right perspective for the song.</p>
<p>If one takes on a training perspective as THE perspective for playing a song, then it&#8217;ll be a pure technical recital of the song without any real expressions or feelings.</p>
<p>In such a case, ordinary people would be able to tell though other musicians may be captivated by the technical-side of things.</p>
<h2>Conclusion</h2>
<p>In conclusion, I&#8217;ll just like to make a few points:</p>
<p>1) Don&#8217;t be an asshole. Just because you don&#8217;t know something doesn&#8217;t mean the others shouldn&#8217;t know as well.<br />
2) If you&#8217;re confused, then you either suck or seek elaborations. It doesn&#8217;t mean the others will be confused.<br />
3) Always know what you&#8217;re playing. Chords represent a part of progression in music which orchestrates the whole song. A chord itself is made up of notes that are usually part of the song&#8217;s stream (major/minor). This allows the song to be disciplined and classified properly, following the rules.<br />
4) Music is not just about playing, it&#8217;s about expressions as well. There&#8217;re many types of expressions, one of which being the expression of understanding (which is attained by understanding the song itself).<br />
5) Knowing an instrument is good, but knowing how to use it well is better.</p>
<p>It certainly applies to software development if you ask me. Just replace &#8220;play&#8221; with &#8220;code&#8221;, &#8220;song&#8221; with &#8220;application&#8221; and so on and you&#8217;ll get the drift.</p>
<p>While music itself is an expression, it&#8217;s also a &#8220;formula&#8221; which can be calculated with musical rules and chord rules. I&#8217;ll talk about this next time.</p>
<p>Anyway, have a great week ahead!</p>
<p>Signing off,<br />
Jeremy</p>
]]></content:encoded>
			<wfw:commentRss>http://www.stridesdev.org/2010/06/musician-wannabes-that-pisses-me-off-to-no-end/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
