<?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>ihumanable &#187; api</title>
	<atom:link href="http://ihumanable.com/blog/tag/api/feed/" rel="self" type="application/rss+xml" />
	<link>http://ihumanable.com/blog</link>
	<description>usable in any place a human can be used</description>
	<lastBuildDate>Wed, 11 May 2011 15:10:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.2</generator>
		<item>
		<title>sanity please</title>
		<link>http://ihumanable.com/blog/2010/10/04/sanity-please/</link>
		<comments>http://ihumanable.com/blog/2010/10/04/sanity-please/#comments</comments>
		<pubDate>Mon, 04 Oct 2010 16:33:03 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[rant]]></category>
		<category><![CDATA[api]]></category>
		<category><![CDATA[facebook]]></category>
		<category><![CDATA[kill it with fire]]></category>

		<guid isPermaLink="false">http://ihumanable.com/blog/?p=870</guid>
		<description><![CDATA[I&#8217;m sure this tale of woe will be shared by many of my web development colleagues, it has to do with Facebook. As a web developer I have to pay a Facebook Tax, Facebook has an API (I think they might be up to their fourth API now) and they have 500 million people, and [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m sure this tale of woe will be shared by many of my web development colleagues, it has to do with Facebook.  As a web developer I have to pay a Facebook Tax, Facebook has an API (I think they might be up to their fourth API now) and they have 500 million people, and so management everywhere wants their product to integrate with Facebook.  Here&#8217;s the problem, Facebook fucking sucks at documentation.</p>
<p>There are as far as I can tell at least 4 competing technology stacks going on over at Facebook: FBML, Javascript SDK, Old REST API, and Graph API.  There could be more, some of those might not be fully APIs and are just components, I&#8217;m not really sure.  I&#8217;ve been reading the pages at <a href="http://developers.facebook.com/">the official documentation website</a> for weeks now trying to wrap my head around this thing.  Maybe it&#8217;s just me, maybe I&#8217;m dense or something, but I can&#8217;t seem to figure out what the fuck is going on or what I should be using.</p>
<p>Here&#8217;s a great example, let&#8217;s say you want to integrate Facebook Connect (if that&#8217;s still a thing, I&#8217;m not really sure), but more succinctly you just want to allow users to sign in using Facebook as their identity provider.  How are you supposed to do this.  Well there is this section on <a href="http://developers.facebook.com/docs/guides/web#login">Single Sign-On</a> that looks promising.  But then later on if you follow the link to learn more about the Graph API you will find a section about Authorization that will lead you to <a href="http://developers.facebook.com/docs/authentication/">this page on Authentication</a> which I think is showing you how to do the same thing, maybe.</p>
<p>The problem seems to be too many ways and pages explaining the same thing or slightly different things, I just want one canonical authoritative place to look that says, &#8220;This is the API you <strong>MUST</strong> use for Authentication.&#8221;  I don&#8217;t think that is asking too much.  But I&#8217;m sure once I finish my primer on <a href="http://tools.ietf.org/html/draft-ietf-oauth-v2-10">OAuth 2.0</a> and figure out how the extended permissions works it will all be more clear.</p>
<p>The API could be forgiven for giving you more than one way to skin a cat, if it then gave you specific details on how this stuff actually works.  Let&#8217;s say I want to build a website that displays events and then let&#8217;s people use my website to mark themselves as attending that event in Facebook, is that possible&#8230; I have no idea.  <a href="http://developers.facebook.com/docs/api#publishing">Here&#8217;s a section of the Graph API about Publishing data to Facebook</a> and it might be in there somewhere, but I can&#8217;t tell.  I guess I&#8217;ll have to play around with how this supposedly RESTful API works when I have some state, maybe if I&#8217;ve successfully negotiated an OAuth Secret Consumer Token UID then I can call /EVENT_ID/attending and that will mark me as attending the Event with EVENT_ID, it seems to make sense a little bit, but the extremely helpful description of &#8220;attend the given event&#8221; and the arguments of <em>none</em> make me have to play around to figure it out.</p>
<p><a href="http://www.sethcall.com/blog/2010/09/30/facebook-api-does-not-care/">Seth Call</a> is similarly frustrated and makes a very nice detailed case for why the Facebook API is so woefully inadequate.  I couldn&#8217;t agree more, and I hope that help is on the way.</p>
<p>The problem I&#8217;m running into now is frustration and discoverability.   There doesn&#8217;t seem to be a particular flow to these documents, they are just disparate documents hyperlinked together in no particular order.  I&#8217;m new is there a tutorial or common use case section, maybe somewhere buried 9 links deep.  If you are going to embrace and extend then at least have the common courtesy to make our lives easier as you try to take over the world.</p>
<p>Facebook seems to have too many developers working in the API space not communicating, the &#8220;Old&#8221; and &#8220;New&#8221; APIs overlap in some areas and miss each other in other areas, there&#8217;s no definitive answer on when support will end for any of the &#8220;Old&#8221; APIs, is it safe to use the &#8220;Old&#8221; REST API for functionality the Graph API doesn&#8217;t support or will they turn off the tap at some point.  When trying to navigate through the documentation it just feels like they made someone do a braindump and didn&#8217;t try to organize it in any fashion.</p>
<p>Well I&#8217;m going to head back in because with the draw of 500,000,000 potential users we can&#8217;t afford not to pay the Facebook Tax, which is a real shame considering how shitty the Tax Code they published is.</p>
]]></content:encoded>
			<wfw:commentRss>http://ihumanable.com/blog/2010/10/04/sanity-please/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>convention vs convenience</title>
		<link>http://ihumanable.com/blog/2009/11/10/convention-vs-convenience/</link>
		<comments>http://ihumanable.com/blog/2009/11/10/convention-vs-convenience/#comments</comments>
		<pubDate>Tue, 10 Nov 2009 19:59:45 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://ihumanable.com/blog/?p=82</guid>
		<description><![CDATA[I&#8217;m a huge believer in Convention over Configuration because it makes life easier and makes me more productive. I use to program in Java, and unless there is some seismic shake-up, I will soon be going back to Java. I like Java well enough, it&#8217;s no lisp or ruby, but it has its place in [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_84" class="wp-caption alignright" style="width: 310px"><img src="http://ihumanable.com/blog/wp-content/uploads/2009/11/chocolate-chip-corn-dog-300x278.jpg" alt="convenience, american style" title="chocolate-chip-corn-dog" width="300" height="278" class="size-medium wp-image-84" /><p class="wp-caption-text">convenience, american style</p></div>
<p>I&#8217;m a huge believer in <a href="http://en.wikipedia.org/wiki/Convention_over_configuration">Convention over Configuration</a> because it makes life easier and makes me more productive.  I use to program in Java, and unless there is some seismic shake-up, I will soon be going back to Java.  I like Java well enough, it&#8217;s no lisp or ruby, but it has its place in the business world.  I have many gripes with Java, verbosity, complexity, etc, but when you are in the enterprise trying to work with a bunch of third party pieces cobbled together into a hulking software nightmare the worst, by far, is configuration.</p>
<p>It makes some business sense, if a customer won&#8217;t use your product because they want to change the tooltip on the help page and they can&#8217;t without hiring a Java programmer, or at all because you distribute closed source .jar files, the simplest solution is to toss a config file at them.  Just change this or that setting in the config file and, look at that, the whole application is christmas colored and in sanskrit.  There are a some huge problems with Java configuration though.</p>
<ol>
<li>The unfortunate pairing with XML &#8211; XML hit its high water mark around the same time as Java, maybe there was some reciprocal love there, and it can be maddening.
<pre class="brush: xml; title: ;">
&amp;lt;env-entry&amp;gt;
  &amp;lt;env-entry-name&amp;gt;maxExemptions&amp;lt;/param-name&amp;gt;
  &amp;lt;env-entry-value&amp;gt;10&amp;lt;/env-entry-value&amp;gt;
  &amp;lt;env-entry-type&amp;gt;java.lang.Integer&amp;lt;/env-entry-type&amp;gt;
&amp;lt;/env-entry&amp;gt;
</pre>
<p>Oh fuck me, are you serious?!  I took that from the official <a href="http://tomcat.apache.org/tomcat-5.5-doc/config/context.html">Tomcat Documentation</a>.  It just sets maxExemptions = 10, but it takes 5 lines, 2 layers of nesting, 4 open tags, 4 close tags, and as you can see, this is a straight copy and paste from the official documentation and it has a pretty clear error.  Clear to me because my eyes have been trained to read xml like a champion, the env-entry-name tag is closed by a param-name tag, that isn&#8217;t right.</li>
<li>Undocumented DSL &#8211; Every configuration is basically an undocumented Domain Specific Language wrapped up in XML&#8217;s ugly ass clothing.  There is little transfer of knowledge between Java and a Java Configuration file, or even between XML and a Java Configuration file.</li>
<li>Undiscoverable &#8211; Maybe it would be more accurate to put hard to discover.  Where do you go to figure out what belongs in your config, or what nodes configure what, your best bet is to hope the developer wrote up (and subsequently kept up to date) some documentation.  Little to no help from your favorite IDE&#8217;s code completion and the constrained nature of the problem domain makes web searches less likely to yield helpful information.</li>
<li>Twiddling &#8211; Like in field of dreams, if you make a configuration, they will come.  Sure there is no good reason for X to be configurable, but I don&#8217;t like having hardcoded values in my code, so every hardcoded value is now configurable, and I&#8217;m on the slippery slope of softcoding now.  This allows the end user too much power to twiddle around and configure things that don&#8217;t ever need to be played with, just because we can doesn&#8217;t mean we should.</li>
</ol>
<p>This isn&#8217;t just Java&#8217;s problem, they are just the easiest to pick on because it seems like its everywhere.  Then Ruby on Rails came onto the scene and made popular this idea, <strong>convention over configuration</strong>.  I want to put my models in the fliggity directory, that&#8217;s too bad, they go in the model directory.  I would like to name my table that stores user data &#8216;tc_people_datastore&#8217;, yea well I would like a billion dollars, you are going to call it users.  This means that if tomorrow I&#8217;m told to go work on a RoR project, having never seen it, I would have a good idea how the project is laid out, where the data lives, and how everything is hooked together.  This convention eases the mental load I have to carry around, replacing it with simple, sane rules.</p>
<p>Convention over configuration, especially the rails way, has been called <em>opinionated software</em>.  The software, in this case rails, has an opinion about how things should be laid out, what your tables should be called, etc.  I&#8217;m in the midst of writing my own software and API and I&#8217;ve decided that my software should have an opinion about stuff, but more importantly that things should follow certain conventions.</p>
<div id="attachment_86" class="wp-caption alignleft" style="width: 215px"><img src="http://ihumanable.com/blog/wp-content/uploads/2009/11/pancakes.gif" alt="conventional breakfast" title="pancakes" width="205" height="175" class="size-full wp-image-86" /><p class="wp-caption-text">conventional breakfast</p></div>
<p>As a corollary to the conventions is a strive for consistency.  Maybe a better title for this post would have been consistency vs convenience, but I&#8217;m already 700 words in, no going back now.  I&#8217;d like a consistent API for a few reasons.  Consistency makes it easy to remember, does this function go ($needle, $haystack) or ($haystack, $needle)?  They all go ($needle, $haystack) calm down.  Consistency makes wrong code look wrong, after seeing the same type of thing over and over again, the pattern gets burned in your brain, any deviation is obvious.  I&#8217;m a little OCD, and making things consistent feels better.</p>
<p>The problem is that convention taken too far leads to an ugly little town called boilerplate, and no one wants to live there.  This is where convenience comes in, it allows you to more-or-less follow convention but allow yourself an out to skip over the obvious parts.  The problem is trying to strike an appropriate balance.  I have a story of failure and redemption that I will quickly share with you.</p>
<p>My new side project is written in phpand makes use of the ubiquitous associative array when it makes sense to.  I love me some php, but I hate the associative array literal syntax, and  <a href="http://markmail.org/message/rsi4welftwou24p3">it&#8217;s not going to change anytime soon</a>  For those of you unfamiliar here is how you would make the same associative arrays, in json and php.</p>
<pre class="brush: jscript; title: ;">
var example = {'a': '1', 'b': '2', 'c': '3'};
</pre>
<pre class="brush: php; title: ;">
$example = array('a' =&amp;gt; 1, 'b' =&amp;gt; 2, 'c' =&amp;gt; 3);
</pre>
<p>Doesn&#8217;t look too bad or different, but if you have to have nested arrays or use an array in a function signature (my case) it gets a ugly pretty quickly.  I have also been reading up on lisp a lot recently and they have an idea that successive arguments can act as a pair.  I thought this was a pretty nifty idea, so I set about creating an alternative calling convention.</p>
<pre class="brush: php; title: ;">
$foo-&amp;gt;bar(array('name' =&amp;gt; 'Matt', 'age' =&amp;gt; 23));
</pre>
</p>
<p>Would be identical to</p>
<pre class="brush: php; title: ;">
$foo-&amp;gt;bar('name', 'Matt', 'age', 23);
</pre>
<p>I thought that this looked much nicer, and it is fairly trivial to implement</p>
<pre class="brush: php; title: ;">
class Foo {
  function bar($values) {
    if(func_num_args() &amp;gt; 1) {
      $values = self::associate(func_get_args());
    }
    ...
  }

  static function associate($args) {
    $count = count($args);
    if($count % 2 == 1) {
      $args[] = null;
      ++$count;
    }
    for($i = 0; $i &amp;lt; $count; %i += 2) {
      $result[$args[$i]] = $args[$i + 1];
    }
    return $result;
  }
}
</pre>
<p>I had done it, bam, lisp style associative arguments in php.  The problem though is that, well, wtf?  That is going to be the reaction to any php programmer unfamiliar with the lisp convention.  I failed to follow the conventions of the language, so this morning I tore this code out.  It added a secondary way to call a function, and it also introduces several edge cases, the benefit is also dubious.  I was scratching my language implementer itch, but not in an appropriate fashion.  This time convenience had to be sacrificed for convention&#8217;s sake.</p>
]]></content:encoded>
			<wfw:commentRss>http://ihumanable.com/blog/2009/11/10/convention-vs-convenience/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>api design</title>
		<link>http://ihumanable.com/blog/2009/11/09/api-design/</link>
		<comments>http://ihumanable.com/blog/2009/11/09/api-design/#comments</comments>
		<pubDate>Mon, 09 Nov 2009 18:57:52 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[code]]></category>
		<category><![CDATA[philosophy]]></category>
		<category><![CDATA[api]]></category>

		<guid isPermaLink="false">http://ihumanable.com/blog/?p=74</guid>
		<description><![CDATA[I&#8217;m still working on my skunkworks side project, over the weekend I had the joy of integrating several third party php libraries. I got to spend a good amount of time on php.net reading over APIs and figuring out how to fit them into my project. Some of them were sublime, as though the author [...]]]></description>
			<content:encoded><![CDATA[<div id="attachment_76" class="wp-caption alignright" style="width: 207px"><img src="http://ihumanable.com/blog/wp-content/uploads/2009/11/blinkenlights-197x300.jpg" alt="blinkenlight interface" title="blinkenlights" width="197" height="300" class="size-medium wp-image-76" /><p class="wp-caption-text">blinkenlight interface</p></div>
<p>I&#8217;m still working on my skunkworks side project, over the weekend I had the joy of integrating several third party php libraries.  I got to spend a good amount of time on <a href="http://php.net">php.net</a> reading over APIs and figuring out how to fit them into my project.  Some of them were sublime, as though the author had read my mind and knew my exact mental model.  Some of them were abominations, fighting me all the way.  This got me to thinking about the design of a good API</p>
<p>What makes an API good?  There are a few things that make an API really nice to work with.</p>
<ol>
<li>Similarity of behavior &#8211; Writing an API that does searching through a b-tree?  Look at how searching is implemented for arrays or strings, and then copy the crap out of that API. This allows the developer to use all that knowledge they&#8217;ve built up about searching, so if I know
<pre class="brush: php; title: ;">array_first($needle, $haystack)</pre>
<p> returns the first instance of $needle in $haystack or FALSE on failure to find $needle, then
<pre class="brush: php; title: ;">btree_first($needle, $haystack)</pre>
<p> should work the same way.</li>
<li>Readability &#8211; Your API should make code that is readable, the function names should be descriptive (without being overly verbose), and code written with it should flow nicely.  Avoid using difficult to pronounce function names like <em>strcspn</em>.</li>
<li>Minimalism &#8211; You&#8217;re writing an API because you are doing something non-trivial, something complex enough that you want a simple looking API to interact with, so do exactly that, make it simple.  I&#8217;m sure that reflangulating the zyffer is a complex process that involves juxtaposing the allibaster and repeppering the kilgore while making sure not to narfle the garthok, but the reason you are writing an API is to hide that complexity away, don&#8217;t write a <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html">Leaky Abstraction</a>.  Allow me to write code like this
<pre class="brush: php; title: ;">
$zyffer = new Zyffer();
$zyffer-&amp;gt;reflangulate();
</pre>
<p>Not like this</p>
<pre class="brush: php; title: ;">
$zyffer = new Zyffer();
$zyffer-&amp;gt;juxtapose(Zyffer::allibaster);
$zyffer-&amp;gt;denarfle(Zyffer::garthok);
$zyffer-&amp;gt;repepper(Zyffer::kilgore);
$zyffer-&amp;gt;reflangulate();
</pre>
</li>
</ol>
<p>In the course of writing the API for my side project I&#8217;ve found it useful to put myself in the shoes of a new programmer trying to use my API.  How long would it take them to figure out X?  How often would they curse my name?  What is the <a href="http://www.osnews.com/story/19266/WTFs_m">WTFs/min</a> ratio looking like?  It has been a helpful tool to adopt that mindset and ask myself, why am I requiring this parameter, why do they have to call this function before that function, and would that be apparent, why am I making their life so difficult.  It has helped my slim down my API considerably, this combined with <a href="http://en.wikipedia.org/wiki/Convention_over_configuration">Convention over Configuration</a> has led to an API approaching &#8220;not terrible.&#8221;</p>
<p>Then it hit me, I have stumbled upon a big important rule, that I&#8217;ve implicitly been following for years, but now my brain is aware of it.</p>
<blockquote><p>You should write everything like it will one day be a public API</p></blockquote>
<p>Of course, like any rule that is written in absolutes, there are sure to be exceptions.  But I think on the whole, it will serve you well for a few reasons.  Public APIs are written to be simple to work with, which means that after you&#8217;ve encapsulated all the hard complicated stuff you can interact with a nice clean API.  This will make your life nice when working with your API, but the best part is <strong>maintenance</strong>.  Remember that new programmer we imagined to help write the API, that will be you, intrepid API writer, just a few short months after moving on from the API.  You will inevitably be called back to add a feature or fix a bug, and if your API is simple to pick up, then you will remember more of it, and relearn the parts you forgot that much quicker.</p>
<p>Another advantage is that a well-written API is much more likely to encapsulate well-written code.  When your API is separated nicely and parsed up cleanly between well defined units of work, the code powering them will probably have well defined separation of labor and understandable flow.  The API itself becomes the documentation for how a process is accomplished, the various actors nicely laid out as well defined classes and the behaviors as fancy-pants interfaces.  I&#8217;m certain you can create a clean API over a horrible pile of spaghetti code, just as surely as you can create a crap API over a beautiful collection of clean OOP, but a good API encourages good code.</p>
<p>At then end of the day the API is the face of your code.  You can write up all the pretty documentation and how-to&#8217;s and promotional websites with sweet web 2.0 reflection and fun oversized graphics, but when it gets down to brass tacks the developer is going to be instantiating your objects and calling your functions.  The fact that there is a pretty floating cloud icon isn&#8217;t going to make a developer feel any better that she just spent 4 hours figuring out that she forgot to juxtapose the allibaster and that made shit hit the fan when she called the promulgate function on the zyffer&#8217;s subclown.  Make sure that your code has a pretty face, even if its only you using it, the benefits will far outweigh the minor upfront costs</p>
]]></content:encoded>
			<wfw:commentRss>http://ihumanable.com/blog/2009/11/09/api-design/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

