<?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; Research</title>
	<atom:link href="http://vgable.com/blog/category/research/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>16</slash:comments>
		</item>
		<item>
		<title>Experts are Easier to Fool</title>
		<link>http://vgable.com/blog/2010/05/24/experts-are-easier-to-fool/</link>
		<comments>http://vgable.com/blog/2010/05/24/experts-are-easier-to-fool/#comments</comments>
		<pubDate>Mon, 24 May 2010 15:47:24 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Cons]]></category>
		<category><![CDATA[Experts]]></category>
		<category><![CDATA[Scams]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=605</guid>
		<description><![CDATA[Another counter-intuitive finding is that scam victims often have better than average background knowledge in the area of the scam content. For example, it seems that people with experience of playing legitimate prize draws and lotteries are more likely to fall for a scam in this area than people with less knowledge and experience in [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Another counter-intuitive finding is that <strong>scam victims often have better than average background knowledge in the area of the scam content</strong>. For example, it seems that people with experience of playing legitimate prize draws and lotteries are more likely to fall for a scam in this area than people with less knowledge and experience in this field. This also applies to those with some knowledge of investments. Such knowledge can increase rather than decrease the risk of becoming a victim.</p></blockquote>
<p>(<a href="http://www.schneier.com/blog/archives/2009/06/the_psychology_3.html">via Bruce Schneier</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2010/05/24/experts-are-easier-to-fool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spurious</title>
		<link>http://vgable.com/blog/2009/11/09/spurious/</link>
		<comments>http://vgable.com/blog/2009/11/09/spurious/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 22:09:29 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Analysis]]></category>
		<category><![CDATA[Batman]]></category>
		<category><![CDATA[Correlation]]></category>
		<category><![CDATA[Data]]></category>
		<category><![CDATA[Drowning]]></category>
		<category><![CDATA[Fallacy]]></category>
		<category><![CDATA[Ice Cream]]></category>
		<category><![CDATA[Lisa Wade]]></category>
		<category><![CDATA[Statistics]]></category>
		<category><![CDATA[Summer]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=490</guid>
		<description><![CDATA[What’s a spurious relationship? Here’s one: People who eat ice cream are more likely to drown. Both incidence of ice cream eating and rates of drowning are related to summertime. The relationship between ice cream and drowning is spurious. That is, there is no relationship. Yet they appear related because they are both related to [...]]]></description>
			<content:encoded><![CDATA[<blockquote><h3>What’s a spurious relationship?</h3>
<p>Here’s one: <strong>People who eat ice cream are more likely to drown</strong>.  Both incidence of ice cream eating and rates of drowning are related to summertime.  The relationship between ice cream and drowning is spurious.  That is, there is no relationship.  Yet they appear related because they are both related to a third variable.
</p></blockquote>
<p>&#8211;<a href="http://contexts.org/socimages/2009/06/06/the-contact-hypothesis-and-spurious-relationships/">Lisa Wade</a></p>
<div style="text-align:center;"><img src="http://vgable.com/blog/wp-content/uploads/2009/11/untitled5sk.jpg" alt="untitled5sk.jpg" border="0" width="400" height="595" /></div>
<p>(Image <a href="http://superdickery.com/index.php?view=article&#038;catid=30%3Aframes-and-panels-index&#038;id=788%3Abatman-hates-ice-cream&#038;option=com_content&#038;Itemid=24">via</a> the amazing <a href="http://superdickery.com/">Superdickery</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/11/09/spurious/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Hack: Counting Variadic Arguments in C</title>
		<link>http://vgable.com/blog/2009/10/16/hack-counting-varadic-arguments-in-c/</link>
		<comments>http://vgable.com/blog/2009/10/16/hack-counting-varadic-arguments-in-c/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 05:04:09 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Design]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Introspection]]></category>
		<category><![CDATA[Parsing]]></category>
		<category><![CDATA[Programming Language Design]]></category>
		<category><![CDATA[Variadic Functions]]></category>
		<category><![CDATA[Variadic Macros]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=442</guid>
		<description><![CDATA[This isn&#8217;t practical, but I think it&#8217;s neat that it&#8217;s doable in C99. The implementation I present here is incomplete and for illustrative purposes only. Background C&#8217;s implementation of variadic functions (functions that take a variable-number of arguments) is characteristically bare-bones. Even though the compiler knows the number, and type, of all arguments passed to [...]]]></description>
			<content:encoded><![CDATA[<p>This isn&#8217;t practical, but I think it&#8217;s neat that it&#8217;s doable in C99. The implementation I present here is <strong>incomplete and for illustrative purposes only</strong>.</p>
<h3>Background</h3>
<p>C&#8217;s implementation of <a href="http://cocoawithlove.com/2009/05/variable-argument-lists-in-cocoa.html">variadic functions</a> (functions that take a variable-number of arguments) is characteristically bare-bones. Even though the compiler knows the number, and type, of all arguments  passed to variadic functions; there isn&#8217;t a mechanism for the function to get this information from the compiler. Instead, programmers need to pass an extra argument, like the <code>printf</code> <a href="http://en.wikipedia.org/wiki/Printf#printf_format_placeholders">format-string</a>, to tell the function &#8220;these are the arguments I gave you&#8221;. This has worked for over 37 years. But it&#8217;s clunky &#8212; you have to write the same information twice, once for the compiler and again to tell the function what you told the compiler.</p>
<h3>Inspecting Arguments in C</h3>
<h4>Argument Type</h4>
<p><strong>I don&#8217;t know of a way to find the type of the Nth argument to a varadic function, called with heterogeneous types.</strong> If you can figure out a way, I&#8217;d love to know. <strong>The <a href="http://gcc.gnu.org/onlinedocs/gcc/Typeof.html"><code>typeof</code></a> extension is often sufficient to write generic code that works when every argument has the same type.</strong> (<a href="http://www.cplusplus.com/doc/tutorial/templates/">C++ templates</a> also solve this problem if we step outside of C-proper.)</p>
<h4>Argument Count (The Good Stuff Starts Here)</h4>
<p><strong>By using <a href="http://gcc.gnu.org/onlinedocs/cpp/Variadic-Macros.html">variadic macros</a>, and <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html">stringification (<code>#</code>)</a>, we can actually pass a function the literal string of its argument list from the source code &#8212; which it can parse to determine how many arguments it was given.<br />
</strong></p>
<p>For example, say <code>f()</code> is a variadic function. We create a variadic wrapper macro, <code>F()</code> and call it like so in our source code,</p>
<pre>x = F(a,b,c);</pre>
<p>The preprocessor expands this to,</p>
<pre>x = f("a,b,c",a,b,c)</pre>
<p>Or perhaps,</p>
<pre>x = f(count_arguments("a,b,c"),a,b,c)</pre>
<p>where <code>count_arguments(char *s)</code> returns the number of arguments in the string source-code string <code>s</code>. (Technically <code>s</code> would be an argument-expression-list).</p>
<h3>Example Code</h3>
<p>Here&#8217;s an implementation for, <code>iArray()</code>, an array-builder for <code>int</code> values, very much like <a href="http://www.amazon.com/gp/product/0596101996?ie=UTF8&#038;tag=vincgabl-20&#038;linkCode=as2&#038;camp=1789&#038;creative=390957&#038;creativeASIN=0596101996">JavaScript</a>&#8216;s <code>Array()</code> constructor. Unlike the <a href="http://www.youtube.com/watch?v=hQVTIJBZook">quirky JavaScript</a> <code>Array()</code>, <code>iArray(3)</code> returns an array containing just the element 3, <code>[3]</code>, not an uninitilized array with 3 elements, <code>[undefined, undefined, undefined]</code>. Another difference: <code>iArray()</code>, invoked with no arguments, is invalid, and will not compile.</p>
<pre>
#define iArray(...) alloc_ints(count_arguments(#__VA_ARGS__), __VA_ARGS__)
</pre>
<p>This macro is pretty straightforward. It&#8217;s given a variable number of arguments, represented by <code>__VA_ARGS__</code> in the expansion. <code>#__VA_ARGS__</code> <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html">turns the code into a string</a> so that <code>count_arguments</code> can analyze it. (If you were doing this for real, you should use two levels of <a href="http://gcc.gnu.org/onlinedocs/cpp/Stringification.html">stringification</a> though, otherwise macros won&#8217;t be fully expanded. I choose to keep things &#8220;demo-simple&#8221; here.)</p>
<pre>
unsigned count_arguments(char *s){
	unsigned i,argc = 1;
		for(i = 0; s[i]; i++)
			if(s[i] == ',')
				argc++;
	return argc;
}
</pre>
<p>This is a <strong>dangerously naive</strong> implementation and only works correctly when <code>iArray()</code> is given a straightforward non-empty list of values or variables. Basically it&#8217;s the least code I could write to make a working demo.</p>
<p>Since <code>iArray</code> must have at least one argument to compile, we just count the commas in the argument-list to see how many other arguments were passed. Simple to code, but it fails for more complex expressions like <code>f(a,g(b,c))</code>.</p>
<pre>
int *alloc_ints(unsigned count, ...){
	unsigned i = 0;
	int *ints = malloc(sizeof(int) * count);
	va_list args;
    va_start(args, count);
	for(i = 0; i < count; i++)
		ints[i] = va_arg(args,int);
	va_end(args);
	return ints;
}
</pre>
<p>Just as you'd expect, this code allocates enough memory to hold <code>count</code> <code>int</code>s, and fills it with the remaining <code>count</code> arguments. Bad things happen if &lt; <code>count</code> arguments are passed, or they are the wrong type.</p>
<p><a href="http://vgable.com/code/iArray.c">Download the code</a>, if you like.</p>
<h3><a href="http://steve-yegge.blogspot.com/2007/06/rich-programmer-food.html">Parsing is Hard</a>, Let's Go Shopping</h3>
<p>I didn't even try to correctly parse <em>any</em> valid argument-expression-list in <code>count_arguments</code>. It's non trivial. I'd rather deal with choosing the correct <code>MAX3</code> or <code>MAX4</code> macro in a few places than maintain such a code base.</p>
<p>So this kind of introspection isn't really practical in C. But it's neat that it can be done, without any tinkering with the compiler or language.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/10/16/hack-counting-varadic-arguments-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Big Freaking Systems</title>
		<link>http://vgable.com/blog/2009/09/17/big-freaking-systems/</link>
		<comments>http://vgable.com/blog/2009/09/17/big-freaking-systems/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 09:03:05 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Complexity]]></category>
		<category><![CDATA[Computer Science]]></category>
		<category><![CDATA[Education]]></category>
		<category><![CDATA[School]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/?p=395</guid>
		<description><![CDATA[A programming language is a tool for handling design complexity. That&#8217;s what all of computer science is, really &#8212; languages, libraries, type systems, garbage collectors, everything you learn about programming. They&#8217;re ways to build more and more complex designs without losing your grip. The way you manage complexity is to be able to ignore it. [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>A programming language is a tool for handling design complexity. That&#8217;s what all of computer science is, really &#8212; languages, libraries, type systems, garbage collectors, <strong>everything you learn about programming. They&#8217;re ways to build more and more complex designs without losing your grip.</strong></p>
<p>The way you manage complexity is to be able to ignore it. A good programming tool lets you forget about some part of the problem, so that you can focus on some other part. And it ensures that when you return to the parts you forgot, you haven&#8217;t accidentally broken them.
</p></blockquote>
<p>&#8211;<a href="http://eblong.com/zarf/essays/rule-based-if/">Andrew Potkin</a></p>
<p>Years ago, When I was taking to programmers about what college I wanted to attend, I had in interesting conversation about how Computer Science education is an <em>utter failure</em> at preparing students for real-world programming. Outside of Software Development, no technical field accepts (sometimes prefers) candidates with &#8220;N years of experience&#8221; in place of a degree. I&#8217;m not sure I know why CS education fails so badly and universally. But my current best guess is that it&#8217;s because <strong>school never exposes you to enough complexity</strong>. Projects have to end in a semester. You never have to deal with a multimillion-line program, written by hundreds of co-workers, dozens of which you need to collaborate with, at unexpected times, for surprising reasons.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/09/17/big-freaking-systems/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>links for 2009-06-04</title>
		<link>http://vgable.com/blog/2009/06/04/links-for-2009-06-04/</link>
		<comments>http://vgable.com/blog/2009/06/04/links-for-2009-06-04/#comments</comments>
		<pubDate>Fri, 05 Jun 2009 00:32:22 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Announcement]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Usability]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/06/04/links-for-2009-06-04/</guid>
		<description><![CDATA[This was an experiment, in doing more with my delicious bookmarks. I was hoping that I could get more feedback and discussion on things I found interesting enough to bookmark by automatically posting links to them here. Many sites that I enjoy reading do something similar. But it hasn&#8217;t felt like a good fit for [...]]]></description>
			<content:encoded><![CDATA[<p>This was an experiment, in doing more with my <a href="http://delicious.com/VTPG">delicious bookmarks</a>. I was hoping that I could get more feedback and discussion on <a href="http://delicious.com/VTPG">things I found interesting enough to bookmark</a> by automatically posting links to them here. Many <a href="http://picocool.com/">sites</a> <a href="http://daringfireball.net/">that I</a> <a href="http://waxy.org/">enjoy</a> <a href="http://www.kottke.org/">reading</a> do something similar. But it hasn&#8217;t felt like a good fit for me.</p>
<ul class="delicious">
<li>
<div class="delicious-link"><a href="http://www.eddit.com/shop/">eddit: Shop: iPhone icon sets</a></div>
<div class="delicious-extended">The $39 ones are very affordable, and <a href="http://twitter.com/scottstevenson/status/2033218172">got a nod from Scott Stevenson</a>.</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/iphonedev">iphonedev</a> <a href="http://delicious.com/VTPG/icons">icons</a> <a href="http://delicious.com/VTPG/design">design</a> <a href="http://delicious.com/VTPG/ui">ui</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://pickfu.com/">Let us Pick-fu you. | Cheap &amp; instant market research.</a></div>
<div class="delicious-extended">Pay $5, get (only!) 50 people to vote on a yes/no question. Sounds like a lot of money compared to <a href="http://www.mturk.com">mturk</a>. As always, I&#039;m skeptical that any internet poll can be a usably-random sample.</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/web2.0">web2.0</a> <a href="http://delicious.com/VTPG/research">research</a> <a href="http://delicious.com/VTPG/crowdsourcing">crowdsourcing</a> <a href="http://delicious.com/VTPG/business">business</a> <a href="http://delicious.com/VTPG/marketresearch">marketresearch</a> <a href="http://delicious.com/VTPG/polling">polling</a> <a href="http://delicious.com/VTPG/opinion">opinion</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://smallbiztrends.com/2009/03/facebook-digital-sharecroppers.html">Is Facebook Turning Us Into Digital Sharecroppers? | Small Business Trends</a></div>
<div class="delicious-extended">
<blockquote>Author Nicholas Carr coined the phrase digital sharecroppers to describe those of us who create content on community Web 2.0 sites&#8230;.He says we are like sharecroppers after the Civil War — tilling land that we don’t own, barely eking out a living, while someone else who owns the land, benefits.</p></blockquote>
<p>But clearly facebook gives us something of value, even if it&#8217;s fun, not money. (That said, I&#8217;ve got adds blocked though CSS).</p>
<p>However, I think Digital Sharecroppers is an appropriate term for contributers to restrictive open source projects. The real wealth of a programming project is the code, not the final product. And licenses like the GPL don&#8217;t let contributers share in that wealth by using it in their own proprietary projects.
</p></div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/web2.0">web2.0</a> <a href="http://delicious.com/VTPG/buisness">buisness</a> <a href="http://delicious.com/VTPG/socialmedia">socialmedia</a> <a href="http://delicious.com/VTPG/facebook">facebook</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://www.buzzmachine.com/2009/06/04/stop-selling-scarcity/">Stop selling scarcity</a></div>
<div class="delicious-extended">
<blockquote>The future of advertising needs to be selling &#8211; that is, enabling &#8211; relevance instead of selling scarce space, time, or eyeballs. The future needs to be about adding value &#8211; relevance &#8211; rather than selling scarcity (extracting what the market will bear). I’m not sure whether Digg’s system is a step in that direction; Batey’s right that there could be unintended consequences. But it’s worth watching. I hope Digg shares data and experience in its fascinating experiment.</p></blockquote>
</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/advertising">advertising</a> <a href="http://delicious.com/VTPG/web2.0">web2.0</a> <a href="http://delicious.com/VTPG/digg">digg</a> <a href="http://delicious.com/VTPG/research">research</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://www.deeperweb.com/">DeeperWeb Search &#8211; The Essential Search Engine Addon and Plugin</a></div>
<div class="delicious-extended">google + tag cloud for your search</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/search">search</a> <a href="http://delicious.com/VTPG/google">google</a> <a href="http://delicious.com/VTPG/web2.0">web2.0</a> <a href="http://delicious.com/VTPG/tags">tags</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://www.cs.utah.edu/~hal/docs/daume02yaht.pdf">http://www.cs.utah.edu/~hal/docs/daume02yaht.pdf</a></div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/toread">toread</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://lifehacker.com/5277383/use-caps-lock-for-hand+friendly-text-navigation">Lifehacker &#8211; Use Caps Lock for Hand-Friendly Text Navigation &#8211; Ubergeek</a></div>
<div class="delicious-extended">The idea is to remap Caps Lock so that while holding it, J-I-L-K work like the arrow keys to move the cursor. Since we have more clear arrow keys, I don&#039;t think that&#039;s the best use for caps lock, but ideas for using it are always interesting.</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/capslock">capslock</a> <a href="http://delicious.com/VTPG/interface">interface</a> <a href="http://delicious.com/VTPG/navigation">navigation</a> <a href="http://delicious.com/VTPG/text">text</a> <a href="http://delicious.com/VTPG/writing">writing</a>)</div>
</li>
<li>
<div class="delicious-link"><a href="http://www.useit.com/alertbox/20040301.html">Risks of Quantitative Studies (Jakob Nielsen&#039;s Alertbox)</a></div>
<div class="delicious-extended">Nielson argues that qualitative analysis is dangerously narrow.<br />
<blockquote>It&#039;s a dangerous mistake to believe that statistical research is somehow more scientific or credible than insight-based observational research. In fact, most statistical research is less credible than qualitative studies. Design research is not like medical science: ethnography is its closest analogy in traditional fields of science. User interfaces and usability are highly contextual, and their effectiveness depends on a broad understanding of human behavior</p></blockquote>
<p> The problem with qualatative &quot;research&quot; however is that it&#039;s not clear how to make it objective and verifiable. </p>
<p>Nielson makes a good point that 95% confidence &rArr; 1/20 results are wrong. But that&#039;s why scientists <em>reproduce</em> experiments, and why it&#8217;s so necessary to be able to do that.</div>
<div class="delicious-tags">(tags: <a href="http://delicious.com/VTPG/design">design</a> <a href="http://delicious.com/VTPG/culture">culture</a> <a href="http://delicious.com/VTPG/science">science</a> <a href="http://delicious.com/VTPG/usability">usability</a> <a href="http://delicious.com/VTPG/data">data</a> <a href="http://delicious.com/VTPG/statistics">statistics</a> <a href="http://delicious.com/VTPG/research">research</a> <a href="http://delicious.com/VTPG/analysis">analysis</a> <a href="http://delicious.com/VTPG/measurement">measurement</a>)</div>
</li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/06/04/links-for-2009-06-04/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Pass Phrases, Not Passwords</title>
		<link>http://vgable.com/blog/2009/06/01/pass-phrases-not-passwords/</link>
		<comments>http://vgable.com/blog/2009/06/01/pass-phrases-not-passwords/#comments</comments>
		<pubDate>Mon, 01 Jun 2009 14:33:57 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Authentication]]></category>
		<category><![CDATA[English]]></category>
		<category><![CDATA[Pass-Phrases]]></category>
		<category><![CDATA[Password]]></category>
		<category><![CDATA[Randomness]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/06/01/pass-phrases-not-passwords/</guid>
		<description><![CDATA[Thomas Baekdal makes a convincing argument for using pass-phrases not passwords (via). It&#8217;s excellent advice, and I know I&#8217;m not alone in having advocated it for years. My keyboard has 26 letters, 10 numbers, and 12 symbol keys, like ~. All but spacebar make a different symbol when I hold down shift, giving me 93 [...]]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.baekdal.com/articles/Usability/password-security-usability/">Thomas Baekdal makes a convincing argument for using pass-<em>phrases</em> not pass<em>words</em></a> (<a href="http://delicious.com/hublicious">via</a>). It&#8217;s excellent advice, and I know I&#8217;m not alone in having advocated it for years. </p>
<p>My keyboard has 26 letters, 10 numbers, and 12 symbol keys, like ~. All but spacebar make a different symbol when I hold down shift, giving me 93 characters to use in my passwords. But <strong> the number of words that can make-up a pass-phrase is <em><a href="http://en.wikipedia.org/wiki/English_language#Number_of_words_in_English">easily</a></em> in the 100,000s</strong>. Estimating exactly how big is a bit tricky, but I will stick with 250,000 here (I think it&#8217;s an <em>undercount</em>, more on this later).</p>
<h3>We Know How To Talk</h3>
<p>The human brain has an <em>amazing</em> aptitude for language. But &#8220;passwords&#8221; aren&#8217;t really words, so they don&#8217;t tap into this ability. In fact, <strong>we often use <em>words</em> to try and remember the nonsense-characters of a password</strong>.</p>
<p>Wouldn&#8217;t it make more sense to just use the words directly, if we can remember them more easily?</p>
<h3>Hard For Computers, Not Hard For Us</h3>
<p><strong>People <em>feel</em> that if security system A is harder for them to use then system B, then A must be harder for an attacker to bypass</strong>. But the facts don&#8217;t always match this intuition.</p>
<p>What authentication code do you think is harder for a bad guy to hack, the 7 character <a href="http://strongpasswordgenerator.com/">strong password</a> &#8220;1Ea.$]/&#8221;, or the mnemonic for the first 3 characters, &#8220;One Elvis Amazon&#8221;? Certainly &#8220;1Ea.$]/&#8221; is harder for a person to remember. It <em>feels</em> like it <em>should</em> be harder to break. But a computer, not a person, is going to be doing the guessing, and all it cares about is how big the search space is. There are 93<sup>7</sup> possible 7 character passwords. Let&#8217;s say there are 250,000 possible English words (more on that figure later). Then there are 250,000<sup>3</sup> 3 word combinations &#8212; meaning an attacker would have to do 260 <em>times</em> more work to guess &#8220;One Elvis Amazon&#8221; than to guess &#8220;1Ea.$]/&#8221;.</p>
<p>With pass phrases, easier for the good guys is also harder for the bad guys.</p>
<h3>Exactly How Much Harder</h3>
<p>The &#8220;250,000 word&#8221; figure is a bunch of hand-waiving, but I believe it&#8217;s an <em>undercount</em>. I picked it, because I wanted a round number to crunch; <a href="http://www.baekdal.com/articles/Usability/password-security-usability/">it&#8217;s what Thomas Baekdal</a> picked; and it&#8217;s about the size of <a href="http://en.wikipedia.org/wiki/Words_(Unix)">the Mac OS X words file</a>,</p>
<pre>
$ wc -l /usr/share/dict/words
  234936</pre>
<p>But liberally descriptive linguists say that <a href="http://www.languagemonitor.com/?p=368">the 1,000,000th word will be added to the English Language on June 10th, 2009</a>. The more conservative <cite>Webster&#8217;s Third New International Dictionary, Unabridged</cite> list 475,000 English words. Obviously <strong>neologisms, slang, and archaic terms are fine for pass phrases</strong>. People <em>like</em> <a href="http://www.google.com/search?rls=en-us&#038;q=word+of+the+day&#038;ie=UTF-8&#038;oe=UTF-8">discovering quirky words</a>. I see far more more people embracing the login, &#8220;kilderkin of locats&#8221;, then rejecting it.</p>
<p><strong>Different conjugations (can) count as different words in pass-phrases.</strong> There&#8217;s only one entry in a dictionary for swim, but swim, swimming, swam, etc. make for distinct pass-phrases (eg. &#8220;Elvis <strong>swims</strong> fast&#8221;, &#8220;Elvis <strong>swam</strong> fast&#8221;, etc. Both phrases don&#8217;t show up in a google search by the way.) So <strong>the real number of words should be a few fold larger than a dictionary indicates</strong>.</p>
<p>But <strong>not all words are equally likely to be chosen</strong> &#8212; just as <a href="http://www.schneier.com/blog/archives/2006/12/realworld_passw.html">some characters are more popular in passwords</a>. My earlier figure of &#8220;250000<sup>3</sup> 3 word combinations&#8221; was based on the naive assumption that each of the 3 words is <a href="http://en.wikipedia.org/wiki/Independent_variable">independent</a>. But <a href="http://scienceblogs.com/cognitivedaily/2007/02/is_17_the_most_random_number.php">people do not pick things at random</a>. And a phrase is <em>by definition</em> not completely random &#8212; it must have <a href="http://en.wikipedia.org/wiki/Subject_Verb_Object">some structure</a>. I&#8217;m unaware of research into exactly how predictable people are when making-up pass-phrases. </p>
<p>But given how <em>terrible</em> we are at picking good passwords, and how good we are at remembering non-nonsense-words, I am optimistic that we can remember pass-phrases that are orders of magnitude harder to guess than the &#8220;good&#8221; passwords we can&#8217;t remember today.</p>
<h3>Fewer Ways To Fail</h3>
<p>We&#8217;ve all locked ourselves out of an account because of typos or <a href="http://imlocation.wordpress.com/2007/07/28/caps-lock/">caps lock</a>. But pass-phrases can be more forgiving.</p>
<p>Pass-phrases are case<em>in</em>sensitive. There&#8217;s no need to lock someone out over &#8220;ELvis&#8230;&#8221;.</p>
<p>Common typos can be auto-corrected, much as google automatically suggests words. Consider the authentication attempt &#8220;Elvis <em>Swimmms</em> fast&#8221;. The system could recognize that &#8220;Swimms&#8221; isn&#8217;t a word, and try the most likely correction, &#8220;Elvis <strong>Swimms</strong> fast&#8221; &#8212; if it matches, then there&#8217;s no reason to ask the user if it&#8217;s what they really meant. (Note that only one pass-phrase is checked per login attempt.) I don&#8217;t have hard data here, but given how successful google is at interpreting typos, I&#8217;d expect such a system to work very well.</p>
<p>Pass-phrases might be more difficult on Phones, and similarly <a href="http://rands.tumblr.com/post/93333051/roughly-30-apology">awkward to write with</a> devices. Writing more letters means more work. <a href="http://en.wikipedia.org/wiki/Predictive_text">Predictive text</a> can only do so much. Repeatedly typing 3 letters <em>and</em> accepting a suggestion is clearly more work then just tapping out 6 characters. Additionally, there are security concerns with a predictive text system remembering your pass-phrase, or even a small part of it. </p>
<p>But for computers, pass phrases look like a clear usability win.</p>
<h3>Easily Secure Conclusion</h3>
<p>(In case you were wondering <a href="http://www.google.com/search?hl=en&#038;q=%22Easily+Secure+Conclusion%22&#038;btnG=Search&#038;aq=f&#038;oq=&#038;aqi=">that was a unique phrase</a> when I wrote this.) Using pass-<em>phrases</em> over passwords (which are really pass-strings-of-nonsense-sybols-that-<a href="http://www.schneier.com/blog/archives/2005/06/write_down_your.html">nobody-can-remember</a>) makes a system significantly harder to crack. Pass-phrases are easier for humans to remember, and a system that uses them can be very forgiving. But as always, the devil is in the details. It&#8217;s terrifying to be an early adopter of a new security practice, even if it seems sound.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/06/01/pass-phrases-not-passwords/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Concise NSDictionary and NSArray Lookup</title>
		<link>http://vgable.com/blog/2009/05/15/concise-nsdictionary-and-nsarray-lookup/</link>
		<comments>http://vgable.com/blog/2009/05/15/concise-nsdictionary-and-nsarray-lookup/#comments</comments>
		<pubDate>Fri, 15 May 2009 19:13:02 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Objective-C]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Sample Code]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[NSArray]]></category>
		<category><![CDATA[NSDictionary]]></category>
		<category><![CDATA[Programming Language Design]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/05/15/concise-nsdictionary-and-nsarray-lookup/</guid>
		<description><![CDATA[I started writing a list of ways I thought Objective-C could be improved, and I realized that many of my wishes involved more compact syntax. For example [array objectAtIndex:1] is so verbose I think it diminishes readability, compared to array[1]. I can&#8217;t quite match that brevity (can you, by using Objective-C++?), but with a one-line [...]]]></description>
			<content:encoded><![CDATA[<p>I started writing a list of ways I thought Objective-C could be improved, and I realized that many of my wishes involved more compact syntax. For example <code>[array objectAtIndex:1]</code> is so verbose I think it diminishes readability, compared to <code>array[1]</code>.</p>
<p>I can&#8217;t quite match that brevity (can you, by using Objective-C++?), but with a one-line category, you can say, <code>x = [array:1];</code>.</p>
<pre>
@interface NSArray (ConciseLookup)
- (id):(NSUInteger)index;
@end
@implementation NSArray (ConciseLookup)
- (id):(NSUInteger)index;
{
	return [self objectAtIndex:index];
}
@end
</pre>
<p>My question is: <strong>do you find this compact &#8220;syntax&#8221; useful at all, or is it added complexity with no substantial code compression?</strong> Personally I think the latter, but the number of wishes I had involving  more concise Objective-C syntax makes me wonder&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/05/15/concise-nsdictionary-and-nsarray-lookup/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Emergent Libraries</title>
		<link>http://vgable.com/blog/2009/05/14/emergent-libraries/</link>
		<comments>http://vgable.com/blog/2009/05/14/emergent-libraries/#comments</comments>
		<pubDate>Thu, 14 May 2009 14:46:01 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Functional Programming]]></category>
		<category><![CDATA[LLVM]]></category>
		<category><![CDATA[Programming Language Design]]></category>
		<category><![CDATA[Programming Style]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Static Analysis]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/05/14/emergent-libraries/</guid>
		<description><![CDATA[I have latched onto an idea, but don&#8217;t have the resources to follow up on it: could a static-analysis tool identify repeated patterns of code, across many code bases, that should be extracted out as subroutines and higher-level functions? How universal would these &#8220;emergent libraries&#8221; be? My inspiration here is Section 4.1 Identifying Common Functions, [...]]]></description>
			<content:encoded><![CDATA[<p>I have latched onto an idea, but don&#8217;t have the resources to follow up on it: could <a href="http://llvm.org/">a static-analysis tool</a> identify repeated patterns of code, across <a href="http://github.com/">many</a> <a href="http://code.google.com/">code</a> <a href="http://sourceforge.net/">bases</a>, that should be extracted out as subroutines and higher-level functions? How universal would these &#8220;emergent libraries&#8221; be?</p>
<p>My inspiration here is <cite>Section 4.1 Identifying Common Functions</cite>, in the <strong>excellent paper</strong> <a href="http://cr.yp.to/qmail/qmailsec-20071101.pdf"><cite>Some Thoughts on Security After Ten Years of qmail 1.0</cite> (PDF)</a>, by Daniel J. Bernstein,</p>
<blockquote><p> Most programmers would never bother to create such a small  function. But several words of code are saved whenever one  occurrence of the <code>dup2()</code>/<code>close()</code> pattern is replaced with  one call to <code>fd_move();</code> replacing a dozen occurrences saves  considerably more code than were spent writing the function  itself. (The function is also <strong>a natural target for tests</strong>.)  The same benefit scales to larger systems and to a huge variety of functions; <code>fd_move()</code> is just one example. In many cases an automated scan for common operation sequences  can suggest <strong>helpful new functions</strong>, but even without automation I frequently find myself thinking “Haven’t I seen this  before?” and extracting a new function out of existing code.</p></blockquote>
<p>What&#8217;s particularly fascinating to me are <strong>the <em>new</em> operations we might find</strong>.</p>
<p>Before I was exposed to the <a href="http://www.haskell.org/onlinereport/standard-prelude.html">Haskell prelude</a> I hadn&#8217;t known about the fundamentally useful <a href="http://en.wikipedia.org/wiki/Foldl"><code>foldl</code> and <code>foldr</code></a> operations.  I had written dozens of programs that used accumulation, but it&#8217;s generalization hadn&#8217;t occurred to me &#8212; and probably never would have. Static analysis can help uncover generalizations that we might have missed, or didn&#8217;t think were important, but turn out <em>in practice</em> to be widely used operations.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/05/14/emergent-libraries/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Acceptable Delays</title>
		<link>http://vgable.com/blog/2009/04/30/acceptable-delays/</link>
		<comments>http://vgable.com/blog/2009/04/30/acceptable-delays/#comments</comments>
		<pubDate>Fri, 01 May 2009 00:03:22 +0000</pubDate>
		<dc:creator>Vincent Gable</dc:creator>
				<category><![CDATA[Accessibility]]></category>
		<category><![CDATA[Design]]></category>
		<category><![CDATA[Quotes]]></category>
		<category><![CDATA[Research]]></category>
		<category><![CDATA[Usability]]></category>
		<category><![CDATA[Cognition]]></category>
		<category><![CDATA[Delay]]></category>
		<category><![CDATA[Interface]]></category>
		<category><![CDATA[Internet]]></category>
		<category><![CDATA[Latency]]></category>
		<category><![CDATA[People Won't Use it if they Hate it]]></category>

		<guid isPermaLink="false">http://vgable.com/blog/2009/04/30/acceptable-delays/</guid>
		<description><![CDATA[This is a collection of sources on what constitutes an acceptable delay. It&#8217;s very much a work in progress, and will be updated when I stumble into new information. I&#8217;m very interested in any insights, experience, or sources you may have. Based on some experiments I did back at IBM, delays of 1/10th of a [...]]]></description>
			<content:encoded><![CDATA[<p>This is a collection of sources on what constitutes an acceptable delay. It&#8217;s very much a work in progress, and will be updated when I stumble into new information. I&#8217;m very interested in any insights, experience, or sources you may have.</p>
<blockquote><p>Based on some experiments I did back at IBM, <strong>delays of 1/10th of a second are roughly when people start to notice that an editor is slow</strong>. If you can respond is less than 1/10th of a second, people don&#8217;t perceive a troublesome delay.</p></blockquote>
<p>&#8211;<a href="http://scienceblogs.com/goodmath/2009/02/gap_buffers_or_why_bother_with_1.php">Mark Chu-Carroll</a></p>
<p></p>
<blockquote><p> One second &#8230; is the required response time for hypertext navigation. Users do not keep their attention on the page if downloading exceeds 10 seconds.</p></blockquote>
<p>&#8211;<a href="http://www.useit.com/about/nographics.html">Jakob Nielsen, (in 1997?)</a></p>
<p></p>
<blockquote><p>In A/B tests (at Amazon.com), we tried delaying the page in increments of 100 milliseconds and found that even very small delays would result in substantial and costly drops in revenue. (eg 20% drop in traffic when moving from 0.4 to 0.9 second load time for search results).</p></blockquote>
<p>&#8211;<a href="http://glinden.blogspot.com/2006/11/marissa-mayer-at-web-20.html">Greg Linden covering results disclosed by Google VP Marissa Mayer</a></p>
<blockquote><p>If a user operates a control and nothing appears on the display for more than <strong>approximately 250 msec, she</strong> is likely to become uneasy, to try again, or to begin to wonder whether the system is failing.</p></blockquote>
<p>&#8211; Jeff Raskin, <cite><a href="http://www.amazon.com/gp/redirect.html?ie=UTF8&#038;location=http%3A%2F%2Fwww.amazon.com%2Fgp%2Fproduct%2F0201379376%2F&#038;tag=vincgabl-20&#038;linkCode=ur2&#038;camp=1789&#038;creative=9325">The Humane Interface</a><img src="http://www.assoc-amazon.com/e/ir?t=vincgabl-20&amp;l=ur2&amp;o=1" width="1" height="1" border="0" alt="" style="border:none !important; margin:0px !important;" /></cite> (<a href="http://books.google.com/books?id=D39vjmLfO3kC&#038;pg=PA75&#038;vq=%22response+time%22&#038;dq=humane+interface&#038;source=gbs_search_s&#038;cad=0">page 75</a>)</p>
<p>David Eagleman&#8217;s blog post <cite><a href="http://www.sentientdevelopments.com/2009/02/will-you-perceive-event-that-kills-you.html">Will you perceive the event that kills you?</a></cite> is an engaging look at how slow human perception is, compared to mechanical response time. For example, in a car crash that takes 70ms from impact until airbags begin <em>deflating</em>, the occupants are not aware of the collision until 150-300 milliseconds (possibly as long as 500 milliseconds) after impact.</p>
]]></content:encoded>
			<wfw:commentRss>http://vgable.com/blog/2009/04/30/acceptable-delays/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

