<?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>Vincent Gable's Blog &#187; Bug Bite</title>
	<atom:link href="http://vgable.com/blog/category/bug-bite/feed/" rel="self" type="application/rss+xml" />
	<link>http://vgable.com/blog</link>
	<description>my weblog.</description>
	<lastBuildDate>Tue, 29 Nov 2011 22:20:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>The Most Useful Objective-C Code I&#8217;ve Ever Written</title>
		<link>http://vgable.com/blog/2010/08/19/the-most-useful-objective-c-code-ive-ever-written/</link>
		<comments>http://vgable.com/blog/2010/08/19/the-most-useful-objective-c-code-ive-ever-written/#comments</comments>
		<pubDate>Thu, 19 Aug 2010 10:01:01 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[LOG_EXPR]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[NSLog]]></category>
		<category><![CDATA[Preprocessor]]></category>
		<category><![CDATA[printf]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=670</guid>
		<description><![CDATA[Actually, it&#8217;s the most useful code I&#8217;ve extended; credit for the core idea goes to Dave Dribin with his Handy NSString Conversion Macro. LOG_EXPR(x) is a macro that prints out x, no matter what type x is, without having to worry about format-strings (and related crashes from eg. printing a C-string the same way as [...]]]></description>
			<content:encoded><![CDATA[<p>Actually, it&#8217;s the most useful code I&#8217;ve <em>extended</em>; credit for the core idea goes to <a href="http://www.dribin.org/dave/">Dave Dribin</a> with his <a href="http://www.dribin.org/dave/blog/archives/2008/09/22/convert_to_nsstring/"><cite>Handy NSString Conversion Macro</cite></a>.</p>
<p><strong><code><a href="">LOG_EXPR</a>(x)</code> is a macro that prints out <code>x</code>, no matter what type <code>x</code> is</strong>, without having to worry about format-strings (and related crashes from eg. printing a C-string the same way as an <code>NSString</code>). It works on Mac OS X and iOS. Here are some examples,</p>
<p><code>LOG_EXPR(self.window.screen);</code></p>
<blockquote><p>self.window.screen = &lt;UIScreen: 0x6d20780; bounds = {{0, 0}, {320, 480}}; mode = &lt;UIScreenMode: 0x6d20c50; size = 320.000000 x 480.000000&gt;&gt;
</p></blockquote>
<p><code>LOG_EXPR(self.tabBarController.viewControllers);</code></p>
<blockquote><p>self.tabBarController.viewControllers = (<br />
    &#8220;&lt;UINavigationController: 0xcd02e00&gt;&#8221;,<br />
    &#8220;&lt;SavingsViewController: 0xcd05c40&gt;&#8221;,<br />
    &#8220;&lt;SettingsViewController: 0xcd05e90&gt;&#8221;<br />
)</p></blockquote>
<p>Pretty straightforward, really. The biggest convenience so far is having the expression printed out, so you don&#8217;t have to write out a name redundantly in the format string (eg. <code> NSLog(@"actionURL = %@", actionURL)</code>). But <code>LOG_EXPR</code> really shows it&#8217;s worth when you start using scalar or <code>struct</code> expressions:</p>
<p><code>LOG_EXPR(self.window.windowLevel);</code></p>
<blockquote><p>self.window.windowLevel = 0.000000</p></blockquote>
<p><code>LOG_EXPR(self.window.frame.size);</code></p>
<blockquote><p>self.window.frame.size = {320, 480}</p></blockquote>
<p>Yes, there are expressions that won&#8217;t work, but they&#8217;re pretty rare for me. I use <code>LOG_EXPR</code> every day. Several times. It&#8217;s not quite as good as having <a href="http://vgable.com/blog/2010/06/14/ask-f-script/">a REPL for Cocoa</a>, but it&#8217;s handy.</p>
<p><a href="#Get_LOG_EXPR">Give it a try</a>.</p>
<h3>How It Works</h3>
<p>The problem is how to pick a function or format string to print <code>x</code>, based on the type of <code>x</code>. C++&#8217;s type-based dispatch would be a good fit here, but it&#8217;s verbose (a full function-definition per type) and I wanted to use pure Objective-C if possible. Fortunately, <strong>Objective-C has an <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html"><code>@encode()</code></a>  compiler directive that returns a string describing any type it&#8217;s given.</strong> Unfortunately it works on <em>types</em>, not variables, but with C99 <strong>the <code><a href="http://gcc.gnu.org/onlinedocs/gcc/Typeof.html">typeof()</a></code> compiler directive lets us get the type of any variable</strong>, which we can pass to <code>@encode()</code>.  The final bit of compiler magic is using <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html">stringification (<code>#</code>)</a> to print out the literal string inside <code>LOG_EXPR()</code>&#8216;s parenthesis.</p>
<h3>The Macro, Line By Line</h3>
<div class="code-box">
<pre>
1 #define LOG_EXPR(_X_) do{\
2 	__typeof__(_X_) _Y_ = (_X_);\
3 	const char * _TYPE_CODE_ = @encode(__typeof__(_X_));\
4 	NSString *_STR_ = VTPG_DDToStringFromTypeAndValue(_TYPE_CODE_, &#038;_Y_);\
5 	if(_STR_)\
6 		NSLog(@"%s = %@", #_X_, _STR_);\
7 	else\
8 		NSLog(@"Unknown _TYPE_CODE_: %s for expression %s in function %s, file %s, line %d", _TYPE_CODE_, #_X_, __func__, __FILE__, __LINE__);\
9 }while(0)
</pre>
</div>
<ol>
<li>The first and last lines are a way to put <code>{}</code>&#8216;s around the macro to prevent <a href="http://en.wikipedia.org/wiki/C_preprocessor#Multiple_statements">unintended effects</a>. The <code>do{}while(0);</code> &#8220;loop&#8221; does nothing else.</li>
<li>First evaluate the expression, <code>_X_</code>, given to <code>LOG_EXPR</code> <em>once</em>, and store the result in a <code>_Y_</code>. We need to use <code><a href="http://gcc.gnu.org/onlinedocs/gcc/Typeof.html">typeof()</a></code> (which had to be written <code>__typeof__()</code> to appease some versions of GCC) to figure out the type of <code>_Y_</code>.</li>
<li><code>_TYPE_CODE_</code> is c-string that <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/ObjCRuntimeGuide/Articles/ocrtTypeEncodings.html">describes the type</a> of the expression we want to print out.</li>
<li>Now we have enough information to call a function, <code>VTPG_DDToStringFromTypeAndValue()</code> to convert the expression&#8217;s value to a string. We pass it the <code>_TYPE_CODE_</code> string, and <em>the address of </em> <code>_Y_</code>, which is a pointer, and has a known size. We can&#8217;t pass <code>_Y_</code> directly, because depending on what <code>_X_</code> is, it will have different types and could be of any size.</li>
<li><code>VTPG_DDToStringFromTypeAndValue()</code> returns <code>nil</code> if it can&#8217;t figure out how to convert a value to a string.</li>
<li>Everything went well, print the <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html">stringified</a> expression, <code>#_X_</code>, and  the string representing it&#8217;s value, <code>_STR_</code>.</li>
<li>otherwise…</li>
<li>The expression had a type we can&#8217;t handle, print out a verbose diagnostic message.</li>
<li>See line 1.</li>
</ol>
<h3>The <code>VTPG_DDToStringFromTypeAndValue()</code> Function</h3>
<p>See the source in <a href="http://github.com/VTPG/CommonCode/blob/master/VTPG_Common.m">VTPG_Common.m</a>:</p>
<p><iframe src ="http://github.com/VTPG/CommonCode/blob/master/VTPG_Common.m" width="100%" height="300">(Your browser does not support iframes.)</iframe></p>
<p>It&#8217;s derived from  <a href="http://www.dribin.org/dave/">Dave Dribin</a>&#8216;s function <a href="http://www.dribin.org/dave/blog/archives/2008/09/22/convert_to_nsstring/"> <code>DDToStringFromTypeAndValue()</code></a>, and is pretty straightforward: <code>strcmp()</code> the type-string, and if it matches a known type call a function, or use <code>+[NSString stringWithFormat]:</code>, to turn the value into a string.</p>
<h3>The First Step Twords Fixing Your Macro Problem is Admitting it&#8230;</h3>
<p>So yeah, maybe I went a little wild with macros here…</p>
<p>But it took out some <a href="http://en.wikipedia.org/wiki/Don't_repeat_yourself">WET</a>-ness of the original code, and prevents me from accidentally mixing up types in a long wall of <code>if</code>s, eg.</p>
<div class="code-box">
<pre>
else if (strcmp(typeCode, @encode(NSRect)) == 0)
{
    return NSStringFromRect(*(NSRange *)value);
}
else if (strcmp(typeCode, @encode(NSRange)) == 0)
{
    return NSStringFromRect(*(NSRange *)value);
}
</pre>
</div>
<p>If I were cool, I&#8217;d use <code>NSDictionary</code>s to map from the <code>@encode</code>-string to an appropriate format string or function pointer.  This is conceptually cleaner; less error-prone than using macros; and almost certainly faster. Unfortunately, it gets a little tricky with functions, since I need to deference <code>value</code> into the proper type.</p>
<p>One final note from my testing, I could do away with the <code>strcmp()</code>s, because directly comparing <code>@encode</code> string pointers (eg <code>if(typeCode == @encode(NSString*))</code> works. I don&#8217;t know if it will <em>always</em> work though, so relying on it strikes me as a profoundly Bad Idea. But maybe that bad idea will give someone a good idea.</p>
<h3>Limitations</h3>
<h4>Arrays</h4>
<p>C arrays generally muck things up. Casting to a pointer works around this:</p>
<div class="code-box">
<pre>
char x[14] = "Hello, world!";
//LOG_EXPR(x); //error: invalid initializer
LOG_EXPR((char*)x); //prints fine
</pre>
</div>
<h4><code>__func__</code></h4>
<p>Because it is a <code>static const char []</code>, <code><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2004/n1642.html">__func__</a></code> (and <code>__FUNCTION__</code> or <code>__PRETTY_FUNCTION__</code>) need casting to <code>char*</code> to work with <code>LOG_EXPR</code>. Because logging out a function/method call is something I do frequently, I use the macro:</p>
<div class="code-box">
<pre>
#define LOG_FUNCTION()	NSLog(@"%s", __func__)</pre>
</div>
<h4><code>long double</code> (Leopard and older)</h4>
<p>On older systems, <code>LOG_EXPR</code> won&#8217;t work with a <code>long double</code> value, because <code>@encode(long double)</code> gives the same result as <code>@encode(double)</code>. This is a <a href="http://openradar.appspot.com/6468314">known issue</a> with the runtime. The top-level <code>LOG_EXPR</code> macro could detect a <code>long double</code> with <code>if((sizeof(_X_) == sizeof(long double)) &#038;&#038; (_TYPE_CODE_ == @encode(double)))</code>. But I doubt this will ever be necessary.</p>
<p>I haven&#8217;t actually written any code that uses <code>long double</code>, because I <strong>use <code><a href="http://developer.apple.com/mac/library/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Functions/Reference/reference.html#//apple_ref/doc/uid/20000055-BCIHCEFJ">NSDecimal</a></code>, or another base-10 number format, for situations that require more precision than a <code>double</code>.</strong></p>
<h3>Scaling and Frameworks </h3>
<p>Growing <code>LOG_EXPR</code> to handle <em>every</em> type is a lot of work. I&#8217;ve only added types that I&#8217;ve actually needed to print. This has kept the code manageable, and seems to be working so far.</p>
<p>The biggest problem I have is <strong>how to deal with types that are in frameworks that not every project includes</strong>. Projects that use CoreLocation.framework need to be able to use <code>LOG_EXPR</code> to print out CoreLocation specific <code>struct</code>s, like <code> CLLocationCoordinate2D</code>. But projects that <em>don&#8217;t</em> use CoreLocation.framework don&#8217;t have a definition of the <code>CLLocationCoordinate2D</code> type, so code to convert it to a string won&#8217;t compile. There are two ways I&#8217;ve tried to solve the problem</p>
<h4>Comment-out framework-specific code</h4>
<p>This is pretty self-explanatory, I&#8217;ll fork VTPG_Common.m and un-comment-out code for types that my project needs to print. It works, but it&#8217;s drudgery. Programmers hate that.</p>
<h4>Hardcode type info</h4>
<p>The idea is to hard-code the string that <code>@encode(SomeType)</code> would evaluate to, and then (since we know how <code>SomeType</code> is laid out in memory) use casting and pointer-arithmetic to get at the fields.</p>
<p>For example:</p>
<div class="code-box">
<pre>
//This is a hack to print out CLLocationCoordinate2D, without needing to #import &lt;CoreLocation/CoreLocation.h&gt;
//A CLLocationCoordinate2D is a struct made up of 2 doubles.
//We detect it by hard-coding the result of @encode(CLLocationCoordinate2D).
//We get at the fields by treating it like an array of doubles, which it is identical to in memory.
if(strcmp(typeCode, "{?=dd}")==0)//@encode(CLLocationCoordinate2D)
	return [NSString stringWithFormat:@"{latitude=%g,longitude=%g}",((double*)value)[0],((double*)value)[1]];
</pre>
</div>
<p>This Just Works in a project that includes CoreLocation, and doesn&#8217;t mess up projects that don&#8217;t. Unfortunately it&#8217;s <em>horribly brittle</em>. Any Xcode or system update could break it. It&#8217;s not a tenable fix.</p>
<h3>Areas for Improvement</h3>
<p>If there&#8217;s some type <code>LOG_EXPR</code> can&#8217;t handle that you need, please <a href="http://github.com/VTPG/CommonCode">jump right in and improve it</a>!</p>
<p>When I have time, I plan to write a general parser for <code>@encode()</code>-strings. This will let me print out <em>any</em> <code>struct</code>, which mostly solves the type-defined-in-missing-framework problem, and would let <code>LOG_EXPR</code> Just Work with types from all kinds of POSIX/C libraries.</p>
<h3><a name="Get_LOG_EXPR"></a>Using <code>LOG_EXPR()</code> in Your Project </h3>
<p>Download <a href="http://github.com/VTPG/CommonCode/blob/master/VTPG_Common.m">VTPG_Common.m</a> and <a href="http://github.com/VTPG/CommonCode/blob/master/VTPG_Common.h">VTPG_Common.h</a> from <a href="http://github.com/VTPG/CommonCode">my github repository</a>, and add them to your Xcode project.</p>
<p>Now just add the line <code>#import "VTPG_Common.h"</code> to your prefix file (named <code>&lt;ProjectName&gt;_Prefix.pch</code> by default), after the <code>#ifdef __OBJC__</code>, for example:</p>
<div class="code-box">
<pre>
#ifdef __OBJC__
    #import &lt;Foundation/Foundation.h&gt;
    // maybe other files, depending on project  template...
    #import "VTPG_Common.h"
#endif</pre>
</div>
<p>Now <code>LOG_EXPR()</code> will work everywhere in your project.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/08/19/the-most-useful-objective-c-code-ive-ever-written/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>#define String</title>
		<link>http://vgable.com/blog/2010/07/19/define-string/</link>
		<comments>http://vgable.com/blog/2010/07/19/define-string/#comments</comments>
		<pubDate>Tue, 20 Jul 2010 04:56:19 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Constants]]></category>
		<category><![CDATA[macros]]></category>
		<category><![CDATA[NSString]]></category>
		<category><![CDATA[Programming Style]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=658</guid>
		<description><![CDATA[When I need a string-constant, I #define it, instead of doing the &#8220;right&#8221; thing and using an extern const NSString * variable. UPDATE 2010-07-20 Thanks to Elfred Pagen for pointing out that you should always put () around your macros. Wrong: #define A_STRING @"hello" instead use (), even when you don&#8217;t think you have to: [...]]]></description>
			<content:encoded><![CDATA[<p>When I need a string-constant, I <code>#define</code> it, instead of doing the &#8220;right&#8221; thing and using an <code>extern const NSString *</code> variable.</p>
<p><H3>UPDATE 2010-07-20</H3> Thanks to <a href="http://twitter.com/elfredpagan">Elfred Pagen</a> for pointing out that you should <strong>always put () around your macros</strong>. Wrong: <del><code>#define A_STRING @"hello"</code></del></p>
<p>instead use (), even when you don&#8217;t think you have to:</p>
<p><code>#define A_STRING (@"hello")</code></p>
<p>This prevents <strong>accidental string concatenation</strong>. In C, string-literals separated only by whitespace are implicitly concatenated. It&#8217;s the same with Objective-C string literals.  This feature lets you break long strings up into several lines, so <code>NSString *x = @"A long string!"</code> can be rewritten:</p>
<div class="code-box">
<pre>
NSString *x =
	@"A long"
	@" string!";
</pre>
</div>
<p>Unfortunately, this seldom-used feature can backfire in unexpected ways. Consider making an array of two strings:</p>
<div class="code-box">
<pre>
#define X @"ex"
#define P @"plain"
a = [NSArray arrayWithObjects:X
                              P,
                              nil];
</pre>
</div>
<p>That <em>looks</em> right, but I forgot a &#8220;<code>,</code>&#8221; after <code>X</code>, so after string-concatenation, <code>a</code> is <code>['explain']</code>, not <code>['ex','plain']</code>.</p>
<p>Moral of the story: <strong>you can never have too many ()&#8217;s in macros</strong>.</p>
<p>And, now, back to why I use <code>#define</code>&#8230;</p>
<h3>It&#8217;s less code</h3>
<p>Using an <code>extern</code> variable means declaring it in a header, <em>and</em> defining it in some implementation file. But a macro is just one line in a header.</p>
<h3>It&#8217;s faster to lookup</h3>
<p>Because there&#8217;s only the definition of a macro, Open Quickly/command-double-clicking a macro <em>always</em> jumps to the definition, so you can see what it&#8217;s value is in one step. Generally Xcode jumps to a symbol&#8217;s declaration first, and <em>then</em> it&#8217;s definition, making it slower to lookup the value of a <code>const</code> symbol.</p>
<h3>It&#8217;s still type safe</h3>
<p>An <code>@"NSString literal"</code> has type information, so mistakes like,</p>
<pre>#define X (@"immutable string")
NSMutableString *y = X;
[y appendString:@"z"];
</pre>
<p>still generate warnings.</p>
<h3>It lets the compiler <a href="http://bobthegnome.blogspot.com/2009/07/format-not-string-literal-and-no-format.html">check format-strings</a></h3>
<p>Xcode can catch errors like &#8220;<code>[NSString stringWithFormat:@"reading garbage since there's no argument: %s"]</code>&#8220;, <a href="http://vgable.com/blog/2009/12/09/compile-safer/">if you let it</a>. Unfortunately, the Objective-C compiler isn&#8217;t smart enough to check <code>[NSString stringWithFormat:externConstString,x,y,z];</code> because it doesn&#8217;t know what an <code>extern</code> variable contains until link-time. But preprocessor macros are evaluated early enough in the build process that that the compiler can check their values.</p>
<h3>It can&#8217;t be changed at runtime</h3>
<p>It&#8217;s possible to change the value of <code>const</code> variables through pointers, like so:</p>
<div class="code-box">
<pre>
const NSString* const s = @"initial";
NSString **hack = &#038;s;
*hack = @"changed!";
NSLog(s);//prints "changed!"
</pre>
</div>
<p>Yes this is pathological code, but I&#8217;ve seen it happen (I&#8217;m looking at you <code>AddressBook.framework</code>!)</p>
<p>Of course, you can re-<code>#define</code> a preprocessor-symbol, so macros aren&#8217;t a panacea for pathological constant-changing code. (Nothing is!) But they push the pathology into compile time, and common wisdom is that it&#8217;s easier to debug compile-time problems, so that&#8217;s a Good Thing. You may <a href="http://vgable.com/blog/2008/09/18/i-would-rather-have-a-runtime-error-than-a-compile-error/">disagree there</a>, and you may be right! All I can say for sure is that <em>in my experience</em>, I&#8217;ve had bugs from <code>const</code> values changing at runtime, but no bugs from re-<code>#define</code>-ed constants (yet).</p>
<h3>Conclusion</h3>
<p>Preprocessor macros are damnably dangerous in C. Generally you should avoid them. But for <code>NSString*</code> constants in applications, I think they&#8217;re easier, and arguably less error prone. So go ahead and <code>#define YOUR_STRING_CONSTANTS (@"like this")</code>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/07/19/define-string/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>NSDictionary Copies It&#8217;s Keys</title>
		<link>http://vgable.com/blog/2010/07/08/nsdictionary-copies-its-keys/</link>
		<comments>http://vgable.com/blog/2010/07/08/nsdictionary-copies-its-keys/#comments</comments>
		<pubDate>Thu, 08 Jul 2010 17:55:29 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Apple]]></category>
		<category><![CDATA[copy]]></category>
		<category><![CDATA[Documentation]]></category>
		<category><![CDATA[NSDictionary]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=643</guid>
		<description><![CDATA[An NSDictionary will retain it&#8217;s objects, and copy it&#8217;s keys. Here are some effects this has had on code I&#8217;ve worked on. Sometimes you get the same object you put in, sometimes not. Immutable objects are optimized to return themselves as a copy. (But with some exceptions!). So the following code: NSDictionary *d = [NSDictionary [...]]]></description>
			<content:encoded><![CDATA[<p>An <code>NSDictionary</code> will <code>retain</code> it&#8217;s objects, and <code>copy</code> it&#8217;s keys. </p>
<p>Here are some effects this has had on code I&#8217;ve worked on.</p>
<ul>
<li>
<strong>Sometimes you get the same object you put in, sometimes not</strong>.<br />
<a href="http://vgable.com/blog/2008/11/14/prefer-copy-over-retain/">Immutable objects are optimized to return themselves as a <code>copy</code></a>. (But with some exceptions!). So the following code:</p>
<pre>
	NSDictionary *d = [NSDictionary dictionaryWithObject:@"object" forKey:originalKey];
	for(id aKey in d)
		if(aKey == originalKey)
			NSLog(@"Found the original key!");
</pre>
<p>Might print &#8220;Found the original key!&#8221;, and might not, depending on how <code>[originalKey  copy]</code> is implemented. For this reason, <strong>never use pointer-equality when comparing keys</strong>.</p>
<li><strong>Mutable objects make bad keys</strong>. If <code>x</code> is a mutable <code>NSObject</code>, <code>[x copy] is an </code><em>immutable</em> copy of <code>x</code>, <em>at that point in time</em>. Any changes to <code>x</code> are <em>not</em> reflected in the copy. For example,
<pre>
	[dict setObject:x forKey:key];
	//...code that changes key, but not dict
	<a href="http://vgable.com/blog/2008/12/04/nsassert-considered-harmful/">assert</a>([[dict objectForKey:key] isEqual:x]); //fails!
</pre>
<p>Because the <code>copy</code> is an immutable object, it will blow up if you try to mutate it.</p>
<pre>
	NSMutableString *key = //something...
	[dict setObject:x forKey:key];
	for(NSMutableString *aKey in dict)
		[aKey appendString:@"2"]; //Error, aKey isn't mutable, even though key is!
</pre>
</li>
<li>
<strong>View objects make bad keys</strong>. Views have state related to  the screen: their <code>frame</code>, position in the view hierarchy, animation layers, etc. When you <code>copy</code> a view object, the copy won&#8217;t (always) be <code>isEqual:</code> to the original, because it&#8217;s not on the screen in exactly the same way.
</li>
</li>
<li>
<strong>Your classes must support <code>NSCopying</code> to be used as a key in an <code>NSDictionary</code></strong>, you can&#8217;t just <a href="http://mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html">implement <code>-hash</code> and <code>-isEqual:</code></a> in your custom classes.
</li>
</ul>
<p>Of course, this isn&#8217;t a complete list of every way key-copying can trip you up. But if you understand what <code>copy</code> means in Cocoa, and remember how <code>NSDictionary</code> works, you&#8217;ll be able to avoid or quickly solve any issues.</p>
<h3>How to Document Such Behavior Better Than Apple Did</h3>
<p>Given what we know about <code>NSDictionary</code>, what&#8217;s wrong with the following snippit from <code>NSDictionary.h</code>?</p>
<pre>
@interface NSMutableDictionary : NSDictionary
- (void)setObject:(id)anObject forKey:(id)aKey;
@end
</pre>
<p>Answer: <code> aKey </code> needs to implement <code>NSCopying</code>, so it should be of type <code>(id&lt;NSCopying&gt;)</code> instead of type <code>(id)</code>. That way, the header is self-documenting, and, if like most smart programmers, you&#8217;re using autocomplete to type out Cocoa&#8217;s long method names, the auto-completed template will be self-documenting too.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/07/08/nsdictionary-copies-its-keys/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Write dealloc FIRST</title>
		<link>http://vgable.com/blog/2010/05/25/write-dealloc-first/</link>
		<comments>http://vgable.com/blog/2010/05/25/write-dealloc-first/#comments</comments>
		<pubDate>Tue, 25 May 2010 20:32:19 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Best Practices]]></category>
		<category><![CDATA[dealloc]]></category>
		<category><![CDATA[ivars]]></category>
		<category><![CDATA[Memory Management]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=607</guid>
		<description><![CDATA[As soon as you give a class a new instance variable (ivar), update the class&#8217;s dealloc method (and viewDidUnload, if the ivar is an IBOutlet) to clean up the ivar. Do this before you write the code using the new ivar. Here&#8217;s why: Never Forget You can&#8217;t forget to release an ivar, if the code [...]]]></description>
			<content:encoded><![CDATA[<p>As soon as you give a class a new instance variable (ivar), update the class&#8217;s <code>dealloc</code> method (and <code>viewDidUnload</code>, if the ivar is an <code>IBOutlet</code>) to clean up the ivar. Do this <em>before</em> you write the code using the new ivar. Here&#8217;s why:</p>
<h3>Never Forget</h3>
<p>You can&#8217;t forget to <code>release</code> an ivar, if the code that reaps it is in place <em>before</em> the code that creates it. Updating <code>dealloc</code> first means less memory leaks.</p>
<p>Even with an impossibly good testing protocol, that catches <em>every</em> memory leak, it&#8217;s faster to fix memory leaks before they happen than to track them down after the fact.</p>
<h3>You Know More Than They Do</h3>
<p>Sometimes there&#8217;s an important step that must be done when cleaning up an ivar. Maybe you need to set it&#8217;s <code>delegate</code> to <code>nil</code>, or unregister for a notification, or break a <a href="http://www.mikeash.com/pyblog/friday-qa-2010-04-30-dealing-with-retain-cycles.html">retain cycle</a>. You know this when you setup the ivar. But your coworkers don&#8217;t know this <em>a priori</em>. When you checkin code that leaks or triggers an analyzer warning, they&#8217;ll want to fix it, and since they know less than you do about your code, they&#8217;re more likely to miss a crucial step. (Even if you work alone, remember Future You! In <em>N</em> weeks, Future You will have to deal with all the code Present You wrote today &#8230; and they&#8217;ll be in the same situation as any other co-worker, because they won&#8217;t remember everything Present You knows. )</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/05/25/write-dealloc-first/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Never Name a Variable &#8220;Index&#8221;</title>
		<link>http://vgable.com/blog/2010/05/24/never-name-a-variable-index/</link>
		<comments>http://vgable.com/blog/2010/05/24/never-name-a-variable-index/#comments</comments>
		<pubDate>Mon, 24 May 2010 05:31:42 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Names]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=603</guid>
		<description><![CDATA[Never name a variable index, especially in C. Instead say what it indexes. For example, if it is used to index an array of Foo objects, call it fooArrayIndex, or currentFooIndex. If the index variable is just used to enumerate over a collection of objects, (eg. for(int i = 0; i &#038;lt arraySize; i++){…} ) [...]]]></description>
			<content:encoded><![CDATA[<p><strong><em>Never</em> name a variable <code>index</code></strong>, especially in C.</p>
<p>Instead <strong>say <em>what</em> it indexes</strong>. For example, if it is used to index an array of <code>Foo</code> objects, call it <code>fooArrayIndex</code>, or <code>currentFooIndex</code>.</p>
<p>If the index variable is just used to enumerate over a collection of objects, (eg. <code>for(int i = 0; i &#038;lt arraySize; i++){…} </code>) then <a href="http://vgable.com/blog/2008/04/07/foreach-for-the-win/">iterate smarter</a>, using a simpler construct that doesn&#8217;t require declaring auxiliary variables. (Eg., in Objective-C use <a href="http://developer.apple.com/mac/library/documentation/cocoa/conceptual/objectivec/articles/ocfastenumeration.html">Fast Enumeration</a>). It&#8217;s not always possible to do this, but it&#8217;s always a good idea to try.<sup>1</sup></p>
<h3>Why <code>index</code> is Especially Bad in C</h3>
<p>The standard <code>strings.h</code> header declares a function named <code>index</code>, that finds the first occurrence of a charicter in a C-string. In practical terms <strong>every C program will have the <code>index</code> function declared everywhere</strong>.</p>
<p>But when a variable is declared with the name <code>index</code> it <a href="http://leepoint.net/notes-java/data/variables/60shadow-variables.html">shadows</a> the function &#8211; meaning the local variable named <code>index</code> takes over the name <code>index</code>, so the function can&#8217;t be called anymore:</p>
<pre>
char * world = index("Hello, World", 'W');
NSLog(@"'%s'", world);
</pre>
<p>Prints &#8220;&#8216;World&#8217;&#8221;, but</p>
<pre>
int index = 0;
char * world = index("Hello, World", 'W');
NSLog(@"'%s'", world);
</pre>
<p>Won&#8217;t compile, because an <code>int</code> isn&#8217;t a function.</p>
<p>Obviously this is a problem for code that uses the <code>index()</code> function — but honestly modern code probably uses a safer, <a href="http://www.mikeash.com/pyblog/friday-qa-2010-02-19-character-encodings.html">unicode-aware</a> string parsing function instead. What&#8217;s given me the most trouble is that <strong>shadowing <code>index</code> makes the compiler give lots of bogus warnings, if you have the useful <code>GCC_WARN_SHADOW</code> <a href="http://vgable.com/blog/2009/12/09/compile-safer/">warning turned on</a></strong>.</p>
<p>There are other good reasons as, specific to Objective-C, which <a href="http://boredzo.org/blog/archives/2009-11-05/the-peril-of-the-index-function">Peter Hosey covers</a>.</p>
<p><sup>1</sup><small>If you <em>really</em> can&#8217;t think of a better name than &#8220;index&#8221;, I prefer the more terse <code>i</code>. It sucks, but at least it&#8217;s shorter. Brevity is a virtue.</small></p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/05/24/never-name-a-variable-index/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>This Usually Makes Me Feel Better</title>
		<link>http://vgable.com/blog/2010/02/09/this-usually-makes-me-feel-better/</link>
		<comments>http://vgable.com/blog/2010/02/09/this-usually-makes-me-feel-better/#comments</comments>
		<pubDate>Tue, 09 Feb 2010 23:55:53 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[Entertainment]]></category>
		<category><![CDATA[Ira Glass]]></category>
		<category><![CDATA[Motivation]]></category>
		<category><![CDATA[Practice]]></category>
		<category><![CDATA[Taste]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=569</guid>
		<description><![CDATA[]]></description>
			<content:encoded><![CDATA[<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/-hidvElQ0xE&#038;hl=en_US&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/-hidvElQ0xE&#038;hl=en_US&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object></p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/02/09/this-usually-makes-me-feel-better/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A C &amp;Puzzler[]</title>
		<link>http://vgable.com/blog/2009/12/25/a-c-puzzler/</link>
		<comments>http://vgable.com/blog/2009/12/25/a-c-puzzler/#comments</comments>
		<pubDate>Fri, 25 Dec 2009 20:35:54 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Pointers]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=547</guid>
		<description><![CDATA[Here&#8217;s a C-puzzler for you! given this function, void foo(char* s){ printf("s is at: %p\n s is: '%s'\n", s, s); } and that char s[] = "Joy!"; foo(s); prints out s is at: 0xbffff46b s is: &#8216;Joy!&#8217; what will this next line print? foo(&#038;s); //WHAT WILL THIS DO? Pick all that apply: Print &#8220;Joy!&#8221; Print [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a C-puzzler for you!</p>
<p>given this function,</p>
<pre>void foo(char* s){
	printf("s is at: %p\n s is: '%s'\n", s, s);
}</pre>
<p>and that</p>
<pre>
char s[] = "Joy!";
foo(s);
</pre>
<p>prints out</p>
<blockquote><p>
s is at: <code>0xbffff46b</code><br />
s is: &#8216;Joy!&#8217;
</p></blockquote>
<p>what will this next line print?</p>
<pre><strong>foo(&#038;s); //WHAT WILL THIS DO?</strong>
</pre>
<p>Pick all that apply:</p>
<ol>
<li>Print &#8220;Joy!&#8221;</li>
<li>Print garbage</li>
<li>Print the same address for <code>s</code></li>
<li>Print the a different address for <code>s</code></li>
<li>Crash</li>
<li>Go into an Infinite loop</li>
</ol>
<h3>Answer</h3>
<p><small>Answer: one and three</small></p>
<p>Yeah, it&#8217;s not what I expected either, especially since:</p>
<pre>@encode(__typeof__(s)) = [5c]
@encode(__typeof__(&#038;s)) = ^[5c]</pre>
<p>In fact, all of these are equvalent (modulo type warnings):</p>
<pre>
foo(s);
foo(&#038;s[0]);
foo(&#038;(*s));
foo(&#038;s);
</pre>
<p><a href="http://www.reddit.com/r/programming/comments/i6k5/jeez_after_all_these_years_a_c_array_vs_pointer">Explanation</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/12/25/a-c-puzzler/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Compile Safer</title>
		<link>http://vgable.com/blog/2009/12/09/compile-safer/</link>
		<comments>http://vgable.com/blog/2009/12/09/compile-safer/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 11:13:18 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Cocoa]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[MacOSX]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Compilers]]></category>
		<category><![CDATA[GCC]]></category>
		<category><![CDATA[Warnings]]></category>
		<category><![CDATA[Xcode]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=526</guid>
		<description><![CDATA[Peter Hosey explains what warnings he uses and why. It&#8217;s good, but long. Fortunately, you can just grab a script, and enable those warnings in your Xcode projects. Warnings = Errors If I could force just one compiler flag on everyone who&#8217;s code I use, it would be TREAT_WARNINGS_AS_ERRORS. As a rule, things don&#8217;t get [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://boredzo.org/blog/archives/2009-11-07/warnings">Peter Hosey explains what warnings he uses and why</a>. It&#8217;s good, but long. Fortunately, you can <a href="http://rentzsch.tumblr.com/post/237349423/hoseyifyxcodewarnings-scpt">just grab a script</a>, and enable those warnings in your Xcode projects.</p>
<h3>Warnings = Errors</h3>
<p>If I could force just one compiler flag on everyone who&#8217;s code I use, it would be <code>TREAT_WARNINGS_AS_ERRORS</code>. As a rule, things don&#8217;t get improved if they aren&#8217;t broken. (How many times have you said &#8220;I&#8217;ll come back and fix this code later&#8221;? Yeah.)  Warnings fester and grow on each other, until they cause a real breakage. It&#8217;s an inescapable evil of building software with finite resources.</p>
<p>If a warning isn&#8217;t worth stopping the build over &#8212; it&#8217;s not worth checking for in the first place.</p>
<h3>Use the Latest Tools</h3>
<p>Specifically, if you aren&#8217;t using <a href="http://www.amazon.com/gp/product/B001AMHWP8?ie=UTF8&#038;tag=vincgabl-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=B001AMHWP8">Snow Leopard</a> and Xcode 3.2 to build your Objective-C code, <strong>you are crazy</strong>. Trust me, <a href="http://developer.apple.com/mac/library/featuredarticles/StaticAnalysis/index.html">painless static analysis</a> is worth upgrading for. It catches maddening memory leaks, not just trivial type errors, like adding an <code>int</code> to an <code>NSArray</code>, that you would catch immediately.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/12/09/compile-safer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Just Look at it, Man!</title>
		<link>http://vgable.com/blog/2009/11/11/just-look-at-it-man/</link>
		<comments>http://vgable.com/blog/2009/11/11/just-look-at-it-man/#comments</comments>
		<pubDate>Wed, 11 Nov 2009 07:46:06 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Graphing]]></category>
		<category><![CDATA[Optimization]]></category>
		<category><![CDATA[SSE]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Visualization]]></category>
		<category><![CDATA[War Story]]></category>
		<category><![CDATA[x86]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=495</guid>
		<description><![CDATA[You&#8217;re looking at Anscombe&#8217;s quartet: 4 datasets with identical simple statistical properties (mean, variance, correlation, linear regression); but obvious differences when graphed. (via Best of Wikipedia) Graphs aren&#8217;t a substitute for numerical analysis. Graphs are not a panacea. But they&#8217;re excellent for discovering patterns, outliers, and getting intuition about a dataset. If you never graph [...]]]></description>
			<content:encoded><![CDATA[<p>You&#8217;re looking at <a href="http://en.wikipedia.org/wiki/Anscombe%27s_quartet">Anscombe&#8217;s quartet</a>: 4 datasets with identical simple statistical properties (mean, variance, correlation, linear regression); but obvious differences when graphed.<br />
<a href="http://en.wikipedia.org/wiki/File:Anscombe.svg" class="no-border">
<div style="text-align:center;"><img src="http://vgable.com/blog/wp-content/uploads/2009/11/325px-Anscombe.svg.png" alt="325px-Anscombe.svg.png" border="0" width="325" height="222" /></div>
<p> </a><br />
(via <a href="http://bestofwikipedia.tumblr.com/">Best of Wikipedia</a>)</p>
<p>Graphs aren&#8217;t a substitute for numerical analysis. Graphs are not a panacea. But they&#8217;re excellent for discovering patterns, outliers, and getting <em>intuition</em> about a dataset. If you never graph your data, then you&#8217;ve never really <em>looked at it</em>.</p>
<h3>War Story</h3>
<p>I was working on optimizing color correction, using SSE (high performance x86 instructions). One operation required division &#8212; an expensive operation for a computer. The hardware had a <code>divide</code> instruction, but sometimes using the <a href="http://www.sosmath.com/calculus/diff/der07/der07.html">Newton-Raphson method</a> to <a href="http://en.wikipedia.org/wiki/Division_(digital)#Newton.E2.80.93Raphson_division">do the division in software</a> is faster. You never know until you measure.</p>
<p>While doing the measurement, I somehow got the crazy idea to try both: I&#8217;d already unrolled the inner loop so instead of repeating the <code>divide</code> or Newton&#8217;s Method twice, I&#8217;d do a <code>divide</code> and then use Newton&#8217;s Method for the next value. Strangely enough, this was faster on the hardware I was benchmarking than either method individually. Modern hardware is a complex and scary beast.</p>
<p>I was fortunate enough to have a suite of very good unit tests to run against my optimized code. But there was a caveat to testing correctness. Because <a href="http://docs.sun.com/source/806-3568/ncg_goldberg.html">computers don&#8217;t have infinitely precise arithmetic</a>, two correct algorithms might give different answers &#8212; but if the numbers they gave were <em>close enough</em> to the infinitely precise answer (say a couple <a href="http://en.wikipedia.org/wiki/Unit_in_the_last_place">ulps</a> apart)  it was good enough. (<a href="http://vgable.com/blog/2009/11/04/tolerance/">We can only be exact within some Tolerance</a>!) The tests cleared my hybrid <code>divide</code>/Newton-Raphson function: <em>but we couldn&#8217;t use it, because it was fundamentally broken</em>.</p>
<p>Even though the error was acceptably small, it had a <em>nasty</em> distribution. Using <code>divide</code> gave color values that were a bit too light. Doing a divide in software gave values that were a bit too dark. Individually these errors were fine. Randomly <a href="http://en.wikipedia.org/wiki/Dither">spread over the image</a> they would have been fine. But processing every other pixel differently had the effect of adding alternating light/dark stripes! <a href="http://www.uiandus.com/2009/06/25/cognitive-science/perception-vs-reality-perception-wins/">We see contrast, not absolute color</a>, so the numerically insignificant error was quite visible. Worse still, bands of 1 pixel stripes combined to form a shimmering <a href="http://en.wikipedia.org/wiki/Moiré_pattern">Moiré pattern</a>. It was totally busted. Unusable.</p>
<p>This was all immediately obvious when the results of the color correction were &#8220;graphed&#8221;. Actually <em>looking</em> at the answer caught a subtle error that our suite of unit tests missed.</p>
<p>To be clear, more subjective graphical analysis is <em>not</em> a substitute for numerical analysis and data mining. But I believe in actually <em>looking at your data</em> at least once. A graph is a kind of <a href="http://vgable.com/blog/2009/03/03/vincents-notes-end-to-end-arguments-in-system-design/">end-to-end</a> visualization of everything, and that has value. Graphs are a cheap sanity check &#8212; does everything look right? And sometimes, they can give you real insight into a problem.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/11/11/just-look-at-it-man/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>sizeof() Style</title>
		<link>http://vgable.com/blog/2009/10/19/sizeof-style/</link>
		<comments>http://vgable.com/blog/2009/10/19/sizeof-style/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 17:23:26 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Bug Bite]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Tips]]></category>
		<category><![CDATA[Programming Style]]></category>
		<category><![CDATA[sizeof]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=460</guid>
		<description><![CDATA[Never say sizeof(sometype) when you can say sizeof(a_variable). The latter works even if the type of a_variable changes, and it is much more obvious what the size is supposed to represent.]]></description>
			<content:encoded><![CDATA[<p>Never say <code>sizeof(sometype)</code> when you can say <code>sizeof(a_variable)</code>.  The latter works even if the type of <code>a_variable</code> changes, and it is much more obvious what the size is supposed to represent.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/10/19/sizeof-style/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

