<?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>Nothing and More &#187; programming</title>
	<atom:link href="http://www.xmonk.org/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.xmonk.org</link>
	<description>Not much, not less</description>
	<lastBuildDate>Fri, 06 Mar 2009 00:18:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Design as the silver bullet (my take)</title>
		<link>http://www.xmonk.org/2008/06/12/design-as-the-silver-bullet-my-take/</link>
		<comments>http://www.xmonk.org/2008/06/12/design-as-the-silver-bullet-my-take/#comments</comments>
		<pubDate>Thu, 12 Jun 2008 13:52:25 +0000</pubDate>
		<dc:creator>xmonk</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[software design]]></category>

		<guid isPermaLink="false">http://www.xmonk.org/?p=56</guid>
		<description><![CDATA[While I agree with most of what  Elvis say. There is a need to look deeper, there are open ends: 1.) How do you determine individuals are &#8220;qualified and prepared&#8221;? 2.) Assuming you can consistently solve point 1, if the individual does not care, is not motivated, then all preparedness and qualifications, and even professionalism [...]]]></description>
			<content:encoded><![CDATA[<p>While I agree with most of what  <a title="Elvis - Design as the silver bullet" href="http://www.elvismontero.com/2008/06/11/design-as-the-silver-bullet/" target="_blank">Elvis</a> say. There is a need to look deeper, there are open ends:</p>
<p>1.) How do you determine individuals are &#8220;qualified and prepared&#8221;?</p>
<p>2.) Assuming you can consistently solve point 1, if the individual does not care, is not motivated, then all preparedness and qualifications, and even professionalism wont help.</p>
<p>3.) Assuming all the above are covered, there still is the human condition. Meaning we are creatures of interpretations, and this adds to the complexity.</p>
<p>I think design is important, but seldom does the designers have the full picture of what&#8217;s being designed. We want to approach software design, as an architect approaches the design of a building. The problem is that the best architects, do an extreme amount of research before starting the design process. Things like:</p>
<ul>
<li> Location.</li>
<li>Elevation</li>
<li>Soil</li>
<li>Dispersion,</li>
<li>Region</li>
<li>Are earthquakes common place in this region?</li>
<li>Are hurricanes or tornadoes common place here?</li>
</ul>
<p>Among many other things they consider before putting pencil or pen to paper, or going into CAD. When the above is decided they work out the best materials for the location, and design they envision. They then analyze costs and what not, make compromises and arrangements to mitigate costs.</p>
<p>After all this they start what we (developers/software engineers) call the design process, and that&#8217;s making drawings or mock ups, showing it to the client, changing to the tastes/needs of the client, when everything is agreed upon, then the plans are made and drawn, there may be a need to adjust the budget here. Then we have peer reviews in the form of all the revisions, etc.. needed to get approval for construction.</p>
<p>So this is a very time consuming process, and one that most Software designers don&#8217;t even bother with. Most don&#8217;t know or care where the application is going to run, or an idea of the resources need for said application, or whether the application really benefits from a heavily threaded system, or if going that route may be even more detrimental performance wise. They just don&#8217;t know or care. I&#8217;m sure there are numerous exceptions to this, and there are quite capable designers that take all the above in consideration, but I believe they are the minority.</p>
<p>Some of you may ask: So, If I want to design an application, I should take into consideration and know about, the Operating System, the Web server, whether threads may help or make it worst, etc?</p>
<p>My answer is a conclusive yes! You should research and know about all of this to make inform decision on what is needed and why. For example: IIS and Apache are completely different servers, and have different requirements maintenance overheads, performance tweaks, etc.. Same goes for the DB, and how you deal with replication, etc..</p>
<p>If you do all the above, it&#8217;s easier for the DB engineers to prepare and optimize querys, etc.. for the application, because there is a clear picture, of what is expected of the DB. Same goes for the other parts of the equation.</p>
<p>So yes, properly designing software is hard, but really what that&#8217;s worth having or building isn&#8217;t hard? The problem in my view is not the silver bullet (I personally don&#8217;t think there is one) but I do think the approach described in <a title="Worse is Better" href="http://www.dreamsongs.com/WorseIsBetter.html" target="_blank">worst is better</a> is better than the approach that&#8217;s being nurtured in the enterprise, working but needs occasional reboots it&#8217;s great to good. Everything below that is good to ok.</p>
<p>This is a very interesting topic, and complex topic, hence all the papers and research around it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.xmonk.org/2008/06/12/design-as-the-silver-bullet-my-take/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C do&#8217;s and don&#8217;ts (mostly don&#8217;ts)</title>
		<link>http://www.xmonk.org/2008/04/28/c-dos-and-donts-mostly-donts/</link>
		<comments>http://www.xmonk.org/2008/04/28/c-dos-and-donts-mostly-donts/#comments</comments>
		<pubDate>Mon, 28 Apr 2008 17:31:36 +0000</pubDate>
		<dc:creator>xmonk</dc:creator>
				<category><![CDATA[programming]]></category>
		<category><![CDATA[technology]]></category>
		<category><![CDATA[thoughts]]></category>
		<category><![CDATA[C]]></category>

		<guid isPermaLink="false">http://www.xmonk.org/2008/04/28/c-dos-and-donts-mostly-donts/</guid>
		<description><![CDATA[This past Friday, I received a surprising email, from a former co-worker, it&#8217;s been a year or more since I left that particular company (wont name, names). We were in different departments, but were by fate put on the same project. This particular project was (is) of the utmost importance for that company, and in [...]]]></description>
			<content:encoded><![CDATA[<p>This past Friday, I received a surprising email, from a former co-worker, it&#8217;s been a year or more since I left that particular company (wont name, names). We were in different departments, but were by fate put on the same project.</p>
<p>This particular project was (is) of the utmost importance for that company, and in his development team he&#8217;s the only one that was working on this specific application (a server). To the suffering of all the involved in his department this particular piece of code had to be written in C, and there was just no way around it for several technical and design reasons that are not important at this moment.</p>
<p>I was in charge of testing his application (not unit testing), I had to performance test his application, to do this, one needs to know the architecture, and all that the developer needs to know to develop it, and more. I don&#8217;t have to tell you that this was a painful experience that mostly drove me crazy.</p>
<p>Just seeing who the email was from and subject surprised me to no end. As it was, they were having some issues, more to the point he was having some issues &#8211;as we were friendly, which basically means he was the only person I didn&#8217;t tell to f..k off. He asked for my number which I gave to him, and a few minutes later, his boss (whom I would have gladly frag&#8217;d) was on the line, telling me, how my NDA still applies and what not&#8230; at this point I just calmly stated you called me. What do you want?</p>
<p>The server has been having issues, and they have to reboot it every 72 hours or so&#8230; at this moment they have put the old code base (which was the one I worked with) back in production, but need the new functionality ASAP, and basically wanted me to check it out. Now, I was curious, I have that problem, I&#8217;m too curious so I said yes, sure.</p>
<p>They sent me the vmstat of the last 72 hours of the server, along with several log files, and after a cursory glance, it was obvious there were memory leaks. This they already knew (they are not dumb) but couldn&#8217;t find the spots where they were happening, and it&#8217;s here where the story gets interesting and where we might learn a few things, so this doesn&#8217;t happen to you.</p>
<p>First a disclaimer, this particular developer is quite good, and diligent. Also I&#8217;m not as good or diligent, and I don&#8217;t know much more than anybody else, but I have had the grand advantage of working with people that do know more than me, and that are willing to show me, so I learn and get better, this is my way of giving back, and saying thanks to all of them.</p>
<p><strong>Malloc</strong></p>
<p>The first issue when I saw the code, was the scheme he was using for memory allocation. I believe that with regards to memory allocation, if there is a failure allocating memory, aborting right then and there is the right thing to do, of course there are exceptions, but for most situations this is ideal, a well done policy, is also something to look into, for this type of scenarios.</p>
<p>His scheme was like this:</p>
<ul>
<li>Allocate a good chunk of memory, that will be shared among threads.</li>
<li> Each thread allocates the memory needed to do it&#8217;s operation, write the results to the shared chunk, and clean after itself.</li>
</ul>
<p>I wouldn&#8217;t do it this way, but this scheme works as long as everyone plays nice. As it happens all threads are playing nice, the problem lies with the allocation done internally by the threads.</p>
<p>He is over writing the pointer that malloc returns, and while he is freeing it, the portion returned by malloc is never free(), this goes on for all the threads.</p>
<p>Some of you might be thinking What? Over writing? How, why? Well the thing is that he didn&#8217;t noticed or know he was doing it, which is not good, but it&#8217;s a common mistake with C programmers (newbies, and not so newbies).</p>
<p>Another nice little side effect, is that every time, a thread wrote to the shared memory chunk, this was sent out to the appropriate interfacing systems, upon a successful completion, the memory chunk was de-allocated and the re-allocated, meaning he free() and then malloc() again and again. Which also brought the nifty problem, that if a thread was waiting in place to write to the chunk, the reference it had to the chunk had gone bye bye, so to avoid a segmentation fault, he worked around this problem in a very creatively unnecessary way (that I would rather soon forget).</p>
<p>Don&#8217;ts:</p>
<ul>
<li>Do not over write (change where it points) the pointer returned by malloc(), don&#8217;t do it ever.</li>
<li>Wrap your malloc() call in a way that it checks (once is enough) no out of memory errors, if there is exit immediately.</li>
<li>Don&#8217;t blindly accept that the arguments to your methods are what you are expecting, or valid data.</li>
<li>When returning an error state from a function, for God&#8217;s sake, don&#8217;t abuse NULL!</li>
</ul>
<p>Do&#8217;s:</p>
<ul>
<li> Learn how to use lint.</li>
<li> Use lint often.</li>
<li> Run lint, after every compilation, add it to the build.</li>
<li> Check and double check all of lint&#8217;s warning and errors, fix them.</li>
<li> Run lint again after fixing the errors.</li>
<li> Read your code, go thru it in your head, or which ever way you prefer.</li>
</ul>
<p>I&#8217;m in agreement with <a title="Thomas Ptacek" href="http://www.matasano.com/log/1041/introduced-a-resolution-resolving-the-semantic-quarrel-over-malloc-checking/" target="_blank">Thomas Ptacek</a>. If my friend would&#8217;ve done that, this problem would have surfaced in the pre-production stages, because the system would have crashed earlier, enabling them to find the culprit much sooner.</p>
<p>There are other things that contributed to the problems, but the good news is after an hour of going thru the code, the system is back up, and it&#8217;s been over 72 hours and it hasn&#8217;t crashed, and it&#8217;s memory consumption is minimal as it should&#8217;ve been from the start.</p>
<p><strong>Update:</strong></p>
<p>Forgot to mention I provided them with a nice little Ring buffer implementation that captures the steps/states of the threads, from beginning to end, in case of an error, it dumps it&#8217;s content to disk.</p>
<p>That way they will be able to pin point more or less what triggered the crash, where in the code this happen, and the time this happened.</p>
<p>For more info on ring buffers, check out this links:</p>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Circular_buffer">http://en.wikipedia.org/wiki/Circular_buffer</a></li>
<li><a href="# http://www.ibm.com/developerworks/aix/library/au-buffer/index.html">http://www.ibm.com/developerworks/aix/library/au-buffer/index.html</a></li>
<li><a href="# http://visibleworkings.com/trace/Documentation/ring-buffer.pdf">http://visibleworkings.com/trace/Documentation/ring-buffer.pdf</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.xmonk.org/2008/04/28/c-dos-and-donts-mostly-donts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
