<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>chrishowie.com &#187; Programming</title>
	<atom:link href="http://www.chrishowie.com/category/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrishowie.com</link>
	<description>The best laid plans are in my other pants</description>
	<lastBuildDate>Fri, 14 May 2010 18:16:06 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>git-svn in the workplace</title>
		<link>http://www.chrishowie.com/2010/04/01/git-svn-in-the-workplace/</link>
		<comments>http://www.chrishowie.com/2010/04/01/git-svn-in-the-workplace/#comments</comments>
		<pubDate>Thu, 01 Apr 2010 16:42:22 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Git]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=365</guid>
		<description><![CDATA[At work, we use Subversion for source control. This is quite the popular VCS, but I&#8217;ve grown accustomed to (and much prefer) Git. Don&#8217;t get me wrong, SVN has its advantages, but since using Git my workflow has changed quite radically, and it&#8217;s difficult to revert to the rather inflexible and tedious SVN workflow. Anyway, [...]]]></description>
			<content:encoded><![CDATA[<p>At work, we use Subversion for source control.  This is quite the popular VCS, but I&#8217;ve grown accustomed to (and much prefer) Git.  Don&#8217;t get me wrong, SVN has its advantages, but since using Git my workflow has changed quite radically, and it&#8217;s difficult to revert to the rather inflexible and tedious SVN workflow.  Anyway, I&#8217;ve been using git-svn for the past month or so, and thought I&#8217;d share some of my practices.</p>
<p>In my clone, master is my &#8220;local&#8221; storage branch.  I use it to version things like my .gitignore, and my commit message template.  I would also use it for my dcommit/rebase scripts too, but since this is on Windows, Git becomes angry when it attempts to remove scripts that are executing.</p>
<p>Master is then the common root for my topic branches.  I&#8217;ll do some work and commit, then do more work, as the usual Git workflow goes.  The ability to create local branches and commits is great for several reasons:</p>
<p>First, I can commit much more often, without fearing that I will break somebody else&#8217;s working copy &#8212; I do frequently commit broken code now, because the commits don&#8217;t get sent to SVN automatically.</p>
<p>Second, and a side effect of the above, I am much more agile.  Sometimes I&#8217;ll be working on two projects at once, and keeping separate branches for them means that the broken state of one branch does not affect my ability to build/debug another.  This means I can even drop everything (after a commit or stash) and help out with an urgent QA or support issue, without either having lots of uncommitted work interfering or committing broken code to a production repository first.</p>
<p>Third, I can version changes I make to code that might make my life easier, but that would require approval to commit.  I have not yet done this, but thanks to my local repository, it&#8217;s an option.</p>
<p>Fourth, I can develop against a stable codebase.  If I need a specific fix from SVN to work, I can cherry-pick it into my topic branch &#8212; fetching commits from SVN does not mandate that my code must be merged with them.  Along the same lines, I also have the ability to rebase all my topic branches against a specific SVN commit, which is great when somebody commits broken code that causes build errors or incorrect runtime behavior.  If I were using SVN, I would either have to fix it myself, wait for the owner of the code to fix it, or revert to an earlier commit.  And since commits are linear, that might mean I would lose some of <i>my</i> code.  Git allows me to retain my commits while backing out changes made by others.  And if I <i>did</i> already commit some of my changes after the broken code, I can still rebase master and cherry-pick my subsequent commits onto a new branch and continue my work.</p>
<p>And finally, I can review all my commits before pushing them out.  I&#8217;ve had several occasions to fix up commit messages already.</p>
<p>Of course, I do eventually need to commit to SVN.  I have a few scripts to help here.  Obviously I don&#8217;t want to commit my local-only stuff in master.  So I have one script that simply does <code>git svn fetch &#038;&#038; git rebase --onto git-svn master</code>.  For the Git-impaired, this fetches any new commits from SVN and adds corresponding Git commits on the git-svn branch.  The rebase command then takes all the commits on the current branch since master&#8217;s latest commit, and applies them as patches to the tip of the git-svn branch, creating a new commit for each.  This effectively removes the local changes I&#8217;ve made in master from the commits, as well as merges the changes in SVN into my commits.  (If one of my commits fails to apply as a patch, then I have to resolve the conflicts manually, just like an SVN update.  But in this case, I still retain all my individual commits.)</p>
<p>After running this script, I then <code>git svn dcommit</code>, which commits my local commits to SVN, one by one.</p>
<p>At this point, I usually run my post-commit script, which rebases master on to git-svn, then rebases all my other branches on top of master.  I might not do this if I don&#8217;t want to rebase some of my other topic branches yet.</p>
<p>In closing, I leave you with my trick for changing commit messages.  I used to use git filter-branch for this, which is like using a sledgehammer for surgery.  (My similes are awesome, I know.)  Now I use this process:</p>
<p><code>git checkout -b temp $COMMIT_TO_CHANGE</code> (Create a new branch called &#8220;temp&#8221; at the commit I&#8217;m changing, and switch to it.)</p>
<p><code>git commit --amend</code> (Open an editor to amend my commit.  I change to message here, then save and quit.  The temp branch now has the new commit, whose parent commit is the same as it was before being amended.)</p>
<p><code>git checkout $ORIGINAL_BRANCH</code> (Switch back to the branch we are amending.)</p>
<p><code>git rebase temp</code> (Rebase the branch on top of the amended commit.  Since the original commit will be applied on top of the amended commit, it is dropped during the rebase.  The other commits will apply with no conflicts.  The history is now corrected.)</p>
<p><code>git branch -d temp</code> (Remove our temporary branch.)</p>
<p>And there you have it.  In a history with many thousands of commits, this is much faster than git filter-branch, and for those relatively fluent in Git, is also easier to remember how to do.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2010/04/01/git-svn-in-the-workplace/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>When FarmVille == Productivity</title>
		<link>http://www.chrishowie.com/2010/01/27/when-farmville-productivity/</link>
		<comments>http://www.chrishowie.com/2010/01/27/when-farmville-productivity/#comments</comments>
		<pubDate>Thu, 28 Jan 2010 00:27:11 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Computer]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=348</guid>
		<description><![CDATA[Update 2010-02-08: Jonathan Pryor has merged many of my extension methods into Cadenza. I&#8217;d strongly suggest checking it out. It&#8217;s no secret to my friends that I love to program&#8230; even more so as I&#8217;ve been developing a FarmVille client in C# and having them test it. (As much as you might hate FarmVille, you [...]]]></description>
			<content:encoded><![CDATA[<p><b>Update 2010-02-08:</b> Jonathan Pryor has merged many of my extension methods into <a href="http://gitorious.org/cadenza">Cadenza</a>.  I&#8217;d strongly suggest checking it out.</p>
<p>It&#8217;s no secret to my friends that I love to program&#8230; even more so as I&#8217;ve been developing a <a href="http://www.farmville.com">FarmVille</a> client in C# and having them test it.  (As much as you might hate FarmVille, you must agree that there&#8217;s a certain awesome factor in LINQ-to-FarmVille: <code>service.Plow(from i in service.World.Objects.OfType&lt;Plot&gt;() where i.State == "fallow" || i.State == "withered" select i</code>)</p>
<p>Well, among this project and others I consistently find myself writing the same code over and over.  I know of many programmers who have developed personal toolkits for the languages they use frequently, but for some reason I&#8217;ve been programming for about 13-15 years now and haven&#8217;t ever built my own library.  This application gave me an excuse to do so, and so I&#8217;ve started on the Cdh.Toolkit suite of libraries.</p>
<p>Here is a summary of the classes available:</p>
<ul>
<li><b>Cdh.Toolkit.Collections</b>: Some useful collection types, all designed to be derived.
<ul>
<li><b>ReadOnlyCollection&lt;T&gt;</b>, <b>ReadOnlyDictionary&lt;TKey, TValue&gt;</b>, and <b>ReadOnlyList&lt;T&gt;</b>: Wrappers around the corresponding interface types ICollection&lt;T&gt;, IDictionary&lt;TKey, TValue&gt;, and IList&lt;T&gt;, throwing exceptions on all write attempts.  While there is a ReadOnlyCollection&lt;T&gt; as part of the .NET framework, it is not designed to be derived, and the other two classes do not have a counterpart at all.</li>
<li><b>SynchronizedCollection&lt;T&gt;</b>, <b>SynchronizedDictionary&lt;TKey, TValue&gt;</b>, and <b>SynchronizedList&lt;T&gt;</b>: Wrappers around the corresponding interfaces.  All accesses are synchronized against a ReaderWriterLockSlim, allowing for multiple concurrent read operations.  The enumeration behavior can be specified as either lock, which holds a read lock for the duration of the enumeration, or copy, which creates a copy of the collection and enumerates it instead.</li>
<li><b>ObservableCollection&lt;T&gt;</b>: A collection that fires events when modified.  ObservableDictionary and ObservableList are currently not provided, due to some implementation complexities.  However, the interfaces <b>IObservableCollection&lt;T&gt;</b>, <b>IObservableDictionary&lt;TKey, TValue&gt;</b>, and <b>IObservableList&lt;T&gt;</b> and some EventArgs classes are provided to allow developers to implement their own observable collections easily.</li>
<li><b>ObservableHashSet&lt;T&gt;</b>: An observable and API-compatible wrapper around HashSet&lt;T&gt;.</li>
<li><b>ReadOnlyObservableCollection&lt;T&gt;</b>, <b>ReadOnlyObservableDictionary&lt;TKey, TValue&gt;</b>, and <b>ReadOnlyObservableList&lt;T&gt;</b>: Wrappers around the IObservable* interfaces mentioned above.  Events from the wrapped collections are forwarded.  This allows one to have a read only observable collection without sacrificing the IObservable* interface, which would happen if such a collection were wrapped in one of the normal read only classes listed above.</li>
</ul>
</li>
<li><b>Cdh.Toolkit.Extensions</b>: Extension libraries designed to ease the use of many classes in the .NET framework.
<ul>
<li><b>Collections</b>: Extensions specific to collection classes.
<ul>
<li><b>TValue IDictionary&lt;TKey, TValue&gt;.GetOrDefault(TKey key)</b>: Returns default(TValue) if the key is not present in the dictionary.</li>
<li><b>TValue IDictionary&lt;TKey, TValue&gt;.GetOrValue(TKey key, TValue fallback)</b>: Returns fallback if the key is not present in the dictionary.</li>
</ul>
</li>
<li><b>ComponentModel</b>: Extensions specific to the System.ComponentModel namespace.
<ul>
<li><b>void ISynchronizeInvoke.AutoInvoke(Action action)</b>: Executes the action delegate on the ISynchronizeInvoke object if required, otherwise does so on the current thread.</li>
<li><b>object ISynchronizeInvoke.AutoInvoke(Delegate method, params object[] args)</b>: Executes the delegate on the ISynchronizeInvoke object if required, otherwise does so on the current thread, and returns the return value of that method in either case.</li>
<li><b>AsyncCallback AsyncCallback.Invoked(ISynchronizeInvoke obj)</b>: Returns a wrapper around the AsyncCallback delegate that will invoke it using the AutoInvoke extension above.  Useful for async callbacks that need to operate on a Winforms GUI.</li>
</ul>
</li>
<li><b>Enumerable</b>: Extensions to enumerable objects.
<ul>
<li><b>IEnumerable&lt;T&gt; IEnumerable&lt;T?&gt;.NotNull() where T : struct</b>: Returns all values from the non-null nullable objects in the sequence.</li>
<li><b>void IEnumerable&lt;T&gt;.Walk()</b>: Enumerates the sequence, discarding all values obtained.  Useful as an alternative to .ToList() when you need to make sure that a query executes, but do not need to use the result.</li>
<li><b>void IEnumerable&lt;T&gt;.CopyInto(IList&lt;T&gt; list)</b>: Copies a sequence into a list.</li>
</ul>
</li>
<li><b>Events</b>: Extensions that make writing event logic easier.  All of these extensions return if the event handler in question is null, making event-firing code simpler and easier to read.
<ul>
<li><b>void EventHandler.Fire(object sender)</b>: Uses EventArgs.Empty as the event arguments.</li>
<li><b>void EventHandler.Fire(object sender, EventArgs args)</b></li>
<li><b>void EventHandler.Fire(object sender, Func&lt;EventArgs&gt; argsFactory)</b>: Calls the factory function only if the event handler is not null.  Useful when construction of the event arguments can take a long time.</li>
<li><b>void EventHandler&lt;T&gt;.Fire(object sender, T args)</b></li>
<li><b>void EventHandler&lt;T&gt;.Fire(object sender, Func&lt;T&gt; argsFactory)</b>: Calls the factory function only if the event handler is not null.  Useful when construction of the event arguments can take a long time.</li>
</ul>
</li>
<li><b>ReaderWriterLockSlim</b>: Allows these kind of locks to be used in a using() block, which makes code easier to read and maintain.  They will also return a no-op IDisposable if a compatible lock is already held by the current thread, which makes non-recursive lock objects simpler to code with.  (The return type is actually a value type that implements IDisposable, which means that usage of these methods does not incur any object allocation overhead.)
<ul>
<li><b>IDisposable ReaderWriterLockSlim.Read()</b>: Returns an IDisposable that will release the read lock when disposed.  This method returns a no-op IDisposable instead if the current thread already holds a read, upgradeable read, or write lock.</li>
<li><b>IDisposable ReaderWriterLockSlim.UpgradeableRead()</b>: Returns an IDisposable that will release the upgradeable read lock when disposed.  This method returns a no-op IDisposable instead if the current thread already holds an upgradeable read or write lock.</li>
<li><b>IDisposable ReaderWriterLockSlim.Write()</b>: Returns an IDisposable that will release the write lock when disposed.  This method returns a no-op IDisposable instead if the current thread already holds a write lock.</li>
</ul>
</li>
<li><b>Reflection</b>
<ul>
<li><b>T ICustomAttributeProvider.GetCustomAttribute&lt;T&gt;(bool inherit) where T : Attribute</b>: Returns a typed attribute, or null if there is no attribute of type T.</li>
<li><b>IEnumerable&lt;T&gt; ICustomAttributeProvider.GetCustomAttributes&lt;T&gt;(bool inherit) where T : Attribute</b>: Returns a sequence of attributes of type T present on the attribute provider.</li>
</ul>
</li>
<li><b>Reflection.Emit</b>
<ul>
<li><b>void ILGenerator.EmitTypeOf(Type type)</b>: Emits the IL sequence that will leave the same Type object on the execution stack.</li>
</ul>
</li>
</ul>
<p>The amount of code is slim, but I&#8217;ve found at least one of the classes or extensions invaluable in every project I&#8217;ve worked on since starting the toolkit.  It&#8217;s an interesting case where coding for a game actually winds up improving my productivity working on other software too.</p>
<p>Eventually these libraries will be released under the MIT license, so stay tuned for another blog post with a link to the Git repository.</p>
<p>(And yes, the above list will be converted into real documentation.  Someday.)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2010/01/27/when-farmville-productivity/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Covariant IEnumerables, pre-.NET-4.0</title>
		<link>http://www.chrishowie.com/2009/11/05/covariant-ienumerables/</link>
		<comments>http://www.chrishowie.com/2009/11/05/covariant-ienumerables/#comments</comments>
		<pubDate>Thu, 05 Nov 2009 18:22:57 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Computer]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=338</guid>
		<description><![CDATA[One of the nice things that .NET 3.5 gives us is LINQ, which gives new life to the often-neglected IEnumerable generic interface. Sequence processing is now a first-class citizen in the C# world, and this is a good thing. However, it can be very tricky to design a usable API around enumerables. Today I present [...]]]></description>
			<content:encoded><![CDATA[<p>One of the nice things that .NET 3.5 gives us is LINQ, which gives new life to the often-neglected IEnumerable generic interface.  Sequence processing is now a first-class citizen in the C# world, and this is a good thing.  However, it can be very tricky to design a usable API around enumerables.  Today I present my solution to an annoying (but not showstopping) hurdle.</p>
<p>Consider the case where you have several types implementing an interface.  In my case, these types all have a common ancestor, but this is beside the point.  We&#8217;ll call the interface <code>IFoo</code>, and the classes implementing this interface <code>ThingOne</code>, <code>ThingTwo</code>, and <code>ThingThree</code>.</p>
<p>If I have a method that acts on a series of <code>IFoo</code> objects, it is tempting to accept <code>IEnumerable&lt;IFoo&gt;</code> as an argument.  It makes sense, right?  Well, sort of.  Your users will not like this, because <code>IEnumerable&lt;ThingOne&gt;</code>, <code>IEnumerable&lt;ThingTwo&gt;</code>, and <code>IEnumerable&lt;ThingThree&gt;</code> are not convertible to <code>IEnumerable&lt;IFoo&gt;</code>.  While it&#8217;s not too annoying, your users will have to cope by invoking <code>Cast&lt;IFoo&gt;()</code> on their enumerables for them to work with your API.  This not only adds code overhead (read: more code to maintain) but a minor amount of CPU and memory overhead to create an object that is going to cast objects to an interface that they explicitly implement.</p>
<p>The solution is rather simple, but not very obvious at first glance.  Instead of using the signature <code>void OperateOnFoos(IEnumerable&lt;IFoo&gt; foos)</code>, use this instead: <code>void OperateOnFoos&lt;T&gt;(IEnumerable&lt;T&gt; foos) where T : IFoo</code>.  It is a simple change, and the method will work exactly the same as before, except your users will no longer be required to cast their enumerables to <code>IFoo</code>.</p>
<p>This technique applies just as well to situations where you take an enumerable to a class that is designed to be subclassed.</p>
<p>Now depending on how generics are implemented in your runtime of choice, you&#8217;re still probably going to see a small memory hit for each different <code>T</code> you use when calling this method.  But it&#8217;s not likely to be anywhere near the cost of creating a bunch of cast-enumerables that you really could do without.  And that aside, the convenience of not having to <code>Cast&lt;IFoo&gt;()</code> enumerables is totally worth changing one line of code.</p>
<p>.NET 4.0 will likely render this mechanism obsolete with the introduction of covariant interfaces, but in the meantime let&#8217;s all do something nice for our users!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/11/05/covariant-ienumerables/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Cdh.SimpleRpc</title>
		<link>http://www.chrishowie.com/2009/10/15/cdh-simplerpc/</link>
		<comments>http://www.chrishowie.com/2009/10/15/cdh-simplerpc/#comments</comments>
		<pubDate>Thu, 15 Oct 2009 21:39:36 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=329</guid>
		<description><![CDATA[I&#8217;ve got this idea to code some game servers for a series of cooperative games my brother and I used to play as kids. I get similar ideas all the time&#8230; how about a game server for this card game or that board game? The problem I run into is pretty much always exactly the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve got this idea to code some game servers for a series of cooperative games my brother and I used to play as kids.  I get similar ideas all the time&#8230; how about a game server for this card game or that board game?  The problem I run into is pretty much always exactly the same: what communication protocol do I use?</p>
<p>I decided on a list of criteria that this protocol, whatever it is, must meet:</p>
<ol>
<li>It must be portable across programming languages and runtimes.  If somebody else wants to write a better client using a different environment, that should be straightforward &#8212; perhaps not necessarily <i>easy</i>, but at least straightforward.</li>
<li>It must be relatively efficient on the wire.  Protocol chatter should be minimal in comparison to the data being exchanged.</li>
<li>The object library should be simple and elegant to code against.  When writing my game, the last thing I want to worry about is silly protocol details.  Just get my message to the other computer please.</li>
</ol>
<p>And here are the existing protocols I considered:</p>
<ul>
<li>.NET remoting.  Since I code most in C# these days, it seemed like a logical choice.  But it very blatantly breaks criterion 1 when using the binary formatter, and breaks both 1 and 2 when using the SOAP formatter.</li>
<li>SOAP web service.  Criterion 3 is satisfied, until you get to session persistence details.  Criterion 1 is satisfied, and criterion 2&#8230; not so much.</li>
<li>XML-RPC.  Criterion 1 is met, and 2 is somewhat met.  But criterion 3 is not &#8212; XML-RPC does not define any mechanism for dealing with persistent sessions.  I would have to spend time writing a session manager with expiration and whatnot.  No thanks.</li>
</ul>
<p>And I&#8217;m sure I looked at others.  The point is, for something as simple as message-passing between a game client and server, there doesn&#8217;t appear to be much out there that satisfies my requirements.  And this is something I&#8217;ve come back to frequently.</p>
<p>Well, after several years of mulling the problem over in my subconscious, I knuckled down and coded.  I have a usable library after two days of development.  (And we&#8217;re talking maybe a few hours per day.)  Written in C#, it allows any CIL-based language to write simple message-based client/server programs in very small amounts of code.  For a quick example, let&#8217;s create a server that will convert strings to uppercase, with tracing back to the client.</p>
<p>First, we need to create an interface library so that the client and server know what each other&#8217;s methods are:</p>
<pre>using System;
using Cdh.SimpleRpc;

namespace ServiceTest.Interfaces {
    public interface IServer {
        [RpcMethod] string ToUppercase(string str);
    }

    public interface IClient {
        [RpcMethod] void Trace(string message);
    }
}</pre>
<p>Now, here is the client:</p>
<pre>using System;
using System.IO;
using Cdh.SimpleRpc;
using ServiceTest.Interfaces;

namespace ServiceTest.Client {
    public class MainClass {
        public static void Main() {
            Stream serverStream = ConnectToServer();

            var service = new RpcService&lt;IClient, IServer&gt;(new Client(), serverStream);

            new Thread(delegate { while(service.Read()); }).Start();

            IServer server = service.RemoteServerProxy;
            Console.WriteLine("ToUppercase result: " + server.ToUppercase("this is a test"));

            serverStream.Close();
        }

        private Stream ConnectToServer() {
            // Here is your code to connect to the server endpoint.
        }
    }

    internal class Client : IClient {
        public void Trace(string message) {
            Console.WriteLine("Server trace: " + message);
        }
    }
}</pre>
<p>Note that the RpcService object generates a typed object that will transparently proxy calls to the remote service.  The server program is almost as simple:</p>
<pre>using System;
using System.IO;
using Cdh.SimpleRpc;
using ServiceTest.Interfaces;

namespace ServiceTest.Server {
    public class MainClass {
        public static void Main() {
            Stream clientStream = AcceptConnection();

            Server server = new Server();
            var service = new RpcService&lt;IServer, IClient&gt;(server, clientStream);
            server.client = service.RemoteServerProxy;

            while(service.Read());

            clientStream.Close();
        }

        private Stream AcceptConnection() {
            // Here is your code to accept a client connection.
        }
    }

    internal class Server : IServer {
        public IClient client;

        public string ToUppercase(string str) {
            client.Trace("Entering ToUppercase");
            str = str.ToUpper();
            client.Trace("Leaving ToUppercase");

            return str;
        }
    }
}</pre>
<p>Ta-da.  Some closing notes about this library:</p>
<ul>
<li>It should be completely thread-safe, and will allow you to place calls using the proxy objects from multiple threads.  The calls will block until a response is returned from the remote service.</li>
<li>Yes, you can throw exceptions in a service method, and yes, it will cause an exception to be thrown remotely from the proxy object.</li>
<li>In the future it may be possible to flag service methods that return void as &#8220;no response&#8221; calls, which will cause the proxy call to return immediately.  Of course, you will not be notified if an exception is thrown remotely.</li>
<li>This API doesn&#8217;t do any complex serialization, and will only operate on the primitive types, excluding IntPtr.  It will probably allow transmission of arrays at some point, and perhaps allow custom objects too.</li>
</ul>
<p>Looking back on the list of criteria, this library, even in the early stages of development, easily meets all three.  I&#8217;ll be hacking on it some more I&#8217;m sure, and may even publish the Git repository somewhere, when I&#8217;m confident that the code doesn&#8217;t totally suck.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/10/15/cdh-simplerpc/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Splitting a Git repository</title>
		<link>http://www.chrishowie.com/2009/07/09/splitting-a-git-repository/</link>
		<comments>http://www.chrishowie.com/2009/07/09/splitting-a-git-repository/#comments</comments>
		<pubDate>Thu, 09 Jul 2009 18:47:46 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=291</guid>
		<description><![CDATA[First some backstory&#8230; I had a public and a private Subversion repository on my web server, and when I started a new project I&#8217;d import it into one of them. This is nice because I get versioning and history, plus I get implicit synchronization between my various development boxen. It&#8217;s not unusual to have one [...]]]></description>
			<content:encoded><![CDATA[<p>First some backstory&#8230;</p>
<p>I had a public and a private Subversion repository on my web server, and when I started a new project I&#8217;d import it into one of them.  This is nice because I get versioning and history, plus I get implicit synchronization between my various development boxen.</p>
<p>It&#8217;s not unusual to have one monolithic Subversion repository for many different projects, mainly because setting up a Subversion repository can take a small bit of work, especially if you are serving it from HTTP.  However, Git makes it so easy to create new repositories that there is no excuse not to create per-project repositories, not to mention that you should anyway since Git doesn&#8217;t support checking out a subdirectory of a repository.  You simply can&#8217;t use a monolithic Git repository because you have to clone the whole big tree, even if you only plan on working on one subdirectory.</p>
<p>Since Git is so much more awesome, I plan on converting my Subversion repositories over.  But what do I do with the multi-project ones?  There&#8217;s no built-in mechanism for pulling out just one directory, with history, into a new repository.  So I <a href="/files/git-pluck.sh">wrote one</a>.</p>
<p>The usage is <code>git-pluck src-repo dest-repo path/to/directory</code>.  The script copies the repository at <code>src-repo</code> to a new directory, <code>dest-repo</code>, and then does its magic.  It rewrites all of the commits so that all of the files in <code>path/to/directory</code> are moved into the root of the repository, and everything else is deleted.  Commits that do not introduce changes to that directory are removed from the history, potentially including the first commit to the repository.  Finally, the reflogs and backups are removed and the repository is compacted, leaving you with a small, single-project repository.</p>
<p>This script was written and tested using Git 1.5.6.5.  Feedback is welcome!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/07/09/splitting-a-git-repository/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Git and Banshee.OpenVP fun</title>
		<link>http://www.chrishowie.com/2009/05/07/git-and-bansheeopenvp-fun/</link>
		<comments>http://www.chrishowie.com/2009/05/07/git-and-bansheeopenvp-fun/#comments</comments>
		<pubDate>Thu, 07 May 2009 21:43:39 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Banshee]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Computer]]></category>
		<category><![CDATA[OpenVP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=244</guid>
		<description><![CDATA[Well it&#8217;s hacking season again. With GNOME&#8217;s switch from Subversion to Git complete, which means Banshee now uses Git too, it gave me an excuse to finally learn it. This was not fun. But having toughed it out, I can definitely say that I love it. Now that Banshee is using Git, Aaron is starting [...]]]></description>
			<content:encoded><![CDATA[<p>Well it&#8217;s hacking season again.  With GNOME&#8217;s switch from Subversion to Git complete, which means <a href="http://mail.gnome.org/archives/banshee-list/2009-April/msg00120.html">Banshee now uses Git too</a>, it gave me an excuse to finally learn it.  <a href="http://twitter.com/cdhowie/status/1664570385">This was not fun.</a>  But having toughed it out, I can definitely say that <a href="http://twitter.com/cdhowie/status/1729199925">I love it</a>.</p>
<p>Now that Banshee is using Git, Aaron is starting work on a branch off of the 1.4 series to incorporate my visualization patch.  Wielding my new Git tool belt, I was off and hacking.  Taking Gabriel&#8217;s branch allowing replacement of source widgets, I rebased that from master to stable-vis, fixed the merge conflicts, and started hacking away at Banshee.OpenVP.  Unfortunately, not all the pieces I needed were there yet.  So I <a href="http://gitorious.org/projects/banshee/repos/cdhowie-clone/commits/327f490aa06f5af59b48d6a4832fd894f351fedb">added</a> <a href="http://gitorious.org/projects/banshee/repos/cdhowie-clone/commits/fd9cf79d6f8f57fabdd0ca58afb722c28756038c">them</a> and pushed them up to <a href="http://gitorious.org">Gitorious</a>.  Neat.</p>
<p>Now Banshee.OpenVP looks like this:
<div style="text-align:center;"><a href="http://picasaweb.google.com/lh/photo/xeCOFVbEQXnGVR0Qy5tU_A?feat=embedwebsite"><img src="http://lh5.ggpht.com/_1U-UwfPfZ6A/SgMW44Vm8cI/AAAAAAAAAe8/BWH-RTov3ZM/s400/Banshee.OpenVP%20-%20Now%20Playing%20integration.png" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/05/07/git-and-bansheeopenvp-fun/feed/</wfw:commentRss>
		<slash:comments>14</slash:comments>
		</item>
		<item>
		<title>The new Gazebo: a Gtk# interface to FICS</title>
		<link>http://www.chrishowie.com/2009/04/17/the-new-gazebo-a-gtk-interface-to-fics/</link>
		<comments>http://www.chrishowie.com/2009/04/17/the-new-gazebo-a-gtk-interface-to-fics/#comments</comments>
		<pubDate>Fri, 17 Apr 2009 19:33:25 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Chess]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=231</guid>
		<description><![CDATA[I&#8217;ve abandoned my idea of creating an AJAX interface for the time being. It is a cool idea but I think I can do much better by writing a proper application. The Linux FICS interface scene is rather weak. eboard is about the best there is in terms of usability, and it has its share [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve abandoned my idea of creating an AJAX interface for the time being.  It is a cool idea but I think I can do much better by writing a proper application.</p>
<p>The Linux FICS interface scene is rather weak.  eboard is about the best there is in terms of usability, and it has its share of problems.  xboard is there for the minimalists who want their interface to provide a chess board only.  When compared with the powerful and extensible interfaces available for Windows it&#8217;s rather a shame there&#8217;s nothing similar for Linux.</p>
<p>So I&#8217;ve decided to take the name I was going to use for my web interface and apply it to a new Linux interface.  Building on Mono.Addins, I&#8217;ve already got an interface that can be extended in several key ways.  Addins can, for example, provide new text highlighting classes or classes that can manipulate the console text buffer in interesting ways.</p>
<p>Using a tip from jonp in #mono, I have now come up with an extensible preferences system that does not suck, based on XLinq.  Addins can simply subclass PreferenceContainer, slap on a few attributes, and they have an easy-to-use set of strongly typed preferences that get automatically serialized to XML.  Right now only the basic primitive types and strings are supported, but this will be extended later to include things like arrays, lists, and XLinq objects.  Thanks to Mono.Addins and some more support classes I wrote, addins can also provide Gtk# widgets that get embedded into the application preferences window.  By writing very little code, addin authors can persist their settings <i>and</i> provide the user with a convenient way to change them.</p>
<p>I&#8217;m still lacking a chess board though.  If anyone likes writing custom widgets and feels comfortable working on this project let me know.  The sources will be made public in the coming weeks after I&#8217;ve had a chance to polish them and set consistent style guidelines.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/04/17/the-new-gazebo-a-gtk-interface-to-fics/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Gazebo: An AJAX interface to FICS</title>
		<link>http://www.chrishowie.com/2009/03/23/gazebo-an-ajax-interface-to-fics/</link>
		<comments>http://www.chrishowie.com/2009/03/23/gazebo-an-ajax-interface-to-fics/#comments</comments>
		<pubDate>Mon, 23 Mar 2009 06:55:41 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Chess]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Web]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=224</guid>
		<description><![CDATA[I&#8217;ve been getting back into chess recently, and my favorite online community is the Free Internet Chess Server (FICS). There are a wealth of free and open interfaces available for download, but they all have one thing in common: you have to download them. At my workplace this is a no-no, but over my lunch [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been getting back into chess recently, and my favorite online community is the <a href="http://freechess.org">Free Internet Chess Server</a> (FICS).  There are a wealth of free and open interfaces available for download, but they all have one thing in common: you have to download them.  At my workplace this is a no-no, but over my lunch break it would be nice to get in a few games.  If I forget my laptop then I have no way to play.</p>
<p>Enter Gazebo.  I started this project last Friday night, so it&#8217;s only been about two days.  Still, what I have right now is rather impressive for that amount of time.  At face value, the current version is not very representative of the time that&#8217;s gone into the project so far, and for a very good reason.</p>
<p>The HTTP protocol used by web servers was not engineered around the idea that you&#8217;d establish a long-lasting connection with the server.  It&#8217;s better suited for quick request-response cycles.  Because of this, the PHP web service has no good way to maintain a connection to FICS.</p>
<p>The solution I came up with for this problem is simple, yet very involved.  A daemon script (yes, written in PHP&#8230;) listens on a UNIX socket for connections from the PHP web service script.  If a new FICS session is requested, it creates a new session and returns some authentication parameters to the web service.  On every request to the service, another connection to the daemon is made over the UNIX socket, the session attached to with the authentication parameters, and some action taken, like &#8220;write this to the network socket&#8221; or &#8220;tell me when you get new data from the network socket&#8221; or even &#8220;close the network socket and destroy the session.&#8221;  The daemon essentially acts as a super-proxy that persists the network sockets and enables access to all of them from one UNIX socket.</p>
<p>Yes, it&#8217;s kinda ugly.  But it also works incredibly well.  There is still some tuning to be done, but behold the awesomeness of what is essentially in-browser, color-coded telnet:</p>
<div style="text-align:center;"><a href="http://picasaweb.google.com/cdhowie/MiscellaneousProjects?feat=embedwebsite#5316269708328510946"><img src="http://lh5.ggpht.com/_1U-UwfPfZ6A/SccvIgcXJeI/AAAAAAAAAbs/kpbN3-A6yOg/s400/gazebo.png" /></a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/03/23/gazebo-an-ajax-interface-to-fics/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Issues with Crockford&#8217;s JavaScript conventions</title>
		<link>http://www.chrishowie.com/2009/03/10/issues-with-crockfords-javascript-conventions/</link>
		<comments>http://www.chrishowie.com/2009/03/10/issues-with-crockfords-javascript-conventions/#comments</comments>
		<pubDate>Tue, 10 Mar 2009 04:36:12 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[JavaScript]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=215</guid>
		<description><![CDATA[I&#8217;ve been reading up on Douglas Crockford&#8217;s Code Conventions for the JavaScript Programming Language and I agree with most of them, but I definitely have a bone to pick with one of them: &#8220;All variables/functions should be declared before they are used.&#8221; This sounds good in theory, and is probably a good programming practice. However, [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been reading up on <a href="http://javascript.crockford.com/code.html">Douglas Crockford&#8217;s <i>Code Conventions for the JavaScript Programming Language</i></a> and I agree with most of them, but I definitely have a bone to pick with one of them: &#8220;All variables/functions should be declared before they are used.&#8221;</p>
<p>This sounds good in theory, and is probably a good programming practice.  However, in JavaScript we frequently use callbacks to implement asynchronous calls, due to the fact that JavaScript is single-threaded.  Code like this is common:</p>
<pre>function BeginProcess(data) {
    // process data
    DoDataProcess({
        'data': data,
        'onComplete': EndProcess
    });
}

function EndProcess() {
    alert('The process is done');
}</pre>
<p>Think AJAX in particular.  This kind of thing is commonplace.  However, declaring things before we use them means we have two options.  We can either swap the functions around, or we can declare <code>var EndProcess;</code> at the top of the script.  The latter reminds me too much of C, where you have to declare function prototypes ahead of time if you want to write them in any order you want.  The former is just incredibly confusing.  Consider how that would look:</p>
<pre>function EndProcess() {
    alert('The process is done');
}

function BeginProcess(data) {
    // process data
    DoDataProcess({
        'data': data,
        'onComplete': EndProcess
    });
}</pre>
<p>This is horrible.  The natural code flow is broken.  You now have to start at the last function and read it, then go <i>up</i> to read the next part.  This is the same reason that <a href="http://www.caliburn.nl/topposting.html">top-posting sucks and bottom-posting makes sense</a>.  If those functions were both longer than a screen, you have to scroll to the bottom of the script, then up to the function header.  Then read down to find &#8220;EndProcess&#8221; and say &#8220;what&#8217;s that?&#8221;  Then scroll up to find EndHeader, then back down to read it.  The human mind has not been conditioned to read this way.</p>
<p>Consider this quote from the linked article on top-posting:</p>
<blockquote><p>Top-posting makes posts incomprehensible. Firstly: In normal conversations, one does not answer to something that has not yet been said. So it is unclear to reply to the top, whilst the original message is at the bottom. Secondly: In western society a book is normally read from top to bottom. Top-posting forces one to stray from this convention: Reading some at the top, skipping to the bottom to read the question, and going back to the top to continue. This annoyance increases even more than linear with the number of top-posts in the message. If someone replies to a thread and you forgot what the thread was all about, or that thread was incomplete for some reasons, it will be quite tiresome to rapidly understand what the thread was all about, due to bad posting and irrelevant text which has not been removed.</p></blockquote>
<p>Given a suitably large enough application (like the one I am working on right now) this means that I either need about 200 <code>var</code> statements at the top of my program to indicate every class I am defining, and the same within each class to indicate each private function, or I have to reorder them.  Both are unwieldy.  One is unnecessarily verbose, while the other is horrible to read and breaks the natural flow of the code.  Your initialization function winds up at the very bottom of the script, then you have to work your way up to see what is going on.</p>
<p>Crockford seems like a pretty intelligent guy, but I&#8217;ve yet to see any extensive code samples that show how he gets around this problem.  Thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/03/10/issues-with-crockfords-javascript-conventions/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>JavaScript appreciation and more</title>
		<link>http://www.chrishowie.com/2009/03/06/javascript-appreciation-and-more/</link>
		<comments>http://www.chrishowie.com/2009/03/06/javascript-appreciation-and-more/#comments</comments>
		<pubDate>Fri, 06 Mar 2009 21:31:44 +0000</pubDate>
		<dc:creator>Chris</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Personal]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.chrishowie.com/?p=209</guid>
		<description><![CDATA[I&#8217;ve been up to a lot of little things recently but haven&#8217;t undertaken any projects big enough to warrant a whole fancy blog post. I figured I might as well summarize what I&#8217;ve been up to. I&#8217;m doing a project at school that improves the experience of on-campus tutors and their clients. They&#8217;d been using [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been up to a lot of little things recently but haven&#8217;t undertaken any projects big enough to warrant a whole fancy blog post.  I figured I might as well summarize what I&#8217;ve been up to.</p>
<p>I&#8217;m doing a project at school that improves the experience of on-campus tutors and their clients.  They&#8217;d been using <a href="http://www.moodle.org">Moodle</a> workshops to allow clients to submit content to tutors, and recording hours manually on timecards.  Moodle will still be involved, but the tutors will now interact primarily with a web application I&#8217;ve been coding that will track their hours for them, as well as fulfill some clerical roles, such as preventing two tutors from working on the same paper.  (Previously this was done more or less manually by updating the workshop submission title.  Not a terribly fun way to track that kind of stuff.)</p>
<p>This project has me up to my neck in JavaScript, a language I&#8217;ve long held in contempt.  However, after reading up on some patterns and watching a talk or two my mind has been completely changed.  In fact, I enjoy coding in JavaScript now.  I enjoy it a lot.  When you know what you are doing (and what to avoid) all the frustration and general icky feelings associated with working in the language disappear.  What&#8217;s left is an incredibly pure, lightning-fast web application.  A maintainable one too.  Who knew JavaScript could do that?</p>
<p>Some other semi-random facts:</p>
<ul>
<li>I&#8217;m getting married in 91 days.  (See that counter in the right column?  Yup, that one.  If you&#8217;ve been wondering what that&#8217;s counting down to, now you know.)</li>
<li>I&#8217;ve recently revived the RTS gaming genre on my system by reinstalling Age of Empires 3.  I don&#8217;t recall why I stopped playing, but I shouldn&#8217;t have.</li>
<li>In case anyone wonders why I haven&#8217;t been on WoW for a while, it&#8217;s because I let my subscription expire.  That was over six months ago, I think.  Honestly I have not missed it.  There are more fun games out there, and they don&#8217;t require a monthly fee.  Team Fortress 2 is an especially good option if you like class-based games and first-person shooters.</li>
</ul>
<p>That&#8217;s all for now, I guess.  Stay tuned for some more developments on Banshee.OpenVP in the coming weeks.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrishowie.com/2009/03/06/javascript-appreciation-and-more/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>
