<?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>Nerd Fortress &#187; Kurt</title>
	<atom:link href="http://nerdfortress.com/author/kgriffs/feed/" rel="self" type="application/rss+xml" />
	<link>http://nerdfortress.com</link>
	<description>Esoteric How-to&#039;s, Essays, and Rand();</description>
	<lastBuildDate>Mon, 21 May 2012 19:55:22 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='nerdfortress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Nerd Fortress &#187; Kurt</title>
		<link>http://nerdfortress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://nerdfortress.com/osd.xml" title="Nerd Fortress" />
	<atom:link rel='hub' href='http://nerdfortress.com/?pushpress=hub'/>
		<item>
		<title>Ruby vs. Python vs. PyPy: Is Ruby Slower than Python for Web Development?</title>
		<link>http://nerdfortress.com/2011/09/05/ruby-vs-python-vs-pypy-is-ruby-slower-than-python-for-web-development/</link>
		<comments>http://nerdfortress.com/2011/09/05/ruby-vs-python-vs-pypy-is-ruby-slower-than-python-for-web-development/#comments</comments>
		<pubDate>Mon, 05 Sep 2011 16:45:32 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Codealicious]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1425</guid>
		<description><![CDATA[If you are into programming languages, you&#8217;ve probably heard people talk about how slow Ruby is, and how you should use Python instead. I&#8217;ve always loved Ruby&#8217;s beautiful syntax. On the other hand, Python isn&#8217;t that ugly, and it&#8217;s hard to argue with raw speed. Ruby 1.9 brought major performance improvements to the table, and recently [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1425&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>If you are into programming languages, you&#8217;ve probably heard people talk about how slow Ruby is, and how you should use Python instead. I&#8217;ve always loved Ruby&#8217;s beautiful syntax. On the other hand, Python isn&#8217;t <em>that</em> ugly, and it&#8217;s hard to argue with raw speed.</p>
<p>Ruby 1.9 brought major performance improvements to the table, and recently I got a chance to sit down and do some web service benchmarking. Based on my tests, the tradeoff between beauty and performance isn&#8217;t as big as it used to be, but there&#8217;s still some work to be done.</p>
<p>Here is what I did.</p>
<p>First, I implemented basic &#8220;Hello World&#8221; apps using the standard web server interfaces for each language; <a title="Python WSGI Documents" href="http://www.wsgi.org/wsgi/" target="_blank">WSGI</a> for Python and <a title="Ruby Rack Interface" href="http://rack.rubyforge.org/" target="_blank">Rack</a> for Ruby.</p>
<p><pre class="brush: ruby;">
# Ruby: Simple Rack app
require 'rack'

class HelloWorld
  def call(env)
    [200, {&quot;Content-Type&quot; =&gt; &quot;text/plain&quot;}, [&quot;Hello Rack!&quot;]]
  end
end
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: python;">
# Python: Simple WSGI app
def simple_app(environ, start_response):
  start_response('200 OK[', [('Content-type','text/plain')])
  return ['Hello world!\n']
</pre></p>
<p>I also tested a simple Python app using Rawr, a fairly well-tuned WSGI/webob micro framework that I developed for Rackspace. Last&#8211;but not least&#8211;I also benchmarked a simple &#8220;Hello World&#8221; <a title="Ruby Sinatra Web Micro-framework" href="http://www.sinatrarb.com/">Sinatra</a> app so I would have something to compare against Rawr.</p>
<p><pre class="brush: ruby;">
# Ruby: Sinatra app showing tested route
require 'sinatra'

get '/hello' do
  'Hello world!'
end
</pre></p>
<p>&nbsp;</p>
<p><pre class="brush: python;">
# Python: Rawr app showing tested route
from rax.http import rawr

class HealthController(rawr.Controller):
  &quot;&quot;&quot;Provides web service health info&quot;&quot;&quot;

def get(self):
  self.response.write(&quot;Alive and kicking!\n&quot;)

class TestApplication(rawr.Rawr):
  &quot;&quot;&quot;Test class for encapsulating initialization&quot;&quot;&quot;

  def __init__(self):
    rawr.Rawr.__init__(self)

    # Setup routes
    self.add_route(r&quot;/health$&quot;, HealthController),

app = TestApplication()
</pre></p>
<h2>Ruby vs. Python: Web Performance</h2>
<p>Everything was benchmarked by running multiple iterations of apache-bench from the terminal on my MBP. I used <a title="Green Unicorn Python Web Server" href="http://gunicorn.org/" target="_blank">Green Unicorn</a> as my test WSGI server, and <a title="Thin Ruby Web Server" href="http://code.macournoyer.com/thin/" target="_blank">Thin</a> for Rack apps.</p>
<p>WSGI (PyPy 1.6.0): ~5300 req/sec<br />
WSGI (Python 2.6.1): ~3200 req/sec<br />
WSGI (Python 2.7.2): ~3000 req/sec</p>
<p>Rack (Ruby 1.9.2 MRI):  ~4500 req/sec<br />
Rack (Ruby 1.8.7 MRI): ~4050 req/sec</p>
<p>Rawr/WSGI (PyPy 1.6.0): ~4900 req/sec<br />
Rawr/WSGI (Python 2.6.1): ~2750 req/sec<br />
Rawr/WSGI (Python 2.7.2): ~2700 req/sec</p>
<p>Sinatra/Rack (Ruby 1.9.2 MRI): ~1900 req/sec<br />
Sinatra/Rack (Ruby 1.8.7 MRI): ~1399 req/sec</p>
<h2>Ruby vs Python: Conclusions</h2>
<p><strong>Rack perf beats WSGI</strong> hands-down for standard Python (hooray!), although it is unclear how much of the difference is due to Green Unicorn vs. Thin. <a title="PyPy alternative Python implementation" href="http://pypy.org/" target="_blank">PyPy</a> is astoundingly fast, but Ruby 1.9.2 isn&#8217;t too far behind.</p>
<p>Also, it was interesting to see what a difference Ruby 1.9 made when there was a lot of code to run through (Sinatra). This difference can also be seen in the Rawr tests with PyPy vs. standard Python.</p>
<p>The <strong>bad news</strong> is that Sinatra was significantly slower than Rawr (booh!). Given the benchmarks for a straight Rack app, I have to wonder whether a Ruby port of Rawr is in order.</p>
<p><em>Note: This article outlines a simple test of GETs returning small amounts of text. Before choosing a language for your next project, you will undoubtedly want to do more extensive testing, especially around concurrency, object serialization, request/response body size, and POST/PUT performance. You should also see how things look when you put everything behind a reverse proxy and/or load balancer, such as Nginx.</em></p>
<br />Filed under: <a href='http://nerdfortress.com/category/codealicious/'>Codealicious</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1425/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1425/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1425/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1425&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2011/09/05/ruby-vs-python-vs-pypy-is-ruby-slower-than-python-for-web-development/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
		<item>
		<title>Ruby on Rails Pros and Cons: Redux</title>
		<link>http://nerdfortress.com/2011/08/19/ruby-on-rails-pros-and-cons-redux/</link>
		<comments>http://nerdfortress.com/2011/08/19/ruby-on-rails-pros-and-cons-redux/#comments</comments>
		<pubDate>Fri, 19 Aug 2011 21:04:05 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Essays]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1416</guid>
		<description><![CDATA[I&#8217;m getting ready to start a new project using Ruby 1.9 and Rails 3.x. that will give me some good info to use in updating this old article on RoR pros and cons. In the meantime, I just wanted to take a moment to summarize my current thoughts on the Ruby+POSIX vs. .NET+Microsoft stacks, having [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1416&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m getting ready to start a new project using Ruby 1.9 and Rails 3.x. that will give me some good info to use in updating this old article on <a title="Ruby on Rails Pros and Cons: Let’s Get Real" href="http://nerdfortress.com/2008/05/13/ruby-on-rails-pros-cons-lets-get-real/" target="_blank">RoR pros and cons</a>.</p>
<p>In the meantime, I just wanted to take a moment to summarize my current thoughts on the Ruby+POSIX vs. .NET+Microsoft stacks, having spent the last several years jumping back and forth between the two ecosystems.</p>
<p>Core dump:</p>
<ul>
<li>Visual Studio is extremely powerful. Their debugger is heads and shoulders above gdb, rdb, and pretty much any other *db on the planet.</li>
<li>Static typing and compiled code is a nice security blanket when it comes to typos and refactoring. Yes, I&#8217;m addicted.</li>
<li>Every Microsoft event I&#8217;ve been to in the last several years has felt stiff and enterprisey. The ecosystem is definitely headed more towards the world of IBM and Oracle, and farther away from the world of Apple and Google.</li>
<li>The higher the suits/t-shirts ratio, the less fun and interesting things get. Microsoft isn&#8217;t fun anymore.</li>
<li>On the other hand, the open-source/POSIX community is becoming more fun and interesting all the time. The community is vibrant, inventive, and supportive. They are more interested in the joy of the craft than in making a buck (although they do that too).</li>
<li>The RoR community has grown up a lot in the past few years. We now have lots of lessons-learned and best practices to reference.</li>
<li>CodePlex and NuGet are steps in the right direction, but aren&#8217;t really changing the wider Microsoft culture.</li>
<li>MongoDB? Awesome. Linux? Awesome. Nginx? Awesome. Ruby 1.9? Awesome. Vim? Debatable. <img src='http://s1.wp.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </li>
<li>With the advent of Ruby 1.9, performance is now good enough. Character encoding woes are a thing of the past. The only thing I miss is my compiled-code security blanket. On the other hand, RSpec and Cucumber give me warm fuzzies.</li>
<li>It&#8217;s a real shame that Python seems to be winning the mindshare war over Ruby. In my own experience and not-so-humble-opinion, Ruby is far more elegant, and package management is better. Python feels like a strange marriage of PHP and Ruby. The only thing that tempts me about Python is it&#8217;s speed (esp. PyPy), but recent releases of Ruby are fast enough for my needs.</li>
</ul>
<p>Bottom line: The better performance and IDE are no longer as compelling an argument to stick with the .NET stack.</p>
<p><em>But wait! There&#8217;s hope! Nancy, Mono, Owin, etc. provide evidence that the .NET community is taking matters into their own hands. Stay tuned&#8230;</em></p>
<br />Filed under: <a href='http://nerdfortress.com/category/essays/'>Essays</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1416/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1416/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1416/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1416&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2011/08/19/ruby-on-rails-pros-and-cons-redux/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
		<item>
		<title>Indie Game Cloud: Public Beta</title>
		<link>http://nerdfortress.com/2011/07/11/indie-game-cloud-public-beta/</link>
		<comments>http://nerdfortress.com/2011/07/11/indie-game-cloud-public-beta/#comments</comments>
		<pubDate>Mon, 11 Jul 2011 21:14:25 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Indie Games]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1404</guid>
		<description><![CDATA[&#60;shamelessplug&#62; If you&#8217;re a game hacker (or know someone who is), check out my startup. We just launched the Indie Game Cloud Public Beta, and I&#8217;d love your help spreading the word. Thanks in advance! http://www.gammeta.com &#60;/shamelessplug&#62; Filed under: Indie Games<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1404&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>&lt;shamelessplug&gt;</p>
<p>If you&#8217;re a game hacker (or know someone who is), check out my startup. We just launched the Indie Game Cloud Public Beta, and I&#8217;d love your help spreading the word.</p>
<p>Thanks in advance!</p>
<p><a title="Indie Game Cloud" href="http://www.gammeta.com" target="_blank">http://www.gammeta.com</a></p>
<p>&lt;/shamelessplug&gt;</p>
<br />Filed under: <a href='http://nerdfortress.com/category/indie-games/'>Indie Games</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1404/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1404/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1404/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1404&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2011/07/11/indie-game-cloud-public-beta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
		<item>
		<title>When and How to Use Singletons</title>
		<link>http://nerdfortress.com/2011/03/29/when-to-use-the-singleton-design-pattern/</link>
		<comments>http://nerdfortress.com/2011/03/29/when-to-use-the-singleton-design-pattern/#comments</comments>
		<pubDate>Tue, 29 Mar 2011 14:07:11 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Codealicious]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1363</guid>
		<description><![CDATA[Is the singleton design pattern inherently flawed? I don&#8217;t think so. Can you abuse the singleton pattern? Certainly. Can you use it effectively? Absolutely. A few questions I ask myself when deciding whether singletons really should be singletons: Is the singleton external to my app? Databases, queuing services, and ESBs are all perfectly valid macro examples of [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1363&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://neil.fraser.name/"><img class="alignright size-thumbnail wp-image-1373" title="Photographs Not Allowed by Neil Fraser" src="http://nerdfortress.files.wordpress.com/2011/03/nophoto-neil-fraser-name.jpg?w=150&h=112" alt="Sometimes you have to break conventional wisdom with the singleton design pattern" width="150" height="112" /></a>Is the singleton design pattern <a title="Are Singletons a Bad Idea?" href="http://stackoverflow.com/questions/1020312/are-singletons-really-that-bad/1020384#1020384" target="_blank">inherently flawed</a>? I don&#8217;t think so.</p>
<p>Can you abuse the singleton pattern? Certainly. Can you use it effectively? Absolutely.</p>
<p>A few questions I ask myself when deciding whether singletons <em>really should</em> be singletons:</p>
<ol>
<li>Is the singleton external to my app? Databases, queuing services, and ESBs are all perfectly valid macro examples of the singleton pattern.</li>
<li>KISS: Is my entire app limited to 2-3 internal singletons?</li>
<li><a title="Learn other ways to apply DRY by reading the Pragmatic Programmer " href="http://amzn.to/hgRULZ" target="_blank">DRY</a>: Are my singletons inherently global? In other words, if they <em>weren&#8217;t</em> singletons, would I have to plumb references to them into almost every object? (e.g., a logger or mediator)?</li>
<li>Do my singletons depend only on each other, and/or the operating environment?</li>
<li>Have I ensured proper start-up and shut-down sequences for each singleton, including memory management considerations? For example, a &#8220;Grand Central&#8221;-style thread pool may require Run() and Shutdown() methods. These methods would be invoked during app startup and shutdown, so that tasks are guaranteed to run only when the objects they operate on are in a valid state.</li>
</ol>
<div><strong><br />
</strong></div>
<br />Filed under: <a href='http://nerdfortress.com/category/codealicious/'>Codealicious</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1363/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1363/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1363/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1363&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2011/03/29/when-to-use-the-singleton-design-pattern/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>

		<media:content url="http://nerdfortress.files.wordpress.com/2011/03/nophoto-neil-fraser-name.jpg?w=150" medium="image">
			<media:title type="html">Photographs Not Allowed by Neil Fraser</media:title>
		</media:content>
	</item>
		<item>
		<title>You say semaphore, I say mutex</title>
		<link>http://nerdfortress.com/2011/02/18/you-say-semaphore-i-say-mutex/</link>
		<comments>http://nerdfortress.com/2011/02/18/you-say-semaphore-i-say-mutex/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 14:10:11 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Codealicious]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1263</guid>
		<description><![CDATA[Suppose you are interviewing a candidate&#8211;let&#8217;s call him Ben&#8211;for a programming job and you ask the well-worn question:   What&#8217;s the difference between a mutex and a semaphore? Ben:   The difference between a mutex and a semaphore? Well, a mutex allows only one thread at a time, while a semaphore can allow several threads [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1263&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Suppose you are interviewing a candidate&#8211;let&#8217;s call him Ben&#8211;for a programming job and you ask the well-worn question:<br />
<code> </code></p>
<blockquote><p>What&#8217;s the difference between a mutex and a semaphore?</p></blockquote>
<p>Ben:<br />
<code> </code></p>
<blockquote><p>The difference between a mutex and a semaphore? Well, a mutex allows only one thread at a time, while a semaphore can allow several threads to run at the same time.</p></blockquote>
<p>Now, you&#8217;d like to probe a little deeper, so you follow up with:<br />
<code> </code></p>
<blockquote><p>OK. Can you give me an example of when you would use a semaphore instead of a mutex?</p></blockquote>
<p>Ben thinks for a moment. This one&#8217;s a little harder to answer, but he remembers something he read once on the Internets:<br />
<code>  </code></p>
<blockquote><p>Yeah, sure. You would use a semaphore when you need to control access to more than one resource. For example, if you&#8217;ve got a gas station with one restroom, you would only need one key, since only one person at a time can use the bathroom. You could use a mutex for that, which is basically just a binary semaphore.</p>
<p>Now, if your gas station had more than one restroom, you would need to use a semaphore so that more than one person could take care of business at the same time.</p></blockquote>
<p>Not bad. But there&#8217;s a better answer.</p>
<p>The differences between a semaphore and a mutex are more subtle than most programmers realize. And, as we all know, Subtle Things have a way of turning themselves into Bad Things when nobody happens to be paying attention to them. Fortunately, you can (mostly) avoid the whole mess by following two simple rules of thumb:<br />
<code> </code></p>
<blockquote><p>Thow shalt use the mutex to protect all thy possessions that thou hast in common among you. This is the first and greatest commandment, and the second is like unto it. Thou shalt use the mutex and the condition variable to signal all thy workers in the field.</p>
<p>On these two commandments hang all the threads and the programs.</p></blockquote>
<p>Semaphores have two traits that are particularly problematic. First, semaphores&#8211;as opposed to mutexes&#8211;have no notion of lock ownership. In other words, one thread can unlock a semaphore that was previously locked by a different thread. This is <em>bad mojo</em>.</p>
<p>In my house I have a very active 2-year old son. Now, as you may or may not know, 2-year olds are (a) too old to sleep in cribs (they just climb out), and (b) too young to stay put in a regular bed. This poses some unfortunate challenges at bed time. The solution? Turn out the lights and lock the bedroom door! Hooray! Eventually the kid will get bored and go to sleep! (This is what sleep-deprived parents everywhere desperately pray, as they lie silently in their beds.)</p>
<p>Unfortunately, 2-year olds have one more trait I didn&#8217;t mention: they are, without a doubt, too smart for their own good. This situation is compounded by the fact that the toddler in question happens to share his room with a big-brother (6 years old), who understandably finds it less-than-ideal to be locked in his own room, and who is also too smart for his own good.</p>
<p>It doesn&#8217;t take long for Big Brother to hack his way out of the room using a clip-on tie (hey, they&#8217;re stylish <em>and</em> practical!).</p>
<p>Semaphores, as it turns out, are surprisingly similar to locks on bedroom doors of ambitious children. It is really hard to ensure that once one thread (Dad) locks a semaphore, you don&#8217;t &#8220;accidentally&#8221; get another thread (Big Brother) unlocking it.</p>
<p>But wait! There&#8217;s more! Semaphores have yet one more issue, related to the first. It&#8217;s called Priority Inversion™. There&#8217;s actually a great little <a title="Priority Inversion and Semaphores" href="http://msdn.microsoft.com/en-us/library/aa450594.aspx">Windows CE article</a> (yes, Windows CE of all things) over at MSDN that does a decent job explaining the problem:<br />
<code>  </code></p>
<blockquote><p><em>Priority inversion</em> occurs when a mutex, critical section, or semaphore resource held by a lower-priority thread delays the execution of a higher-priority thread when both are contending for the same resource.</p>
<p>For mutexes and critical sections, to correct this situation and free the higher-priority thread, with priority inheritance, Windows CE enables the lower-priority thread to inherit the more critical thread&#8217;s priority and run at the higher priority until it releases its use of the resource. This mechanism does not work for semaphores, which do not have a specific owner associated with them. Therefore, priority inversion may occur when using semaphores.</p>
<p>Because an unbounded amount of time is needed to relinquish the inverted thread and it is out of the control of the kernel, the OEM loses control of the scheduling process. To guarantee real-time performance, OEMs should ensure that a priority inversion condition does not occur.</p></blockquote>
<p>Note that last line: &#8220;&#8230;[you] should ensure that a priority inversion condition does not occur.&#8221; Right. That sounds like a blast.</p>
<p>The bottom line is this: semaphores can be a royal pain. Fortunately, there are ways to avoid ever having to employ the little beasties:</p>
<ol>
<li>For managing access to a shared resource where only ONE thread should be working with the resource at any one time, simply use a mutex. Note here that a mutex != a semaphore with a count of 1.</li>
<li>If you are implementing a classic producer/consumer model with a thread pool, strongly consider using a combination of a condition variable and mutex. Chances are that the threading library you are using supports this natively (e.g., <a title="pthread condition variables tutorial" href="https://computing.llnl.gov/tutorials/pthreads/#ConditionVariables">pthread</a>, <a title="Boost threading condition variable" href="http://www.boost.org/doc/libs/1_45_0/doc/html/thread/synchronization.html#thread.synchronization.condvar_ref">Boost</a>, <a title="Win32 condition variables" href="http://msdn.microsoft.com/en-us/library/ms682052(VS.85).aspx">Win32</a>, <a title=".NET condition variables" href="http://stackoverflow.com/questions/1986055/condition-variables-in-c">.NET</a>).</li>
<li>Do something wild and crazy, like <a title="Erlang vs. Threads" href="http://www.eecs.berkeley.edu/Pubs/TechRpts/2006/EECS-2006-1.pdf">switch to Erlang</a>.</li>
</ol>
<p><em>Bonus!</em> You can choose from several specialized locks that can be more performant in certain situations, such as <a href="http://msdn.microsoft.com/en-us/library/ms682530(VS.85).aspx">critical sections</a> and multi-reader/single-writer locks. Any threading library worth its salt will support at least one or two specialized locks.</p>
<p>So, now that we&#8217;ve covered when <em>not</em> to use a semaphore, the question becomes: when <em>should</em> you use a semaphore? Honestly, I have no idea.</p>
<br />Filed under: <a href='http://nerdfortress.com/category/codealicious/'>Codealicious</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1263/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1263/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1263/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1263&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2011/02/18/you-say-semaphore-i-say-mutex/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
		<item>
		<title>Behind the Scenes of the C++ STL Algorithm Model</title>
		<link>http://nerdfortress.com/2010/08/17/behind-the-scenes-of-the-c-stl-algorithm-model/</link>
		<comments>http://nerdfortress.com/2010/08/17/behind-the-scenes-of-the-c-stl-algorithm-model/#comments</comments>
		<pubDate>Tue, 17 Aug 2010 17:17:17 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Codealicious]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1217</guid>
		<description><![CDATA[Ever wonder why the C++ STL uses an external, non-member function model for implementing algorithms for containers? The following article sums it up. Although a few of the &#8220;no less efficient&#8221; examples are debatable, the underlying principles definitely have merit. Monoliths &#8220;Unstrung&#8221; One downside to the functional approach outlined in the article&#8211;that I didn&#8217;t see mentioned&#8211;is [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1217&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Ever wonder why the C++ STL uses an external, non-member function model for implementing algorithms for containers? The following article sums it up. Although a few of the &#8220;no less efficient&#8221; examples are debatable, the underlying principles definitely have merit.</p>
<p><a href="http://www.gotw.ca/gotw/084.htm" target="_blank">Monoliths &#8220;Unstrung&#8221;</a></p>
<p>One downside to the functional approach outlined in the article&#8211;that I didn&#8217;t see mentioned&#8211;is the fact that the interface is actually being split in a few cases, which is actually detrimental to cohesion. This happens when you have multiple overloaded forms of a function, and you keep one &#8220;flexible&#8221; one as a member function, but make the others external functions. Why not keep those as members for the sake of consistency? You can still implement them in terms of the one &#8220;flexible&#8221; member function, thereby continuing to ensure good encapsulation.</p>
<p>A few thoughts on applying the spirit of the law discussed in the article to other languages:</p>
<ul>
<li><strong>C#</strong> &#8211; Use extension methods, but the &#8220;this&#8221; type should be as generic as possible. You still get the benefits of DRY but in a more object-oriented fashion that works well with Intellisense and cohesion. I like the extension  method approach better than the old static-methods approach (e.g., string.Join) because it still enforces good encapsulation, and is less verbose and more cohesive than the alternative.</li>
<li><strong>Ruby</strong> &#8211; Use mix-ins that use duct-type delegation to other methods. These can be automatically mixed into all applicable classes when the mix-in is &#8220;required&#8221;.</li>
<li><strong>Lisp</strong> &#8211; Brilliant! All you <em>have </em>are functions!</li>
</ul>
<p>It&#8217;s also important to note the power you derive from combining this functional approach with lambda functions,  function objects, and covariance.</p>
<p><em>See also: </em><a href="http://www.drdobbs.com/184401197" target="_blank"><em>How Non-Member Functions Improve Encapsulation</em></a></p>
<br />Filed under: <a href='http://nerdfortress.com/category/codealicious/'>Codealicious</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1217/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1217/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1217/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1217&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2010/08/17/behind-the-scenes-of-the-c-stl-algorithm-model/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
		<item>
		<title>The Closet Indie Game Developer</title>
		<link>http://nerdfortress.com/2010/03/30/the-closet-indie-game-developer/</link>
		<comments>http://nerdfortress.com/2010/03/30/the-closet-indie-game-developer/#comments</comments>
		<pubDate>Wed, 31 Mar 2010 00:55:23 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Indie Games]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1198</guid>
		<description><![CDATA[Come on, admit it. You started programming because you wanted to make games. Really cool ones with things that go bloop in the night. Then, somehow, life came along and you had to be practical and, well, pay the rent. So now you make websites or program database access layers, or whatever. But there is an [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1198&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>Come on, admit it.</strong> You started programming because you wanted to make games. Really cool ones with things that go bloop in the night.<a href="http://gammeta.com"><img class="alignright" style="border:none;background:none;" title="munch-man-2" src="http://nerdfortress.files.wordpress.com/2010/03/munch-man-2.png?w=500" alt="indie game munch man" /></a></p>
<p>Then, somehow, life came along and you had to be <em>practical</em> and, well, <em>pay the rent</em>. So now you make websites or program database access layers, or whatever.</p>
<p>But there is an indie revolution brewing. You&#8217;ve got tools such as Unity. Platforms like the iPhone. Indie-friendly publishing on major consoles for the first time ever.</p>
<p>Gammeta is the last piece of the puzzle. It&#8217;s the trump card that lets you compete with the big game shops.</p>
<p>Gammeta wants to make it easy for your indie game players to connect with friends and other players. We believe that bridging the gap between the virtual and real worlds is <a href="http://g4tv.com/videos/44277/DICE-2010-Design-Outside-the-Box-Presentation/" target="_blank">the future of gaming</a>.</p>
<p>So, rather than spend a lot of time and money to develop and run a one-off backend server for your game, you can have Gammeta take care of it for you. Simple. Neat. Fast and easy. Magically delicious.</p>
<p><a href="http://forum.gammeta.com/topic/1/whats-going-on-here/" target="_blank">Are you an indie game developer? Let us know what you think.</a></p>
<br />Filed under: <a href='http://nerdfortress.com/category/indie-games/'>Indie Games</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1198/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1198/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1198/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1198&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2010/03/30/the-closet-indie-game-developer/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>

		<media:content url="http://nerdfortress.files.wordpress.com/2010/03/munch-man-2.png" medium="image">
			<media:title type="html">munch-man-2</media:title>
		</media:content>
	</item>
		<item>
		<title>WCF Madness: Method Not Allowed on Missing Query Parameter</title>
		<link>http://nerdfortress.com/2010/02/13/wcf-madness-method-not-allowed-on-missing-query-parameter/</link>
		<comments>http://nerdfortress.com/2010/02/13/wcf-madness-method-not-allowed-on-missing-query-parameter/#comments</comments>
		<pubDate>Sat, 13 Feb 2010 16:53:52 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Codealicious]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1185</guid>
		<description><![CDATA[While testing some web services, I was not-so-pleasantly surprised to find that WCF cannot disambiguate two methods when one is a GET nd the other a POST: [OperationContract] [WebDispatchFormatter] [WebGet(UriTemplate = "/{encodedGameId}?startDate={startDate}&#38;endDate={endDate}&#38;tag={tag}")] Contracts.Out.Statistics GetStatistics(string gameId, string startDate, string endDate, string tag); [OperationContract] [WebInvoke(UriTemplate = "/{encodedGameId}", Method = Verbs.Post)] void AddSample(string gameId, Contracts.Sample newSample); [WebDispatchFormatter] If [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1185&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><a href="http://nerdfortress.files.wordpress.com/2010/02/curved-yellow-fruit.jpg"><img src="http://nerdfortress.files.wordpress.com/2010/02/curved-yellow-fruit.jpg?w=150&h=105" alt="" title="curved-yellow-fruit" width="150" height="105" class="alignright size-thumbnail wp-image-1191" /></a>While testing some web services, I was not-so-pleasantly surprised to find that WCF cannot disambiguate two methods when one is a GET nd the other a POST:<br />
	<code><br />
        [OperationContract]<br />
	[WebDispatchFormatter]<br />
	[WebGet(UriTemplate = "/{encodedGameId}?startDate={startDate}&amp;endDate={endDate}&amp;tag={tag}")]<br />
	Contracts.Out.Statistics GetStatistics(string gameId, string startDate, string endDate, string tag);</p>
<p>	[OperationContract]<br />
	[WebInvoke(UriTemplate = "/{encodedGameId}", Method = Verbs.Post)]<br />
	void AddSample(string gameId, Contracts.Sample newSample);<br />
	[WebDispatchFormatter]</code></p>
<p>If you leave off any of the query parameters for GetStatistics, WCF cheerfully returns &#8220;Method not allowed&#8221;. I wanted to make the &#8220;tag&#8221; parameter optional, and worried this would be a deal breaker.</p>
<p>Fortunately, I came across this <a href="http://blogs.msdn.com/rjacobs/archive/2009/02/10/ambiguous-uritemplates-query-parameters-and-integration-testing.aspx">WCF post by Ron Jacobs</a>.</p>
<p>The basic idea is to leave off the optional query parameters in the UriTemplate, instead manually pulling them from the current request context. This approach is actually similar to the way you access query parameters in RoR, so I should have thought of doing it like this in the first place.</p>
<p>In fact, if you beef up Ron&#8217;s QueryString class, it can clean help you DRY up your code by taking care of data type conversions on the sly.</p>
<p>The moral of the story is that a framework&#8217;s design can induce sneaky biases that you only discover as they jump out of the shadows to bite you.</p>
<p>Thanks Ron!</p>
<br />Filed under: <a href='http://nerdfortress.com/category/codealicious/'>Codealicious</a>  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1185/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1185/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1185/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1185&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2010/02/13/wcf-madness-method-not-allowed-on-missing-query-parameter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>

		<media:content url="http://nerdfortress.files.wordpress.com/2010/02/curved-yellow-fruit.jpg?w=150" medium="image">
			<media:title type="html">curved-yellow-fruit</media:title>
		</media:content>
	</item>
		<item>
		<title>Dude, you&#8217;re not gettin&#8217; a Dell: Why I Like Windows</title>
		<link>http://nerdfortress.com/2010/01/11/why-i-like-windows-no-dell/</link>
		<comments>http://nerdfortress.com/2010/01/11/why-i-like-windows-no-dell/#comments</comments>
		<pubDate>Mon, 11 Jan 2010 14:29:04 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Random Stuff]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1138</guid>
		<description><![CDATA[Recently I realized that one of the main reasons I like Windows is that I build my own boxes. Most of the PCs sold are lame, including those by Dell, HP, and Acer. You can build your own computer using similar specs to anything from these manufacturers and generally (1) save money, (2) get better [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1138&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Recently I realized that one of the main reasons I like Windows is that I <a href="http://nerdfortress.com/2008/02/26/build-a-custom-pc/">build my own boxes</a>. Most of the PCs sold are lame, including those by Dell, HP, and Acer. You can build your own computer using similar specs to anything from these manufacturers and generally (1) save money, (2) get better performance, and (3) avoid all the low-quality, resource-hogging software that comes pre-installed on retail PCs. </p>
<p><a href="http://nerdfortress.files.wordpress.com/2010/01/xenix.png"><img src="http://nerdfortress.files.wordpress.com/2010/01/xenix-small.png?w=500" alt="" title="xenix-small" class="alignright size-full wp-image-1159" /></a></p>
<p>One other significant reason that I like Windows is that I haven&#8217;t been running Windows XP for a long time. I was one of the brave few who decided to give Vista a try and I have to tell you, XP is absolutely archaic in comparison. Even more so when you compare XP to Windows 7. <a href="http://www.codinghorror.com/blog/archives/001290.html">Windows 7 is very, very good</a>. </p>
<p>A simple example of what you get when you upgrade from Windows XP is the ability to mute annoying system sounds, like those &#8220;online/offline&#8221; dings that I can&#8217;t seem to turn off in Trillian. I know this feature may seem trivial, but all these little goodies add up to a great experience.</p>
<p><img src="http://nerdfortress.files.wordpress.com/2010/01/mute-application.png?w=500" style="border:none;background:none;" alt="" title="mute-application"   class="aligncenter size-full wp-image-1140"></p>
<p>Don&#8217;t get me wrong, I also like Mac OS X and Linux. If only PC manufacturers would raise their standards, more people would like Windows as well. Fortunately, looking at the announcements coming out of CES last week, things are trending in the right direction.</p>
<br />Posted in Random Stuff  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1138/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1138/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1138/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1138&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2010/01/11/why-i-like-windows-no-dell/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>

		<media:content url="http://nerdfortress.files.wordpress.com/2010/01/xenix-small.png" medium="image">
			<media:title type="html">xenix-small</media:title>
		</media:content>

		<media:content url="http://nerdfortress.files.wordpress.com/2010/01/mute-application.png" medium="image">
			<media:title type="html">mute-application</media:title>
		</media:content>
	</item>
		<item>
		<title>Indie Gamers: Help Me Choose</title>
		<link>http://nerdfortress.com/2009/12/31/indie-gamers-help-me-choose/</link>
		<comments>http://nerdfortress.com/2009/12/31/indie-gamers-help-me-choose/#comments</comments>
		<pubDate>Thu, 31 Dec 2009 21:57:00 +0000</pubDate>
		<dc:creator>Kurt</dc:creator>
				<category><![CDATA[Indie Games]]></category>

		<guid isPermaLink="false">http://nerdfortress.com/?p=1125</guid>
		<description><![CDATA[I&#8217;m getting ready to launch my new indie game services project, Cupcake, but I need a good domain name. The general idea of Cupcake is to provide tools and services that take the pain out of making high-quality indie games. What do you think is a good domain name? Vote for one of the ones [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1125&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m getting ready to launch my new indie game services project, Cupcake, but I need a good domain name. The general idea of Cupcake is to provide tools and services that take the pain out of making high-quality indie games. </p>
<p>What do you think is a good domain name? Vote for one of the ones I&#8217;ve already come up with, or enter your own. </p>
<div style="margin:20px;">
<a name="pd_a_2451666"></a>
<div class="PDS_Poll" id="PDI_container2451666" data-settings="{&quot;url&quot;:&quot;http:\/\/static.polldaddy.com\/p\/2451666.js&quot;}" style="display:inline-block;"></div>
<div id="PD_superContainer"></div>
<noscript><a href="http://polldaddy.com/poll/2451666">Take Our Poll</a></noscript>
</div>
<p><em>Note: I would LOVE to use cupcake.com but someone is squatting on that name.</em></p>
<br />Posted in Indie Games  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/nerdfortress.wordpress.com/1125/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/nerdfortress.wordpress.com/1125/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/nerdfortress.wordpress.com/1125/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=nerdfortress.com&#038;blog=4772118&#038;post=1125&#038;subd=nerdfortress&#038;ref=&#038;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://nerdfortress.com/2009/12/31/indie-gamers-help-me-choose/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/50b7c50e71c508c9874184663384efb9?s=96&#38;d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D96&#38;r=G" medium="image">
			<media:title type="html">Random</media:title>
		</media:content>
	</item>
	</channel>
</rss>
