<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Can't see nothing but the source code</title>
	<atom:link href="http://codeforfun.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeforfun.wordpress.com</link>
	<description>Java development with an iPhone touch pad for the Atari 2600 from an urban hip-hop perspective</description>
	<lastBuildDate>Wed, 18 Nov 2009 21:26:33 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='codeforfun.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/8d21f8fd8dcc021adcd46592bfbddcda?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Can't see nothing but the source code</title>
		<link>http://codeforfun.wordpress.com</link>
	</image>
			<item>
		<title>This makes me happy</title>
		<link>http://codeforfun.wordpress.com/2009/11/18/this-makes-me-happy/</link>
		<comments>http://codeforfun.wordpress.com/2009/11/18/this-makes-me-happy/#comments</comments>
		<pubDate>Wed, 18 Nov 2009 21:26:33 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1076</guid>
		<description><![CDATA[groovy -e &#8216;def printout = { it.consumeProcessOutput(System.out, System.err); it.waitFor() }; new File(/./).eachDirMatch ({ new File(it, /pom.xml/).exists() }) { printout(&#8220;mvn -f $it/pom.xml clean&#8221;.execute()) }&#8217;
Which can be simplified from Groovy 1.5 to Groovy 1.6.5 speak:
groovy -e &#8216;new File(/./).eachDirMatch ({ new File(it, /pom.xml/).exists() }) {&#8220;mvn -f $it/pom.xml clean&#8221;.execute(). waitForProcessOutput(System.out,System.err)}&#8217;
which only fits in a tweet if you don&#8217;t care [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1076&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>groovy -e &#8216;def printout = { it.consumeProcessOutput(System.out, System.err); it.waitFor() }; new File(/./).eachDirMatch ({ new File(it, /pom.xml/).exists() }) { printout(&#8220;mvn -f $it/pom.xml clean&#8221;.execute()) }&#8217;</p>
<p>Which can be simplified from Groovy 1.5 to Groovy 1.6.5 speak:<br />
groovy -e &#8216;new File(/./).eachDirMatch ({ new File(it, /pom.xml/).exists() }) {&#8220;mvn -f $it/pom.xml clean&#8221;.execute(). waitForProcessOutput(System.out,System.err)}&#8217;</p>
<p>which only fits in a tweet if you don&#8217;t care for errors when a directory isn&#8217;t a maven project:<br />
groovy -e &#8216;new File(/./).eachDir {&#8220;mvn -f $it/pom.xml clean&#8221;.execute(). waitForProcessOutput(System.out,System.err)}&#8217;</p>
<p>For those of you looking puzzled, it&#8217;s a Groovy way to clean a bunch of Maven project subfolders you plan to add into Subversion. It&#8217;ll work for ant too just by changing &#8220;mvn&#8221; to &#8220;ant&#8221; and changing &#8220;pom.xml&#8221; to &#8220;build.xml&#8221; in case you have a bunch of Ant projects that need to be added into svn.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1076/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1076/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1076/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1076/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1076/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1076/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1076/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1076/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1076/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1076/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1076&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/11/18/this-makes-me-happy/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Don&#8217;t forget to flush!</title>
		<link>http://codeforfun.wordpress.com/2009/11/16/dont-forget-to-flush/</link>
		<comments>http://codeforfun.wordpress.com/2009/11/16/dont-forget-to-flush/#comments</comments>
		<pubDate>Tue, 17 Nov 2009 04:30:57 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[I/O streams]]></category>
		<category><![CDATA[Java]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1074</guid>
		<description><![CDATA[It&#8217;s been a rough day. I spent the majority of it chasing down random misbehavior on a staging server. My development machine is 32 bit. (Technically my development machine is 64 bit but I&#8217;m running a 32bit Kernel in my OS.) The staging server is 64bit. I write Java. Java sez, &#8220;you write once and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1074&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>It&#8217;s been a rough day. I spent the majority of it chasing down random misbehavior on a staging server. My development machine is 32 bit. (Technically my development machine is 64 bit but I&#8217;m running a 32bit Kernel in my OS.) The staging server is 64bit. I write Java. Java sez, &#8220;you write once and run anywhere!&#8221; In reality, when I move compiled source code from my development machine to my staging machine things act radically different.</p>
<p>The big picture is that I&#8217;m trying to make the staging machine talk to me. I mean literally talk, using english words and all. It&#8217;s the extra 32 bits in this staging machine that have been getting in the way. They force me to scour the web and find native libraries that contain the same amount of extra chromosomes&#8230; err&#8230; bits. Then on top of that, Tomcat likes to do different things when you throw war files in it.</p>
<p>Today&#8217;s lesson begins from Tomcat. Pretend you&#8217;ve written a servlet. (Ok, you don&#8217;t have to pretend. Go on and write a servlet if it makes you feel better, I&#8217;ll wait here patiently.) In your servlet make like you have a lot of binary stuff that you want to share with connecting web people. These people might be sitting under a MacbookPro, or scrolling a Blackberry wheel, or flicking an iPhone or something. Whatever the case, they came to your servlet to get these wonderful binary thingies. These binary thingies are larger than your typical web page, spanning a few kilobytes. So now you have to use one of those stream classes. If you&#8217;re really smart, like I think I am, then you&#8217;ll do something clever [stupid] and try pipelining, or reading from an input stream and writing to an output stream. You&#8217;ll do this because you&#8217;re afraid of materializing too much binary goodness in your precious RAM sticks. You&#8217;ll say &#8220;1024 bytes is plenty enough! Let&#8217;s take these one thousand twenty four bytes and put them on the output stream for the people can get those!&#8221; Then if you&#8217;re really really smart, you&#8217;ll do this in a loop until you reach the bottom of your input stream.</p>
<p>Are you all done with your computer program? I think I&#8217;m done with mine! Goody! Lets mash the run button and see what happens? Is yourz doing like mine isn&#8217;t doing? Minez is supposed to be shuttling all of the binary stuff across teh internets, but its not because its borked. I only get part of what I thought I was gonna git. Now go scratch your head like the guys in the head and shoulders commercials and pour another cup of coffee. when you get back we&#8217;ll figure out wha happend&#8230;</p>
<p>Are you back yet? Cool! Lets look into your really really smart looping program. Do you see it? Right there in the middle of your loop. You keep writin&#8217; stuff but only part of it is showing on the other end. Any idea why? My Mommy told me a long time ago, &#8220;never forget to flush! It&#8217;s just bad manners&#8230;&#8221; She was also famous for saying stuff like, &#8220;poop or get off the pot!&#8221; In the loop thing we never flush our output stream! Maybe that&#8217;s why we only see a part of the stuff on the other end. So then there&#8217;s a happy ending to the story after all isn&#8217;t there?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1074/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1074/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1074/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1074/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1074/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1074/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1074/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1074/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1074/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1074/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1074&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/11/16/dont-forget-to-flush/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Linux Can&#8217;t load library:libmawt.so</title>
		<link>http://codeforfun.wordpress.com/2009/11/13/linux-cant-load-librarylibmawt-so/</link>
		<comments>http://codeforfun.wordpress.com/2009/11/13/linux-cant-load-librarylibmawt-so/#comments</comments>
		<pubDate>Fri, 13 Nov 2009 14:38:07 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[AWT]]></category>
		<category><![CDATA[Java]]></category>
		<category><![CDATA[Linux Hacks]]></category>
		<category><![CDATA[Window Toolkits]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1072</guid>
		<description><![CDATA[Your a Java developer and you&#8217;ve installed Linux. Maybe this is your first time converting from Windows. Maybe you&#8217;re a Linux veteran trying Java for the first time. Maybe you&#8217;re new to both Java and Linux and you&#8217;re running some crappy program some other Java guy wrote. Whatever your background is, you now find yourself [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1072&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Your a Java developer and you&#8217;ve installed Linux. Maybe this is your first time converting from Windows. Maybe you&#8217;re a Linux veteran trying Java for the first time. Maybe you&#8217;re new to both Java and Linux and you&#8217;re running some crappy program some other Java guy wrote. Whatever your background is, you now find yourself staring at an unstatisfied link error. You don&#8217;t know what angered the link and you have no idea how to satisfy it. Hi, I&#8217;m <a href="http://codeforfun.wordpress.com/about">Cliff</a> and you&#8217;re here because you suck at satisfying links. But we already knew that, didn&#8217;t we? Does the error below look familiar?</p>
<p>java.lang.UnsatisfiedLinkError: Can&#8217;t load library: /usr/lib/jvm/java-6-openjdk/jre/lib/amd64/motif21/libmawt.so<br />
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1666)<br />
 at java.lang.Runtime.load0(Runtime.java:787)<br />
 at java.lang.System.load(System.java:1022)<br />
 at java.lang.ClassLoader$NativeLibrary.load(Native Method)<br />
 at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1767)<br />
 at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1684)<br />
 at java.lang.Runtime.loadLibrary0(Runtime.java:840)<br />
 at java.lang.System.loadLibrary(System.java:1047)<br />
 at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:67)<br />
 at sun.security.action.LoadLibraryAction.run(LoadLibraryAction.java:47)<br />
 at java.security.AccessController.doPrivileged(Native Method)<br />
 at java.awt.Toolkit.loadLibraries(Toolkit.java:1610)<br />
 at java.awt.Toolkit.(Toolkit.java:1632)</p>
<p>The long answer begins, &#8220;four score and seventeen (&#8230;seven? &#8230;several?) years ago&#8230;&#8221; and continues with babbling about openjdk and motif libs with a bunch of other nonsense you probably don&#8217;t particularly care about. The short story (which is also why you&#8217;re here listening to the most long-winded developer this side of the east coast that loves to insert rambling between parenthesis as if that makes any of his blog posts easier on the eyes&#8230;) is that you probably need to unset or set an environment variable. &#8220;export AWT_TOOLKIT=MToolkit&#8221; will cause the error while &#8220;export AWT_TOOLKIT=XToolkit&#8221; should make it go away. The environment variable controls which one of Linux&#8217;s windowing toolkits are used to draw the program on your screen. The MToolkit causes the Java program to look for the &#8220;libmawt.so&#8221; file which is a Motif Abstract Windowing Toolkit Shared Object, hence the &#8220;m-a-w-t.s-o&#8221; in the file name. Shared objects are the Linux way of sharing code. Other operating systems use other files. Windows uses &#8220;.dll&#8221; files, while Mac OSX uses &#8220;dylib&#8221; files. The Abstract Windowing Toolkit is the Java way of drawing programs on your screen which is abstract so that it can change the way the program looks and feels. Motif is one of the many looks of a java program, while others include &#8220;Native&#8221;, &#8220;Metal&#8221;, &#8220;Aqua&#8221; and others. Not all of these looks are available in each distribution of Java so chances are that you copied a program from a system (or developed a program for a system) that included the Motif look and feel and now you&#8217;re trying to run it on your fresh Linux install. </p>
<p>The good news is the problem is easy to fix once you know the how and why. The bad news is you&#8217;ll probably do something clever like putting &#8220;AWT_TOOLKIT=XToolkit&#8221; in your &#8220;~/.bash_profile&#8221; and forget this hack is in place which will likely cause other issues several months down the line when you want to toy with Compiz-Fusion but your IntelliJ editor is acting funny, locking up or going completely dark or something. That&#8217;s your good-news/bad-news for the day. Happy coding and clever hacking to you all.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1072/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1072/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1072/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1072&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/11/13/linux-cant-load-librarylibmawt-so/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Wave to me</title>
		<link>http://codeforfun.wordpress.com/2009/11/03/wave-to-me/</link>
		<comments>http://codeforfun.wordpress.com/2009/11/03/wave-to-me/#comments</comments>
		<pubDate>Tue, 03 Nov 2009 19:05:42 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1063</guid>
		<description><![CDATA[I received a Google Wave invite this morning from a friend and I was all excited and ready to jump in. You know that feeling you get when you put on your favorite hat and your best shoes, grab a six pack and run into the party but nobody&#8217;s there? Yeah, thats the feeling. It&#8217;s [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1063&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I received a Google Wave invite this morning from a friend and I was all excited and ready to jump in. You know that feeling you get when you put on your favorite hat and your best shoes, grab a six pack and run into the party but nobody&#8217;s there? Yeah, thats the feeling. It&#8217;s like the Music is playing but there&#8217;s no DJ on the turn tables. You got a full tank of gas, you mash the pedal but the transmission is slipping. It&#8217;s when you pour the most gigantimous bowl of Lucky Charms, grab the shovel from next to the microwave oven, dig it into the bowl then open the refrigerator door to find an empty milk carton. I&#8217;m not out of hope, if I gotta wave to complete strangers then that&#8217;s what I&#8217;ll do for now. It&#8217;d be much better if Google found a way to make it work with existing communications like AIM, email, MyBook and FaceSpace. Then people would have some use for it other than a place holder in an otherwise empty conversation, &#8220;&#8230;say y&#8217;know I got one uh dose G Wiz Googly Wave thing-a-ma-jigs&#8230; it&#8217;s awesome&#8230;&#8221;</p>
<p>If you&#8217;re in the same boat as I am, look for clifton.craig somewhere in the wave system. By the way, how do you search and find new contacts with this crazy thing? Until then, I&#8217;m waving but nobody&#8217;s waving back&#8230; holler&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1063/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1063/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1063/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1063/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1063/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1063/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1063/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1063/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1063/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1063/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1063&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/11/03/wave-to-me/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Hard to test things</title>
		<link>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 23:21:03 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone SDK]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[Objective C]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1059</guid>
		<description><![CDATA[So I&#8217;d been thinking. Because I&#8217;m back into iPhone development and getting warmed up not only to ObjC issues and errors but also C++ oddities, I&#8217;m wondering how do you write tests for some of the more difficult things to capture? For instance, I&#8217;ve figured out how to capture some of the manual reference counting [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1059&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>So I&#8217;d been thinking. Because I&#8217;m back into iPhone development and getting warmed up not only to ObjC issues and errors but also C++ oddities, I&#8217;m wondering how do you write tests for some of the more difficult things to capture? For instance, I&#8217;ve figured out how to capture some of the manual reference counting that&#8217;s required by CocoaTouch. (I assert that objects passed into other objects are properly retained and properly released when the object itself is released.) Still I can&#8217;t capture the more involved memory management problems. How do you assert an autorelease? What about dynamic memory allocation with pointers? I ended up with a single method that dynamically allocates for a pointer via malloc. I then changed it to use new with array notation. </p>
<p>void MySpecialObject::writeRequestToStream(CFStringRef aRequest, CFWriteStreamRef requestStream)<br />
{<br />
  if(CFWriteStreamGetStatus(requestStream) == kCFStreamStatusNotOpen) CFWriteStreamOpen(requestStream);<br />
  UInt8* convertedString =(UInt8*)convertToCString(aRequest);<br />
  CFWriteStreamWrite(requestStream, convertedString, CFStringGetLength(aRequest));<br />
  free(convertedString);<br />
}</p>
<p>It&#8217;s used in one spot so far and I&#8217;ve manually added the free without a prior failing test. I felt dirty. Assuming there were no call to free, how would you write a failing test for the code above? Is this just one of those things where you have to be extra careful? Maybe I should investigate the use of Velocity style code macros/templates that expand after keying special abbreviation similar to what we have in IntelliJ. I can imagine something like &#8220;cstr&#8221; expanding to:</p>
<p>char *myCStr = new char[size];<br />
// use myCStr here<br />
free(myCStr);</p>
<p>With the ability to tab through highlighting the variable name, declared size and commented insert code section. Any bright ideas?</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1059/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1059/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1059/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1059&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/28/hard-to-test-things/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Downgrade your iPhone DFU mode</title>
		<link>http://codeforfun.wordpress.com/2009/10/26/downgrade-your-iphone-dfu-mode/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/26/downgrade-your-iphone-dfu-mode/#comments</comments>
		<pubDate>Mon, 26 Oct 2009 13:15:24 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[DFU Mode]]></category>
		<category><![CDATA[firmware hacks]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone SDK]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1057</guid>
		<description><![CDATA[My iPhone crapped out on me this weekend. I went to use it and the screen wouldn&#8217;t show at all. I loaded iTunes which was able to recognize it and offer to restore it to factory. Word of advice, iTunes is very sneaky! I didn&#8217;t realize that the factory restore it offered came with a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1057&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>My iPhone crapped out on me this weekend. I went to use it and the screen wouldn&#8217;t show at all. I loaded iTunes which was able to recognize it and offer to restore it to factory. Word of advice, iTunes is very sneaky! I didn&#8217;t realize that the factory restore it offered came with a complimentary upgrade to OS 3.1.2! It became apparent after I went to use the device and swiped right revealing the new spotlight search. Crap! I needed to keep it on 2.2 because I need to verify 2.2 compatibility. No worries, I&#8217;l just down grade when I get to the office. I then realized that I couldn&#8217;t build and run on device using XCode. I was getting &#8220;No Provisioned device connected&#8221; errors. I got concerned thinking I had to go through the whole re-provisioning my device hassle. Then I realized the &#8220;use for development&#8221; button in XCode. One thing lead to another then I finally realized all of the ugly truths about iPhone development. </p>
<p>1. OS 3.1.2 only accepts builds from XCode with iPhone SDK 3.1.2.<br />
2. The iPhone SDK 3.1.2 only installs on OSX 10.6 (Snow Leopard)<br />
3. Apple no longer offers any iPhone OS earlier than 3.1.2 on its website.<br />
4. If you are lucky enough to find a lingering copy of iPhone OS 3.0 or earlier, you cannot roll back from 3.1.2 (&#8230;easily) due to baseband errors.<br />
5. DFU mode is not easy to do or understand.<br />
6. You will likely spend the good part of a couple of days trying to recover from an unintentional upgrade as your first 5-7 rollbacks will leave you with misc errors.</p>
<p>The simple answer is that you cannot downgrade the OS without using DFU mode. DFU stands for Device Firmware Upgrade and is a secret mode that Apple doesn&#8217;t want you to know about. You have to use something similar to the old Nintendo Contra cheat (you remember up, up, down, down, left, right, left, right, b, a&#8230;) to enable it. I&#8217;ve tried it a couple of times so far and realized that you probably should have a completely installed OS before trying it. My second attempt (after a fresh iTunes restore) left me with an error and I&#8217;m hoping the third time is a charm. Here goes nothing&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1057/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1057/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1057/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1057&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/26/downgrade-your-iphone-dfu-mode/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Classic vs Mockist, TDD vs BDD</title>
		<link>http://codeforfun.wordpress.com/2009/10/21/classic-vs-mockist-tdd-vs-bdd/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/21/classic-vs-mockist-tdd-vs-bdd/#comments</comments>
		<pubDate>Wed, 21 Oct 2009 17:00:18 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Agile]]></category>
		<category><![CDATA[Behavior Driven Development]]></category>
		<category><![CDATA[Test Driven Development (TDD)]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1055</guid>
		<description><![CDATA[I&#8217;ve been having constant issues with Behavior Driven Design using xUnit tools. For those that don&#8217;t know what behavior driven design means check out Dan North&#8217;s introduction. When writing tests you can choose from a number of approaches. I feel I&#8217;ve followed an evolutionary chain through the most popular. Most people start with CWT, or [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1055&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>I&#8217;ve been having constant issues with Behavior Driven Design using xUnit tools. For those that don&#8217;t know what behavior driven design means check out <a href="http://dannorth.net/introducing-bdd/">Dan North&#8217;s introduction</a>. When writing tests you can choose from a number of approaches. I feel I&#8217;ve followed an evolutionary chain through the most popular. Most people start with CWT, or Coding While Testing. This is an approach where the tests are written with the code, not necessarily before but along side. People take this &#8220;feel good&#8221; approach in order to cover their code with tests and to gain confidence that their code won&#8217;t break without them knowing why/where. Eventually tests become brittle and break all around and the tests become a burden to maintain. Some people evolve into TDD or Test Driven Design. This is where the test is written first in an attempt to achieve better design. When I evolved this far I was still struggling in the &#8220;implementation zone&#8221;. That&#8217;s where most developers get their mail delivered. The implementation zone is where the major concern is how things work. You can&#8217;t rest well unless you know exactly how things work beneath a method call. There are no surprises because everything is understood. Doing TDD while living here leads to &#8220;White Box&#8221; tests. These are tests that mirror the implementation of the system. These test scream immediately when the system change in the slightest. It&#8217;s no fun. </p>
<p>Later I learned about the Behavior Driven approach which lead to my understanding DSLs, or Domain Specific Languages. Actually I picked up my understanding of DSLs when I started using JMock, which is still one of my favorite tools. I started to remember why programming languages were invented. &#8220;Code is for Humans&#8221; became my mantra. I stopped caring about <em>how</em> code worked and started concerning myself with <em>why</em> code was written. With today&#8217;s systems rivaling NASA in their complexity it becomes impossible to obsess over every implementation detail. It&#8217;s more natural to trust that something works through an automatable specification that says it works. Its hard to put in English, but there&#8217;s a subtle difference in how I look at code compared to how I see most of my co-workers look at code. I rely on a system of trust which helps both in design and in debugging. I digress.</p>
<p>This morning I began reading Martin Fowler&#8217;s revised <a href="http://martinfowler.com/articles/mocksArentStubs.html">write up on Mocks vs. Stubs</a>. If you do any automated testing of your system at all I demand you read this article. If you&#8217;ve read it in the past (as I had) I demand you read it again because it&#8217;s updated. If you read it last week then I demand you read it to your 5 year old tonight at bed time. The point is that Martin makes very good distinctions on what he calls classic TDD and Mockist TDD. He explains the difference between state verification and behavior verification. He explains it in a way that shocked me, because I&#8217;d classify myself as a mockist. The entire time I obsessed over implementation being secondary to design I see how and why the mockist frame of thought can easily shackle your design to your implementation details. I almost wanted to change ships, jump on the classical bandwagon. However the article very fairly points out several flaws in both approaches while not condemning either. In the end the choice is left to you. Well done Martin. Well done.</p>
<p>I titled this post, &#8220;Classic vs Mockist, TDD vs BDD&#8221; not to align BDD with the mockist approach though it fits better. The truth is that you can use Martin&#8217;s classic TDD style when doing BDD and vice versa. There really isn&#8217;t much of a difference between classic or mockist, TDD or BDD. It&#8217;s all really a matter of style as all these approaches aim in the same direction. Its similar to comparing Baptist to Methodist religions. There are differences but one is not more true than the other and its the faith or general direction that both point to that makes them equally as important. Here&#8217;s what&#8217;s really important.</p>
<p>Back to my problem. I posted on Stack overflow yesterday asking the question of <a href="http://stackoverflow.com/questions/1595952/how-to-write-tests-without-so-many-mocks">how to avoid so many mocks</a>. I have yet to receive a solution to the core problem I&#8217;m seeing. If you or someone you know has a mastery of TDD please chime in. I&#8217;d love to finally have a good discussion on how to solve a complex problem using the practice. I feel like I&#8217;m 80% there but I&#8217;m missing one piece of the pie.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1055/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1055/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1055/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1055/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1055/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1055/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1055/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1055/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1055/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1055/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1055&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/21/classic-vs-mockist-tdd-vs-bdd/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>How to go really really slow at programming</title>
		<link>http://codeforfun.wordpress.com/2009/10/19/how-to-go-really-really-slow-at-programming/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/19/how-to-go-really-really-slow-at-programming/#comments</comments>
		<pubDate>Mon, 19 Oct 2009 23:16:24 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Subversion]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1053</guid>
		<description><![CDATA[This morning I spent 10 minutes answering &#8220;ok&#8221; to 65,536 dialogs in Finder. This is the direct result of used the latest thing. I don&#8217;t do like I used to. I used to install bleeding edge software and constantly run around with napkins as my nose dripped red goo. I&#8217;ve learned my lesson. I now [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1053&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>This morning I spent 10 minutes answering &#8220;ok&#8221; to 65,536 dialogs in Finder. This is the direct result of used the latest thing. I don&#8217;t do like I used to. I used to install bleeding edge software and constantly run around with napkins as my nose dripped red goo. I&#8217;ve learned my lesson. I now know to install software only after its been battle tested and at least 1/2 of my coworkers are using it. So what has happened? What I used was the latest version of SVN support in Versions&#8230; 1.6 support. It&#8217;s not what I would call bleeding edge. Version 1.6 of svn has been around long enough. It&#8217;s battle tested and proven. Why then do I have exactly 65,536 ok dialogs scattered across my screen, each informing me that &#8220;my client is too old to work with&#8230;&#8221;? And how did I know that there were exactly 65,536 dialogs? (An exercise left to the reader&#8230; YOU! Not your RSS reader!) A long time ago I installed a Tortoise-like plugin for Finder. It gives you little folder decorations for things that are up to date in svn, checked out, conflicting or whatever. I forget the name of the app. It was so long ago that I&#8217;ve since forgotten and lost the installer. I don&#8217;t even know if there&#8217;s an uninstaller. (Which reminds me&#8230; why is it soo difficult to remove software from a Mac?) Still it helps me. It&#8217;s one of those nice to have things that help but doesn&#8217;t do the job entirely. So this tool has been hanging around assiting Finder for the past year or so and keeping me out of trouble when I attempt to delete old work that I&#8217;m not sure is under a VCS. After I switched Versions to use 1.6 format for its checkouts I started getting these dialogs. I didn&#8217;t know which tool they were coming from because I also use IntelliJ which includes its own svn support. Also I&#8217;ve since irreparably hacked XCode to work with svn 1.5. The dialog could have been coming from any of these three svn related tools. (I&#8217;d completely forgotten about the Finder plugin.) So I restarted versions a few times which seemed to remedy the problem. I was sure it was a Versions problem because I had other minor glitches since taking a recent Versions upgrade. By the time I figured out the Finder plugin was the problem I was already in knee deep. Unable to delete the 4-5 projects checked out in 1.6 format. Today I got a small break and decided to address the problem. It took me 5-10 minutes to fix because I had to first answer ok to each dialog. Then I had to delete and checkout the projects again. I also had to delete and checkout the projects again after realizing I forgot to change the Versions flag before the first delete/checkout cycle.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1053/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1053/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1053/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1053&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/19/how-to-go-really-really-slow-at-programming/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>Let&#8217;s rewrite Hudson from scratch!</title>
		<link>http://codeforfun.wordpress.com/2009/10/16/lets-rewrite-hudson-from-scratch/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/16/lets-rewrite-hudson-from-scratch/#comments</comments>
		<pubDate>Fri, 16 Oct 2009 23:22:56 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[build systems]]></category>
		<category><![CDATA[complexity]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1051</guid>
		<description><![CDATA[Because I have nothing better to do with the eight hours I spend in my company&#8217;s office building I felt it would be a great idea to sit down in from of a vi prompt and rewrite the Hudson build server all over again! From scratch! With no syntax highlighting! Without help from any of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1051&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p>Because I have nothing better to do with the eight hours I spend in my company&#8217;s office building I felt it would be a great idea to sit down in from of a vi prompt and rewrite the Hudson build server all over again! From scratch! With no syntax highlighting! Without help from any of its core dev team! Ain&#8217;t I cool? Hi, <a href="http://codeforfun.wordpress.com/about">I&#8217;m Cliff</a>. You&#8217;re here because you too would like to waste hours of development time toiling over a build tool or IDE setting for years&#8230; just to make it do what it was doing three weeks ago before the system admins decided to switch all network traffic to route through a SOCKs server then through an authenticating HTTP proxy which is managed by a complicated key based 256bit encryption mechanism hosted on a Novell server that mandates each employee drive across the parking lot.. in the rain&#8230; and place their thumb on a high-tech print-scanner to acquire a key that is only valid for 2 1/2 hours after which the entire process must be repeated to continue accessing private company systems. Yeah, that&#8217;s why you&#8217;re here. That&#8217;s why I&#8217;m here too. After all, if you don&#8217;t get that one particular tool working the rest of your life will be a living nightmare of, &#8220;why am I not getting optimal results? Oh yeah, it&#8217;s because I forgot to do the manual 37 step process just before checking my changes into svn. Lets add step number 38 to prevent the disaster that just occurred last Wednesday when we tried to demo for our CEO.&#8221;</p>
<p>On to today&#8217;s topic. No I didn&#8217;t actually decide to rewrite Hudson. I just got tasked with figuring out why we don&#8217;t have CI in our project. That turned into the, &#8220;oh yeah it&#8217;s because this part of our project runs on a later version of Hudson.&#8221; That became, &#8220;why can&#8217;t we downgrade?&#8221; Which was answered with, &#8220;because we put so many man hours into getting to this point all of which would need repeating.&#8221; this ultimately turned into a hack that depends on Bazaar brilliance. The hack intermittently falls over so it became my job to revisit why we can no longer use normal subversion tools. When I got deep into this task I found myself staring into a vi prompt on a Linux machine looking at the Java source code which propels Hudson into action. Its bad enough that I made several failed attempts to build Hudson from source on my Mac each which consumed valuable CPU cycles and upwards of 10-20 minutes. It became really painful when I knew I had to point Linux through ssh at the several hundred megabyte (Gigabyte?) source package sitting on my Mac. Why not just checkout the source directly in Linux? Well the initial checkout took hours on my Mac and I wasn&#8217;t sure whether it was due to rainy conditions in the weather or client side bandwidth or slow server side response time and I wasn&#8217;t willing to do yet another bout of research just to get the answer to question which really isn&#8217;t critical. So here I am, looking at Java source and unable to rapidly navigate it as I could in IntelliJ Idea. Its a sea of text and I&#8217;m lost in the middle without a clue. I have Spotlight which pin-pointed the location that needs to be fixed. but I have no confidence that the build I execute is responsible for the war file that I ultimately collect because this war file is in a non-standard location. Also, the instructions for building this war file are comparable in complexity to the non-standard structure of the project. This structure is, in turn, comparable to the complexity of the source code. I&#8217;m lost, frustrated, and I just want it to work. On a good day (a Monday) I&#8217;d love to obsess over how the Hudson team has managed to tackle whatever problem that lead to the complexity that is their current build system. But on a bad day (a Friday) I only care that the end result of their build system can find the source code that is locked behind yet another ocean of complicated security constraints. I just want things to work. I don&#8217;t want to learn their interiors. I want them to do the thing I they were designed to to.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1051/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1051/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1051/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1051/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1051/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1051/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1051/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1051/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1051/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1051/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1051&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/16/lets-rewrite-hudson-from-scratch/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
		<item>
		<title>AssertRunsInAnotherThread ?</title>
		<link>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/</link>
		<comments>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/#comments</comments>
		<pubDate>Wed, 14 Oct 2009 01:55:39 +0000</pubDate>
		<dc:creator>Cliff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[iPhone]]></category>
		<category><![CDATA[iPhone TDD]]></category>
		<category><![CDATA[Objective C]]></category>
		<category><![CDATA[Objective C unit tests]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://codeforfun.wordpress.com/?p=1038</guid>
		<description><![CDATA[**Update**
I&#8217;ve updated my example below after realizing I left out some important pieces&#8230;
**Update**
How do you assert that something runs in a different thread? Or more generically, how do you assert that something runs asynchronously? I need to do this in ObjC but also in Java. The scenario is as follows. I have a WhatzItz object [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1038&subd=codeforfun&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<div class='snap_preview'><br /><p><strong>**Update**</strong><br />
I&#8217;ve updated my example below after realizing I left out some important pieces&#8230;<br />
<strong>**Update**</strong></p>
<p>How do you assert that something runs in a different thread? Or more generically, how do you assert that something runs asynchronously? I need to do this in ObjC but also in Java. The scenario is as follows. I have a WhatzItz object instance stored in myWhatzItz. I tell myWhatzItz to doDisThing. I need to specify that myWhatzItz will doDisThing asynchronously. Experience tells the story that multi-threaded unit tests are dumb, complicated and wrong. So asking myWhatzItz to doDisThing then waiting or polling for completion of doDisThing is not what we want to do here. (It may be what you want to do but it&#8217;s not what I want. Since we&#8217;re on the same team and since I&#8217;m doing the writing you have to want what I want not what you want. I <em>want</em> you to want my wants&#8230; forget your wants&#8230; your wants are dumb anyhow!)</p>
<p>So how do we design myWhatzItz to doDisThing and doDisThing right? I&#8217;m going to suggest an interface&#8230; err prototcol. That is an abstraction for what we want to design. In unit testing we stay focused on one thing. All distractions are tossed behind abstractions. So after asking myWhatzItz to doDisThing I need to assert that it uses asynchronous behavior. That brings us a step back. I have to design a dependency on asynchronous behavior first. Right now you&#8217;re probably wondering how asynchronous behavior works. Right now I&#8217;m &#8217;bout to slap you like Bruce Lee slapped that boy in Enter the Dragon. (Or was that Return of the Dragon? Maybe it was the game of death? Bonus points to the 1st person that gets the movie correct with a link to the clip on YouTube!) &#8220;Don&#8217;t focus on the finger or you&#8217;ll miss the beauty in the sky above!&#8221;, says Bruce. We <em>don&#8217;t care</em> about how asynchronous behavior works, as its irrelevant to our design. We only care that our work is done asynchronously! So we&#8217;ll code this test in ObjectiveC:</p>
<pre class="brush: cpp;">
#import
@protocol MyAsynchronousBehavior
-(void) performAsynchronously:(SEL) aSelctor onTarget:(id)aTarget withObject:(id)anObject;
@end

@interface MyWhatzItzTest : SenTestCase &lt;MyAsynchronousBehavior&gt;
{
  MyWhatzItz *myWhatzItz;
  SEL selectorPerformed;
  id targetForSelector;
  id parameterForSelector;
  int performAsynchronouslyInvocationCount;
}
@end

@implementation MyWhatzItzTest

-(void) setUp
{
   myWhatzItz = [[MyWhatzItz alloc] init];
   //The test uses the self-shunt pattern to listen for MyAsynchronousBehavior interaction.
   id theAsynchronousBehavior = self;
   myWhatzItz.asynchronousBehavior = theAsynchronousBehavior;
}

-(void) testMyWhatzItzWillAsynchronouslyDoDisThingWhenAskedToDoDatThing
{
  STAssertEquals(performAsynchronouslyInvocationCount, 0, @&quot;Assuming that we haven't been asked to performAsynchronously&quot;);
  [myWhatzItz doDatThing];
  STAssertEquals(performAsynchronouslyInvocationCount, 1, @&quot;We SHOULD HAVE been asked to performAsynchronously&quot;);
  STAssertEquals(selectorPerformed, @selector(doDisThing:), @&quot;Should have asked to doDisThing using asynchronous behavior.&quot;);
  STAssertEquals(targetForSelector, myWhatzItz, @&quot;Should use myWhatzItz for asynchronous execution.&quot;);
}
@end
#pragma mark MyAsynchronousBehavior protocol methods
-(void) performAsynchronously:(SEL) aSelctor onTarget:(id)aTarget withObject:(id)anObject
{
  performAsynchronouslyInvocationCount++; selectorPerformed = aSelctor; targetForSelector = aTarget; parameterForSelector = anObject;
}
</pre>
<p>Supplying the asynchronous behavior becomes a construction/intialization concern, which could be extracted into a wiring framework like Interface Builder (or if you do Java, Springframework). The nice thing is that we can alternate our asynchronous behavior without touching the rest of the project. We can do something quick/dirty like detachThread&#8230; and later get more elegant with RunLoops. Today&#8217;s tip comes to you (me) completely by accident. I&#8217;ve been trying to test drive things in Java and ObjC for several years now and I&#8217;ve never got this part quite right. Feel free to share your opinions/experiences with threads and tests.</p>
<p><strong>**Update**</strong><br />
The above example demonstrates a few important unit testing concepts. first it uses the self-shunt pattern to allow the test to become a mock and listen for interactions between the tested object and its collaborator(s). Second, it demonstrates the importance of using tests to carve out the pieces that should NOT be under test. In this situation it&#8217;s multi-tasking, however in other scenarios it could be anything from a DBMS to a network call. I could have illustrated an example where I spin up a Thread pool of some sort from within the test started work, paused the main thread and waited for a response. That&#8217;s what I&#8217;ve done in the past and it becomes extremely complicated and brittle. In stead, I use the elegance of abstraction to make the test 100% predictable, 200% more simplistic, and 300% more maintainable. Where do I get those statistics? The short answer is they&#8217;re sequential. (The long story begins yesterday when my 5yr old spontaneously decided to count from 1 to infinity in the middle of our shopping trip. You see, she only recently learned her numbers up to 100 and after getting to 199 we all realized the child&#8217;s computational limits as she continued with one hundred one hundred then followed up with one hundred one hundred one, one hundred one hundred two&#8230;)<br />
<strong>**Update**</strong></p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/codeforfun.wordpress.com/1038/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/codeforfun.wordpress.com/1038/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/codeforfun.wordpress.com/1038/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=codeforfun.wordpress.com&blog=228419&post=1038&subd=codeforfun&ref=&feed=1" /></div>]]></content:encoded>
			<wfw:commentRss>http://codeforfun.wordpress.com/2009/10/13/assertrunsinanotherthread/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/11e7597f889f569d804b6f8c79e60e6a?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">Cliff</media:title>
		</media:content>
	</item>
	</channel>
</rss>