<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
    <title>Cordinc Blog</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/" />
    <link rel="self" type="application/atom+xml" href="http://www.cordinc.com/blog/atom.xml" />
    <id>tag:www.cordinc.com,2008-02-05:/blog//1</id>
    <updated>2012-05-12T10:33:52Z</updated>
    
    <generator uri="http://www.sixapart.com/movabletype/">Movable Type Personal 4.1</generator>

<entry>
    <title>Debugging context in Unity3D</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/05/debugging-context-in-unity3d.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.198</id>

    <published>2012-05-12T10:31:21Z</published>
    <updated>2012-05-12T10:33:52Z</updated>

    <summary>A cool little feature of Unity3D scripting I recently found is using conditional compilation for debug statements. The C based languages (but not Java unfortuately) have inbuilt preprocessors that allow developers to only compile certain parts of the code if...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unity" label="Unity" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>A cool little feature of Unity3D scripting I recently found is using conditional compilation for debug statements. The C based languages (but not Java unfortuately) have inbuilt preprocessors that allow developers to only compile certain parts of the code if certain parameters are set (it can also do much more, including macros). Thus you could write the below and the code would only be included in the executable if <tt><span class="caps">DEBUG</span></tt> is defined.</p>

<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 55px">

<pre>
#if DEBUG
    // do some special code
#endif
</pre>

</div>

<p>Unity3D has a similar system. Mostly the docs (<a href="http://unity3d.com/support/documentation/Manual/Platform%20Dependent%20Compilation.html">available here</a>) seem to suggest this is for specialist code for different platforms: iPhone, Web, <span class="caps">PC, </span>etc. Thus the defined parameters are set in advance (e.g. <tt><span class="caps">UNITY</span>_IPHONE</tt>). However, there is one that is useful for debugging, <tt><span class="caps">UNITY</span>_EDITOR</tt>. This will only be set if the application is running inside the Unity3D <span class="caps">GUI.</span> Once you build the app those lines of code will be skipped. It can be used like the below example - very handy.</p>

<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 55px">

<pre>
#if UNITY_EDITOR
    Debug.Log(&quot;Debugging&quot;);
#endif 
</pre>

</div>

<p>According to <a href="http://forum.unity3d.com/threads/71445-How-To-Set-Project-Wide-pragma-Directives-with-JavaScript">this Unity3D forum post</a> it is also possible to define your own project specific preprocessor parameters.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Unit Testing UnityScript in Unity3D with SharpUnit</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/05/unit-testing-unityscript-in-un.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.197</id>

    <published>2012-05-04T14:13:05Z</published>
    <updated>2012-05-04T14:18:35Z</updated>

    <summary>I have been programming mainly in Unity3D over the last fortnight, and thought it time to write some unit tests for my work. I found reference to a few testing frameworks online. The most promising appeared to be SharpUnit, and...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unity" label="Unity" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>I have been programming mainly in <a href="http://unity3d.com/">Unity3D</a> over the last fortnight, and thought it time to write some unit tests for my work. I found reference to a <a href="http://unifycommunity.com/wiki/index.php?title=Category%3AUnit_Test_Framework">few testing frameworks online</a>. The most promising appeared to be <a href="http://www.unifycommunity.com/wiki/index.php?title=SharpUnit">SharpUnit</a>, and it is also released under a fairly relaxed license. However, I had to make a few changed to get it running, so this post details that work.</p>

<p>SharpUnit works like a standard unit testing framework for C# code in Unity3D (although all output goes to the console, but that is fine for me). Although my work has largely been in UnityScript (Unity3D's JavaScript like language) and this didn't work so well due to issues with compilation order and SharpUnit's use of .Net custom attributes. After making the changes below, I found SharpUnit works well, and I'll probably be using it for my unit testing.</p>

<p>Unity3D compiles scripts in a set order (<a href="http://unity3d.com/support/documentation/ScriptReference/index.Script_compilation_28Advanced29.html">as described here</a>). Thus if you have C# code that references a UnityScript class there can be a problem - although the reverse is not such an issue. When testing UnityScript with SharpUnit this means that the C# <tt>Unity3D_TestRunner</tt> class can be an issue. It references the <tt>TestCase</tt> classes, which I want to write in UnityScript. To do this I put the SharpUnit code in a folder under the <tt>Plugins</tt> top-level folder (the <tt>Standard Assets</tt> folder would have also worked). This means the SharpUnit code is compiled first. Then my tests went in a new folder together with a UnityScript rewrite of <tt>Unity3D_TestRunner</tt>, as shown below. This UnityScript TestRunner script is then attached to the TestRunner GameObject (in a special testing scene) rather than the C# version as described in the SharpUnit instructions.</p>

<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 210px">

<pre>
#pragma strict

import SharpUnit;

function Start () {
	var suite: TestSuite = new TestSuite();
	suite.AddAll(DummyTest());
	var res: TestResult = suite.Run(null);
	var reporter: Unity3D_TestReporter = new Unity3D_TestReporter();
    reporter.LogResults(res);
}
</pre>

</div>

<p>Other possible solutions to this problem would be to just write my code in C# or to change SharpUnit to load <tt>TestCase</tt> classes dynamically at runtime. Rewriting the TestRunner seemed easiest.</p>

<p>The other problem encountered is that SharpUnit uses the C# custom attribute <tt>[UnitTest]</tt> to identify its test methods. The equivalent in UnityScript is a script directive (see <a href="http://answers.unity3d.com/questions/12911/what-are-the-syntax-differences-in-c-and-javascrip.html">the relevant section here</a>). Thus <tt>@UnitTest</tt> needs to be placed at the top of each test function.</p>

After that change I could run UnityScript tests with SharpUnit. An example test is below:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 350px">

<pre>
#pragma strict

import SharpUnit;

class DummyTest extends TestCase {

    var dummy: String;  

    /** Setup test resources, called before each test. */
    function SetUp() {
        dummy = &quot;lkjkjh&quot;; 
    }

    /** Dispose of test resources, called after each test */
    function TearDown() {
        dummy = null; 
    }

    /** Sample test that passes */
    @UnitTest
    function TestDummy_Pass() {
        Assert.NotNull(dummy);
    }

    /** Sample test that fails. */
    @UnitTest
    function TestDummy_Fail() {
        Assert.Null(dummy);
    }
}
</pre>

</div>]]>
        
    </content>
</entry>

<entry>
    <title>Sicily</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/04/sicily.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.196</id>

    <published>2012-04-27T12:06:06Z</published>
    <updated>2012-04-27T12:11:30Z</updated>

    <summary>I&apos;ve just returned from an underwhelming two week break in Sicily. A Flickr slideshow is viewable here....</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="sicily" label="Sicily" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="travel" label="Travel" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>I've just returned from an underwhelming two week break in Sicily. A <a href="http://www.flickr.com/photos/33547649@N07/sets/72157629910747427/show/">Flickr slideshow is viewable here.</a></p>

<p><a href="http://www.flickr.com/photos/33547649@N07/sets/72157629910747427/show/"><img src="http://farm8.staticflickr.com/7262/6972257770_e73a3020b0.jpg" alt="" /></a></p>]]>
        
    </content>
</entry>

<entry>
    <title>Rio Rambo Course</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/04/rio-rambo-course.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.195</id>

    <published>2012-04-14T08:51:49Z</published>
    <updated>2012-04-14T08:56:00Z</updated>

    <summary><![CDATA[The most oft repeated tale of my time at Rio Tinto R&amp;TD is the Rambo course. Every year a dozen or so staff would be sent on a management training course. Many people were eager to avoid it. Although everyone...]]></summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="memories" label="Memories" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="riotinto" label="Rio Tinto" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="work" label="Work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>The most oft repeated tale of my time at Rio Tinto <span class="caps">R&amp;TD </span>is the Rambo course. Every year a dozen or so staff would be sent on a management training course. Many people were eager to avoid it. Although everyone had to do it at least once and it was advisable to go if you wanted to be promoted (so I was keen). Most people had been multiple times. Since our team was so small, about a third of the facility went each year. </p>]]>
        <![CDATA[<p>It took two consecutive days and we all stayed at a place in the hills surrounding Perth. I wasn't exactly a holiday resort, but comfortable enough. We were split into two teams each with a cross section of staff (in terms of experience). Each team contained one of the managers and had one new hire (a role I fulfilled on my team). Our General Manager was present as a observer and also worked with the facilitator (from some consulting company that Rio apparently used a lot). </p>

<p>The format of the course was alternating sessions of lessons on management with physical tasks. The physical tasks were set up so that during the first session the least experienced member of each team would lead it, and the last practical was led by the most experienced. </p>

<p>The course started with a task, thus I started as a team leader. The idea was that the whole team would be blindfolded and led into the bush. There we would be handed a rope and we had to form it into a square. As team leader I was allowed to remove my blindfold if I wished, but then I wouldn't be allowed to move or touch the rope. I kept the blindfold on. Everyone else had to stay blind regardless. It didn't go very well - neither team completed the task. My team's square was more like a rounded triangle. However, the other team's square wasn't much better, although it was definitely more square-like. </p>

<p>Then we all gathered to analyse the team leader's performance. I just remember getting a bollocking. There were loads of problems. Mostly they revolved around me not communicating enough, so my team wasn't sure what they were supposed to be doing. In traditional consultant fashion, the facilitator ensured we finished with a positive. Apparently staying blindfolded was a good thing to do in Australian groups as it helped keep the leader as part of the group. Among other nationalities removing the blindfold was preferred. </p>

<p>Then points were allocated to the teams. Neither team completed the task so we both only got partial points. We were in competition with eachother!</p>

<p>Then followed various sessions. The management sessions were basic theory combined with information on Rio Tinto. We learnt about the different business units in the company and how to get promoted (act as if you were already at the promoted level). We were also told that there were no more than 7 levels of management. True enough, I worked out that my boss's boss's boss's boss's boss was the <span class="caps">CEO.</span></p>

<p>The physical tasks were fun. The team leaders were keen to impress the General Manager and organised everything. The rest of the team just ran around in the bush trying to win the exercise. At the end of the day we were fed well. Although we had to share bedrooms and my room-mate snored - I slept in the hall and wasn't well rested.</p>

<p>Then started the infamous second day. The teams' scores were close with a single task left. Whichever team won it would win the whole event. The aim was to build a raft to cross a small lake (about 15-20 metres across), collect some widgets from the other side and then bring them back. Points were awarded for each widget returned and there was one widget worth of points separating the teams. The difficulty was increased by the rule that people getting wet were "dead" so couldn't participate further in the task, and that only one widget could be transported on the raft at a time. </p>

<p>I actually suggested that the teams collaborate to build a big raft and bring back all the widgets together. That idea went down like a lead balloon. Having been outed as a naive hippy pacifist, my team sidelined me for the rest of their war planning. Our plan was to quickly build a raft and tie a rope to it. One person would then paddle across the other side and put a widget on the raft and stay on the other side while the team pulled the raft back. This would then be repeated, but the second person would come back with the raft on the return journey. The other team had basically the same plan.</p>

<p>Our raft was completed first. Hastily built from barrels, some wooden planks and rope - it didn't look very stable. Sure enough, the first team member who tried to row it got a couple of stokes before toppling over. The raft was quickly pulled back, but the paddle was left floating in the lake. With one team member "dead" another rower had to be found. I swear all my team mates swivelled to look at me simultaneously. As I didn't have a paddle, I had to use my hands to move the raft (the facilitator ruled that was ok). To improve stability I got myself as close to the water as possible, basically laying down on the raft. I then flapped my hands in the water from the wrists only (no arm movement) to propel myself to the paddle. Even in this position the raft felt very wobbly. One positive was the other team slowed down a bit as they laughed at my "duckling" impression.</p>

<p>After was seemed like ages, I reached the paddle and then crossed to the other side about the same time the other team launched their much more stable raft. From that point on I was largely an observer of the action. The other team soon followed us to the other side. We had a head start, but they were gaining fast due to a better raft. After a few back and forth journeys, the teams had an equal number of widgets. It was down to the last one. I think we just had it (the other team lost one after it got wet). As our raft started its return journey, both teams clustered on the far shore. Our team to shepherd the widget to where it would be scored. The other team to see if they could steal it.</p>

<p>As the raft arrived a scrum developed. Or at least that is how it appeared from my side of the lake. There were a half dozen people heatedly wrestling and a few more on the edges throwing buckets of water (which were ignored). The rules were forgotten and the widget didn't survive (it was made of paper and soon crushed). Eventually it all calmed down and embarrassment ensued. The task was declared a draw and the other team won, although there wasn't much celebration. A grand melee over paper widgets is not a good look in front of the General Manager.</p>

<p>When we got back to the office we all spent nearly a day filling in health and safety reports. Many violation of the rules were detailed. There were numerous bruises, a bad case of rope burn and a few dunkings in the lake. It must have made for strange reading for those not present ("so your work colleague tackled you to the ground, got you in an arm lock and then stole a piece of paper from you"). Luckily, there was video of the whole thing! There was much merriment from the non-participating colleagues  at an office showing. There wasn't a Rambo course held the next year.</p>]]>
    </content>
</entry>

<entry>
    <title>Failure: Unity Javascript in Java VM</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/04/failure-unity-javascript-in-ja.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.194</id>

    <published>2012-04-07T10:13:23Z</published>
    <updated>2012-04-14T08:51:01Z</updated>

    <summary>School science teachers like to emphasize that the failure of an experiment is as useful a learning experience as its success. Of course the high-achieving student knows that is bollocks and ensures their experiements always succeed - if you need...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unity" label="Unity" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>School science teachers like to emphasize that the failure of an experiment is as useful a learning experience as its success. Of course the high-achieving student knows that is bollocks and ensures their experiements always succeed - if you need a straight line, only gather two data points! Despite that I think the underlying idea is correct and experimental failure should not be hidden. </p>

<p>A recent experiment of mine failed. I am writing a game with an online component and wanted the same code running on both the client and server - as this would reduce the chance of bugs. For ease of development <a href="http://unity3d.com/">Unity3D</a> is being used for the client end, so the code there is either Javascript or C#. I have been writing Java servers professionally for years so it seemed silly not to use that knowledge. Clearly there is no common ground there. However, there is a project called <a href="http://www.mozilla.org/rhino/">Rhino</a> to allow Javascript to run inside the Java <span class="caps">JVM. </span></p>

<p>So can Javascript from Unity run in a Java environment? The short answer is "no", but the longer answer is "sometimes, with many caveats".  </p>

Firstly it is possible to run Javascript functions in Java. Load up the Rhino library into the classpath and if you have Javascript code like:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 50px">

<pre>
function square(i) {
	return i*i;
}
</pre>

</div>
then you can run it in Java with the folowing:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 80px">

<pre>
Context cx = Context.enter();
Scriptable scope = cx.initStandardObjects();
Function f1 = cx.compileFunction(scope, readFile(&quot;src/test_fn.js&quot;), &quot;&lt;cmd&gt;&quot;, 1, null);
System.out.println(f1.call(cx, scope, f1, new Object[] {5}));
</pre>

</div>
So far so good. If your Unity Javascript is just a collection of simple functions then this is all that is required. However, there is a good chance this is not the case. Obviously any Unity specific functions and classes are not available (eg Ray, Input, etc). However, more important are the big differences between Unity Javascript and standard (ECMA) Javascript.

<p>Many people say that Javascript in Unity should more accurately be referred to as UnityScript. I think that is definitely true. Although it looks like Javascript there are some fundamental changes. Most importantly, Javascript uses a <a href="http://stackoverflow.com/questions/387707/whats-the-best-way-to-define-a-class-in-javascript">prototype-based scheme to define classes</a>. UnityScript has an inheritance model, and <a href="http://unifycommunity.com/wiki/index.php?title=UnityScript_versus_JavaScript">the two schemes are not compatible</a>. To me these differences are enough to prevent want I wanted to achieve.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Lost Code</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/04/lost-code.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.193</id>

    <published>2012-04-01T14:08:19Z</published>
    <updated>2012-04-01T14:09:04Z</updated>

    <summary>Recently at work I was asked to find out if anyone was still using a small tactical program I wrote. If it was unused, they apologetically asked me to shut it down. No apology was required, but I understand why...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="memories" label="Memories" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>Recently at work I was asked to find out if anyone was still using a small tactical program I wrote. If it was unused, they apologetically asked me to shut it down. No apology was required, but I understand why it was offered. Some developers can become quite precious about their code and want to see it keep running forever. However, after working in this fast-paced industry for nearly 15 years I have long accepted that most of my code is no longer running. I'd be lucky if most of it is even still backed up somewhere rather than being sent to <a href="http://en.wikipedia.org/wiki//dev/null">/dev/null</a>.</p>

<p>Four of my old teams were shutdown with near total loss of code. Another two years were spent at a consulting firm where most of the clients I serviced no longer exist. Those 5 jobs combined mean that half of my working life's production is largely gone. At a guess I would say 10% of the code from my first five working years is still used; around 30% from the second five years; and, over two-thirds of the last 5 years of my code is currently running. My professional code appears to have a half-life of around 4 years. This sounds about right considering the rate of technology change.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Line / Plane Intersection in Unity3D</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/03/line-plane-intersection-in-uni.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.192</id>

    <published>2012-03-26T17:54:22Z</published>
    <updated>2012-03-26T18:31:16Z</updated>

    <summary>In a recent Unity3D game prototype I needed to determine the point of intersection between a line and plane. A player would click on the screen where they wanted their spaceship to go, and I needed to work out where...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="unity" label="Unity" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>In a recent <a href="http://unity3d.com/">Unity3D</a> game prototype I needed to determine the point of intersection between a line and plane. A player would click on the screen where they wanted their spaceship to go, and I needed to work out where that actually was in the world coordinates. The line is defined by the camera point and the point on the screen clicked (as given by <tt>camera.ScreenToWorldPoint</tt>). The plane was the spaceship (assuming no up or down movement).  </p>

<p><img src="http://www.cordinc.com/blog/line_plane.png" alt="" /></p>

<p>If the line was intersecting an object in the scene then this could be easily achieved with Unity3D's built in functions. In this case by casting a ray from the camera and finding the objects it hits (see the <a href="http://unity3d.com/support/documentation/ScriptReference/Physics.Raycast.html">Raycast help page</a>). However, my prototype is set in space, there is no object there to hit other than a small spaceship. </p>

First, let's work out the equation of the line from the camera (point 'c') and the mouse click (point 'm'). We can get the position of the camera with <tt>var c = camera.transform.position</tt> and the position of the mouse click with:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 40px">

<pre>
var s = camera.ScreenToWorldPoint(Vector3(Input.mousePosition.x, Input.mousePosition.y, 100.0)); 
</pre>

</div>
Note that in the above, the third vector parameter (the Z value) in the <tt>ScreenToWorldPoint</tt> call is the distance from the camera of the resulting point. Thus if 0 or <tt>mousePosition.z</tt> (which is also 0) is used then the resulting point is just the camera location itself. Here I have used a distance of 100 to make sure there is a good separation between the points describing the line. The <a href="http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html">general equation of a line in 3 dimensions</a> is (for the points c &amp; m):<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 40px">

<pre>
[c.x + (m.x - c.x) * t, c.y + (m.y - c.y) * t, c.z + (m.z - c.z) * t]
</pre>

</div>
So to find the point of intersection requires solving that simultaneously with the equation of the plane. Here is where my scenario gets easy. The plane this line intersects with in my game is the horizontal plane the spaceship is current only. That is the plane is described by:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 30px">

<pre>
y = spaceship.y
</pre>

</div>
At some point on the line the following holds as long as the line intersects at some point:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 30px">

<pre>
spaceship.y = c.y + (m.y - c.y) * t
</pre>

</div>
which means:<br />
<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 90px">

<pre>
if (m.y == c.y) {
   t = 0; // no intersection
} else {
   t = (spaceship.y - c.y) / (m.y - c.y); 
}
</pre>

</div>
The case <tt>m.y == c.y</tt> denotes the case where the line does not intersect the plane. What happens here is up to you. With the value of 't' known the equation for the line can be solved to give the point of intersection. Done.]]>
        
    </content>
</entry>

<entry>
    <title>La Trobe University Archaeology</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/03/la-trobe-university-archaeolog.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.191</id>

    <published>2012-03-17T10:57:06Z</published>
    <updated>2012-03-17T11:06:23Z</updated>

    <summary>Available from iTunes or from the La Trobe University Podcasts page (but they will have to be found individually as there does not appear to be a series webpage). This is a series of talks and interviews from the La...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="history" label="History" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="podcasts" label="Podcasts" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>Available from <a href="http://itunes.apple.com/gb/itunes-u/archaeology/id394588178">iTunes</a> or from the <a href="http://www.latrobe.edu.au/news/podcasts">La Trobe University Podcasts page</a> (but they will have to be found individually as there does not appear to be a series webpage).</p>

<p>This is a series of talks and interviews from the La Trobe University Archaeology department. The topics vary wildly, from the traditional Ancient Egypt and Cyprus, to relatively modern digs in <a href="http://en.wikipedia.org/wiki/Melbourne">Melbourne city</a> (founded in 1835). As the series is archaeologically focussed there is more emphasis on the extraction and identification of objects than history. At present there are 12 episodes - 2 are short videos (around 3 minutes) and the remainder are audio only. Two of the audio podcasts are hour long scholarly presentations, while the other 8 are interviews of between 15 to 20 minutes duration. There may be more episodes in the series as the entries so far have trickled in over the last 2 years. Production quality is high for the whole series. </p>

<p>There are two podcasts on archaeology in <a href="http://en.wikipedia.org/wiki/Oceania">Oceania</a>, particularly <a href="http://en.wikipedia.org/wiki/Hawaii">Hawaii</a>. One is an academic presentation, while the other is an interview with the same presenter on the same topic. There is some talk on <a href="http://en.wikipedia.org/wiki/Collapse:_How_Societies_Choose_to_Fail_or_Succeed">Jared Diamond's  Collapse book</a>. Diamond suggests that society on the Polynesian island <a href="http://en.wikipedia.org/wiki/Mangareva">Mangareva</a> due to overforestation. However, the presenter's research suggests instead that the deforestation was caused by a lack of phosphorus in the soil due to the killing of sea birds. The discussion of Hawaii is similarly focussed on the affect of intensive cultivation on soil quality. Unsurprisingly the indigenous people started agriculture on the best land and as population grew, expanded out to less productive land. Once all arable areas were cultivated, the land became more subdivided and population growth slowed. Also there is evidence of political consolidation beginning around the same time.</p>

<p>Another paired presentation and interview discuss excavations at the ancient Egyptian capital <a href="http://en.wikipedia.org/wiki/Akhetaton">Amarna</a>. They are focussed on the industry of the time - in particular small metal work and glazed pottery. Details of the materials used are probed with <a href="http://en.wikipedia.org/wiki/Synchrotron">synchrotrons</a> and a bit of experimental archaeology is conducted to determine the techniques used to manufacture them.</p>

<p>Another episode details the search for ships lost in Vietnam by the Chinese emperor <a href="http://en.wikipedia.org/wiki/Kublai_Khan">Kublai Khan</a> at the <a href="http://en.wikipedia.org/wiki/Battle_of_B%E1%BA%A1ch_%C4%90%E1%BA%B1ng_(1288)">Battle of Bach Dang</a>. Three episodes (including both video podcasts) discuss the tools and evolution of early humans, especially the position in the evolutionary tree of some complete skeletons recently found in <a href="http://en.wikipedia.org/wiki/Sediba">Sediba</a>. There is also an interview about bronze age burials in Cyprus and other podcasts focus on the archaeological difficulties and discoveries underwater or in cities.</p>]]>
        
    </content>
</entry>

<entry>
    <title>NavigableMap &amp; time-based caches</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/03/navigablemap-timebased-caches.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.190</id>

    <published>2012-03-10T09:52:16Z</published>
    <updated>2012-03-10T09:56:44Z</updated>

    <summary>NavigableMap I often find myself writing time-based caches. Something like storing the last X hours of ticks from a data feed. Most teams I join usually have a utility class to help with such tasks. In a recent move I...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="java" label="Java" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="technical" label="Technical" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>NavigableMap</p>

<p>I often find myself writing time-based caches. Something like storing the last X hours of ticks from a data feed. Most teams I join usually have a utility class to help with such tasks. In a recent move I joined a team that didn't have such a utility, but did have a need for such a cache. Before coding, I thought I do a quick check to see if anything new had come along to help. At this point I discovered the Java 6 <a href="http://docs.oracle.com/javase/6/docs/api/java/util/NavigableMap.html">NavigableMap</a> interface.</p>

<p>NavigableMap defines a type of sorted map with handy methods for obtaining submaps. So to get a map of the entries greater than a particular value use the <tt>tailMap</tt> method. The corresponding method for the submap less than a value is <tt>headMap</tt>. These methods return a view on the original map. So changes to the submap are reflected in the original map. The <span class="caps">JDK </span>provides <a href="http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ConcurrentSkipListMap.html">concurrent</a> and <a href="http://docs.oracle.com/javase/6/docs/api/java/util/TreeMap.html">non-concurrent</a> implementations of the interface.</p>

<p>This is very useful for a time-based cache. Create a NavigableMap sorted on the time (I used the epoch milliseconds returned by <tt>System.currentTimeMillis()</tt>) then <tt>tailMap</tt> returns the entries younger than a given time, and <tt>headMap</tt> those older. So to trim the cache of entries older than a certain time use <tt>headMap(System.currentTimeMillis() - maxAge).clear()</tt>. So easy!</p>

<p>Here is a complete time-based cache class for use as an example.</p>

<div style="background: #DFE8DF; overflow: auto; padding: 2px; margin-bottom: 10px; margin-top: 1px; height: 300px">

<pre>
public class TimeSeriesCache&lt;V&gt; {

    private static final int MILLIS_IN_MINUTE = 60 * 1000;
    private static final int CLEAR_OLD_PERIOD_MINUTES = 1;

    private final NavigableMap&lt;Long, V&gt; series = new ConcurrentSkipListMap&lt;Long, V&gt;();
    private final Set&lt;TickListener&lt;K, Long, V&gt;&gt; subscribers;

    public TimeSeriesCache(int maxAgeMinutes) {
        if (maxAgeMinutes &gt; 0) {
            final int maxAge = maxAgeMinutes * MILLIS_IN_MINUTE;
            Executors.newSingleThreadScheduledExecutor().scheduleWithFixedDelay(
                    new Runnable() {
                        @SuppressWarnings(&quot;boxing&quot;)
                        @Override public void run() {
                            series.headMap(System.currentTimeMillis() - maxAge).clear();

                        }
                    }, CLEAR_OLD_PERIOD_MINUTES, CLEAR_OLD_PERIOD_MINUTES, TimeUnit.MINUTES);
        }
    }

    public Collection&lt;V&gt; getSeriesAfter(Long fromTimestamp) {
        return series.tailMap(fromTimestamp).values();
    }

    public void add(V value) {
        series.put(System.currentTimeMillis(), value);
    }

    public void add(Long timestamp, V value) {
        series.put(timestamp, value);
    }
}
</pre>

</div>]]>
        
    </content>
</entry>

<entry>
    <title>Kuala Lumpur</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/03/kuala-lumpur.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.189</id>

    <published>2012-03-03T16:47:24Z</published>
    <updated>2012-03-03T16:47:59Z</updated>

    <summary>I&apos;m not sure how many people who read this blog actually know me in person - probably very few. However, for those that do, I am moving. Towards the end of the year (the exact date is still uncertain), I&apos;m...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="general" label="General" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>I'm not sure how many people who read this blog actually know me in person - probably very few. However, for those that do, I am moving. Towards the end of the year (the exact date is still uncertain), I'm physically moving to <a href="http://en.wikipedia.org/wiki/Kuala_Lumpur">Kuala Lumpur</a>. Virtual location (email, website, etc) will remained unchanged. It is not yet known what I'll be doing there - there are some work visa issues to be sorted out.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Game Reviews Again</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/02/game-reviews-again.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.188</id>

    <published>2012-02-26T10:23:52Z</published>
    <updated>2012-02-26T10:25:15Z</updated>

    <summary>Almost exactly six months ago I wrote a review of some modern computer games. All were well known, and I said they were all excellent. I even suggested that computer games were in a golden age - better than ever...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="games" label="Games" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>Almost exactly six months ago I wrote a <a href="http://www.cordinc.com/blog/2011/08/modern-gaming.html">review of some modern computer games</a>. All were well known, and I said they were all excellent. I even suggested that computer games were in a golden age - better than ever before. Now I have completed 3 more well known, highly regarded, recent games. How did they do in comparison? Not as well unfortunately.</p>

<p>First up I played <a href="http://en.wikipedia.org/wiki/Call_of_Duty_4:_Modern_Warfare">Call Of Duty 4: Modern Warfare</a>, the original 2007 Modern Warfare game which spawned the incredibly popular series of <a href="http://en.wikipedia.org/wiki/First-person_shooter">first-person shooters</a> of the same name. At first I was impressed with the intensity of this game. However, the fast pace quickly slows with realisation there is essentially no penalty to getting shot. Death is a mere slight pause. I felt like I was on rails, being led through the action. The game was just a reaction speed test. Multiplayer is probably better, but I didn't play that - I doubt my reactions are fast enough. The story is ok, nothing special. Although I did detect a possible subtle satire on war - but that could just be me. The story is most notable for a couple of impressive famous scenes (the nuke level and the gunship level) that do work very well. This game is probably too linear and twitchy for me.</p>

<p>Next up I played <a href="http://en.wikipedia.org/wiki/Assassin's_Creed:_Brotherhood">Assasins Creed: Brotherhood</a>. I was particularly looking forward to this game because of its open world setting in medieval Rome. Certainly the graphics are beautiful and I enjoyed wandering around the ruins of Rome. But the controls! This game was incredibly frustrating - it was hard to get my avatar to perform as intended. I tried for many hours (28 total), but still found myself often shouting at the computer and cursing the clumsy controls. Eventually I just raced to finish the main story. Incidently, the story is very silly and not worth discussing. This game could have been so much better, but is just annoying.</p>

<p>Just a few days ago I completed <a href="http://en.wikipedia.org/wiki/BioShock">Bioshock</a>. This is an excellent game, restoring my belief in modern gaming after the previous two disappointments. The Ayn Rand-gone-wild underwater setting is incredible. The art-deco and slightly cartoony (but I think that was the point) graphics are decent. I often found myself just walking around looking at the banners and architecture. Most importantly the controls were super smooth. The game was also quite intense, particularly at the start and end. Sometimes I jumped at a surprising action or went looking for someone I could hear nearby. It is interesting that both this game and Mass Effect 2, give the player some small choices that make minor differences to gameplay, as opposed to the lack of agency in Modern Warfare. A little choice (even if it is fairly inconsequential in plot terms) goes a long way in making the player feel involved. </p>]]>
        
    </content>
</entry>

<entry>
    <title>Rio Tinto R&amp;TD (continued)</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/02/rio-tinto-rtd-continued.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.187</id>

    <published>2012-02-19T13:29:04Z</published>
    <updated>2012-02-19T13:52:49Z</updated>

    <summary><![CDATA[After joining Knowledge-based Systems at Rio Tinto R&amp;TD, my first task was working on the MineSim project. This was a very successful application to simulate minesites. To do this a user would define the topology/geology of a mine, the equipment/personnel...]]></summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="memories" label="Memories" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="riotinto" label="Rio Tinto" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="work" label="Work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>After joining Knowledge-based Systems at Rio Tinto <span class="caps">R&amp;TD, </span>my first task was working on the MineSim project. This was a very successful application to simulate minesites. To do this a user would define the topology/geology of a mine, the equipment/personnel available and the goals to pursue. The program would then simulate the mine minute by minute. New blocks would be blown when ready, little loaders would muck out the ore from the block and large trucks moved round the mine, picking up ore and driving back to the dumps. </p>]]>
        <![CDATA[<p>It was incredibly detailed. At the end of shifts workers would have to be ferried around the mine, Muslim workers would take regular breaks for prayers, people got sick and equipment broke down. Trucks would plot their own route dynamically to take account of various events like mine road rules, breakdowns and new areas becoming accessible or inaccessible. It even simulated the engine dynamics of vehicles so their speed and acceleration/braking profile were accurate. Very accurate as it turned out. When checked against reality, our model was more accurate than the manufacturers'. A certain US manufacturer slightly overstated their trucks performance in marketing materials, while a Japanese manufacturer slightly understated. When backtested against a couple of real-life mines the whole simulation was accurate to within 3% of mine output over a couple of months. Good enough for how it was being used (testing the effect of various actions like buying more trucks or the order of block development). </p>

<p><img src="http://www.cordinc.com/blog/omme_example.png" alt="" height="391" width="500" /></p>

<p>The application could run in a <span class="caps">GUI </span>if desired or alternatively just run as fast as possible to the end. The picture above is the simulation zoomed in on part of a mine (found in an old email). Adding a <span class="caps">GUI </span>was an inspired decision. The mine would be shown as a graph with lines representing roads. Trucks and other equipment were marked as little squares - colour denoting type and size representing how much ore was carried. Watching the squares moving around the screen at 10x normal speed was hypnotic. It almost felt like a primitive game. It also gave our customers confidence in the simulation when they saw it happening right in front of them. It was also inspired to have the inputs and outputs work through Microsoft Excel (rather than more technically respectable formats) as the customers on mine sites were comfortable with that tool and it made visualising data easy. </p>

<p>When I started on MineSim it had already been developed and used on a couple of <a href="http://en.wikipedia.org/wiki/Open-pit_mining">opencut mines</a>. My job was to make it support underground mines and expand it so that multi-year simulations could be run. The application at that time took nearly a day to simulate half a year. This is probably the closest I've come to proper algorithm work in my professional career. I improved the graph traversal code (used by the trucks to find a path) by recognising some properties of the graph and rewriting the existing suboptimal implementation. There were some other gains to be made by modifying the large amount of code written by mathematicians who taught themselves programming. </p>

<p>Underground mines are run in a very dissimilar manner to open mines. The processes and equipment are quite different. A well-capitalised underground mine digs its main shaft first and then extracts ore from the bottom up (it is cheaper than going top-down, but takes longer to get started). This means that after "mucking out a stope" (meaning extracting ore from a designated block of rock), it has to be filled in again so trucks can drive on top of it when mucking out the level above. This and other improvements to MineSim consumed my working life for my first months at Rio Tinto.    </p>

<p>The end of the project was supposed to coincide with a visit to the underground gold mine sponsoring it. We would present them with the application and train them in its use. It took flights on ever smaller planes to reach <a href="http://en.wikipedia.org/wiki/Cobar,_New_South_Wales">Cobar</a>, the nearest town in outback Australia. I was looking forward to seeing a working mine. Unfortunately when we arrived it was shut down due to an accident with the shaft lift the day before. No one was even in the mine at the time of the incident (the lift was operating automatically during shift change), but as a safety precaution everything was stopped for a week while the cause was determined. It was impressive how serious safety was taken. </p>

<p>It was probably a good thing there was no tour, it was a very busy trip. Our first action was to give a presentation on the program. The mine staff were impressed. They said most other people modelled filling in a stope as negative digging, but we simulated the myriad of steps involved.  We were the most accurate simulation of underground mining they had seen. Then they spent some time telling us what we had done was still not good enough. It was an important lesson in the pitfalls of <a href="http://en.wikipedia.org/wiki/Waterfall_model">Waterfall process</a>. We should have been talking and confirming we were building the right thing the entire time. I ended spending all day, every day trying to fix our code. At the end they were happy enough to keep funding the work. They got everything they wanted a couple of months late.</p>

<p>Part of travelling to a mine site was being given official Rio Tinto clothes. At the office we just wore normal office clothes. At "site", we had to wear special clothes: steel-capped boots, hard wearing trousers and shirts (with our names embroidered on them). I was given these clothes a few days before leaving and when I arrived on site it was the first time they were worn. I was immediately an object of ridicule. The mine workers asked if my mother had dressed me. It seems that <span class="caps">R&amp;TD </span>people had a reputation as soft city people and brand new, clean, site clothes just played to the stereotype. My team leader didn't shave that first morning and his clothes were uncleaned - the mine workers accepted him. The lesson was learnt. It was also quickly reinforced. In the afternoon the Beard arrived after travelling separately to the team leader and I. The Beard was an older mining engineer who had transferred from the mines to work at <span class="caps">R&amp;TD.</span> At the office he was always well-spoken and well-dressed, often with a natty waistcoat. When he arrived at the mine it looked like he had been lost in the bush for a week and just crawled out. As soon as he was spotted he turned the air blue with swearing. I was amazed how differently he acted looked and compared to the office. The mine workers loved it - they were all instant friends! One person joked that <span class="caps">R&amp;TD </span>had finally sent a real man. I just went back to my coding.</p>

<p>The MineSim manager was pretty cool and one of the best manager's I've had. When I needed to vent about some dodgy mathematician code (a 6 page function, containing tens of nested if-statements), he let me and then told me to go fix it. He managed to be friendly, but still get us working (to his advantage there was never a huge pressure to get something finished to a tight deadline). Senior management must have liked him too, as he was one of the few saved from redundancy at the end. He used to write two sets of travel reports: the official ones; and the version just for the team, written in a <a href="http://en.wikipedia.org/wiki/Gonzo_journalism">gonzo</a> style - very funny. When <span class="caps">R&amp;TD </span>was reoganised he managed to get our team renamed <span class="caps">REPO </span>so he could use <a href="http://en.wikipedia.org/wiki/Repo_Man_(film)">Repo Man</a> movie quotes like "the life of a repo man is always intense" and "ordinary fucking people, I hate 'em". I can't remember what <span class="caps">REPO </span>actually stood for, it was a fairly tortured acronym if recall correctly. His vision was that MineSim would evolve into an automated mine system. I hear Rio Tinto is starting to move in this direction. However I doubt any of our code survived. It would be surprising if anyone currently working on mine automation was ever aware of our work.</p>

<p>Besides the underground work I did various other little jobs on the MineSim project during my time at Rio Tinto. Including some work for a diamond mine and a coal mine. There was also an aborted attempt to produce a similar project for ore processing plants. It was to be OreSim (pronounced "AWE-some"). It never went anywhere as it seemed we couldn't get anyone interested in it. That was the problem with <span class="caps">R&amp;TD.</span> We were seen as internal consultants, but not very practical ones. Our work took time to produce and was all this "computery stuff" done by people who hadn't spent much time at real minesites. When we did produce something worth while we couldn't sell it to other companies due to our internal status. Thus we never got any scale. I believe MineSim could have been sold on the wider market, we sometimes heard favourable comparisons between us and commercial competition. A training product we produced was actually requested by a competitor. It would have been a big sale, easy, and not in any way a matter of competitive advantage (it was safety training). So it was suggested to senior management, who refused it. We had no real advantages as internal staff - we still had to market and sell our services to mines. However, we were handicapped by not being allowed to compete properly. </p>

<p>There were a few other projects I worked on: an optimisation tool for a coal port in <span class="caps">NSW</span>; a website with searchable mine information; and, a travellers advice website (unofficially nicknamed <a href="http://en.wikipedia.org/wiki/Robert_Bogucki">Bogucki Net</a> after a lost tourist). My part of these wasn't particular interesting. I did the <a href="http://en.wikipedia.org/wiki/Object-relational_mapping"><span class="caps">ORM</span></a> for the port tool and the search and display for the websites. The port work was most notable for difficulties with the first-timer team leader - he was micromanaging, dismissive and insulting. It got to the point I had to make a complaint to my manager (the only time in my working life). It turned out the other team member had also complained about the team leader too, so everyone calmed down and was on their best behaviour until the end of the project.</p>]]>
    </content>
</entry>

<entry>
    <title>Rio Tinto R&amp;TD</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/02/rio-tinto-rtd.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.186</id>

    <published>2012-02-12T10:40:24Z</published>
    <updated>2012-02-19T13:40:24Z</updated>

    <summary>After Electrolley I worked at Rio Tinto in their Research and Technical Development division. I had wanted a job there for sometime. Many of my honours classmates and one of my ex-lecturers (the one I originally wanted as my honours...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="memories" label="Memories" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="riotinto" label="Rio Tinto" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="work" label="Work" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[<p>After <a href="http://www.cordinc.com/blog/2011/03/electrolley.html">Electrolley</a> I worked at <a href="http://www.riotinto.com/">Rio Tinto</a> in their Research and Technical Development division. I had wanted a job there for sometime. Many of my honours classmates and one of my ex-lecturers (the one I originally wanted as my honours supervisor) worked there. I had interviewed with them during my PhD, but was rejected as the position was for a more practical programmer and they saw me as too theoretical. After a few months at Electolley I was contacted saying a position more suited for my skills had arisen and asking if was I still interested. Soon I was being interviewed again.</p>

<p>The interview process was the most arduous I've ever encountered. First there was an interview by a couple of managers. Then another interview by the entire team I would be joining. A panel of nine people arrayed in front on me. During this part they asked me to give an impromptu 15 minute presentation of my ex-PhD topic. A quizzing on its practical applicability followed. By this stage I have been onsite two hours and they said it was time for the next stage. I was taxied into the city and given a battery of psychometric tests. There was a logical reasoning test (well-above average), vocabulary test (average), Myers-Briggs test (INTP, as always) and another test I'd never heard of before to check my work aptitude. Nearly 5 hours in total and I was completely drained.</p>

<p>I got the job and after a few months I heard that it didn't really matter what the tests said. Half the team (including the manager) knew me from uni or honours, so unless I had a breakdown the job was always mine. To prove the point I was told the results of the psychometric tests. Apparently the unknown test had indicated I was completely unemployable and unable to work in a team. They ignored it and hired me anyway.</p>

<p>The Rio Tinto <span class="caps">R&amp;TD </span>team in Perth was in beautiful purpose built building near Curtin University. It was designed to be like a village - a central street walkway acting as a street with trees and benches (all inside). Off the walkway came the open plan office space. There was also a large reception, board room, library, large eating area and kitchen. No canteen, but I never heard of anyone in Perth having a canteen. It was set on landscaped grounds with more than enough parking and there was tons of natural light. A very pleasant workspace. The only problem was the abandoned building and the emptiness.</p>

<p>The complex was built to house over 300 staff, but never housed more than 55 people while I was there. There was another entire building with workshops unused and locked up. Most of my colleagues spread themselves out over 2 desks. A couple of months before I started there was over 200 people on site. Most desks were taken and the workshops full of engineers. However, many were made redundant or transferred around the time of my interview. Four small teams were left (plus admin staff). </p>

<p>I was in Knowledge-Based Systems. We were supposed to focus on applying machine learning techniques (like expert systems) to mining problems. Although most of our time was spent writing mine simulations, linear optimisation systems (basically the <a href="http://en.wikipedia.org/wiki/Simplex_algorithm">simplex method</a> with a large number of variables and a nice <span class="caps">GUI</span>) or training tools. There was another team of more "practical" software developers working with early web technologies. On the non-computer side was a team of mathematicians and engineers doing various consulting tasks and a small team focused on <a href="http://en.wikipedia.org/wiki/Computational_fluid_dynamics" title="CFD">Computational Fluid Dynamics</a> in smelters. </p>

<p>With just 1st class Honours I was clearly one of the least educated people in the building. Their was a distinct academic bias. Most of the senior managers had PhDs, as did probably a third of the staff. People generally had time to think - although that may not have been a good indicator for future prospects. There were often discussions of very scientific topics and opinions were always well informed. Here I learnt the more theoretical side of software engineering with regular arguments on what process or pattern was best in a certain situation. Later I learnt the more practical side.</p>

<p>While I was there the place had an eerie atmosphere. All non-managers openly believed that we would all be made redundant sooner rather than later. Everyone knew the intimate details of the redundancy policy. It was very generous so staff turnover was low as people waited for their inevitable payout. I remember hearing a couple of anonymous shouts of "make me redundant now!". There was a bit of black humour around the situation. When the head of the global technology division changed we joked about him being an evil leprechaun (he had an unfortunate staff photo) who would sack us all. We were right!</p>

<p>The site was also extremely safe. All sites in Rio Tinto apparently followed the same safety precautions. Thus our research office building took safety as seriously as a mine site. There was a sign at the entrance proudly displaying there there had been no lost time due to injury for over 600 days (not sure the actual number, but it was years). Towards the end of my time there the counter reset after a morning was lost when a minor traffic accident resulted in a checkup at the doctors (they were fine). We had a safety manager who trained us all on the safety precautions. Every month he would tour the site for safety violations and hand out cautions - normally for overly large stacks of paper or dirty mugs. I felt a little sorry for the guy, there wasn't much for him to do. He previously had a similar job at a mine, which must have been much more interesting. Although it was impressive how after I casually mentioned my fingers ached a little one day to see how serious it was taken. I was visited by an outside ergonomics expert who recommended my desk be lowered a few centimeters. That afternoon it was dismantled and rebuilt! The expert was right, the new desk was much better.</p>

<p>I sat with two colleagues is a small area of desks partitioned off between a reception desk and the General Manager's office. The area was partitioned into thirds, each section with 2 desks, 2 PCs, etc. We took one section each. It was a good little spot. The partitions went up to eye level, and there was only one place to enter the area. The partitions were also setup such that to reach the back thirds a visitor would need to make a couple of 90 degree turns. Furthermore large pot plants had been placed at strategic points to block sightlines into the area. The basic affect was that we could tell when someone was coming towards us, but they couldn't see what we were doing. Knowing the person who sat furthest from the entrance (an aspiring DJ), I don't think this setup was unintentional. For the same reason none of the three of us could see eachothers' screens. I had two PCs, but only ever used one, a decent second hand computer (from someone recently made redundant - Pentium2 with a 17" CRT, good for the late 90's). One of the other guys had 2 PCs and bright blue <a href="http://en.wikipedia.org/wiki/SGI_Indigo">Silicon Graphics Indigo</a> machine for a 3D modelling project he did - very cool. </p>

<p>As a small office in a global company we traveled often to various mining sites around the world. I only went once, to an Australian gold mine, which I will write about later. Others went around the world. The one place I would have like to have visited was the <a href="http://en.wikipedia.org/wiki/Grasberg_mine">Grasberg mine in Indonesia</a> - a very large gold and copper mine up a tropical mountain. There was some talk of sending me there to run a training course, but I didn't act keen and the timing wasn't good with my other projects. In retrospect I should have volunteered. <a href="http://en.wikipedia.org/wiki/West_Papua_(province)">Irian Jaya</a> is a place that most foreigners (or even Indonesians) do not get a chance to visit. There were always good stories about visits. During the <a href="http://en.wikipedia.org/wiki/1997_Asian_financial_crisis">Asian financial crisis in 1997</a> one colleague visiting there managed to run up an enormous 5 digit expenses bill - he occasionally told snippets of the story of his few days living the high life. Management were aghast, but I had the sense they were slightly impressed with the ability to spend so much when the local currency was so cheap.</p>

<p>Soon after I declined the trip to Grasberg one of our staff visiting the mine was threatened with a spear when some locals bust into the onsite offices. I think it turned out to be a dispute over a pig, but management was greatly concerned as there is a low-level insurgency in the area (over independence from Indonesia). No one from our office ever went there again. </p>

<p>Working at <span class="caps">R&amp;TD </span>was fairly pleasant on a day-to-day basis. It was small enough for us all know eachother, and there was a slight siege mentality - us versus the off-site management wanting to shut us down. Everyone got a mug with their name (or nickname) printed on it when they started work. This stopped the problem everywhere else about disappearing mugs/cups. I still have mine 12 years later. When an eclipse occurred we all headed outside for the afternoon to see it. There was a social committee which arranged various regular small events. I was actually a member or the committee for a while. I arranged the Christmas Party river cruise right before I left. In fact I didn't go to the party I organised, it didn't seem right as I quit and left a few weeks before the event. </p>

<p>I also tried to get involved in the company superannuation/pension plan. They had elections for staff representatives on the plan's board. I thought it would look good on my resume. Most of the people I worked with acted bemused when told I was running. My campaign was fairly weak, consisting mainly of writing a blurb for the company magazine (As did all the other candidates). In the end I think I got about 20 votes, not even half the people I worked with. The winners got thousands of votes.</p>

<p>After I had been at Rio just over a year, the work starting slowing, senior management swapped jobs and a review was announced. It seemed like the end was nigh. I knew the redundancy policy very well (as did everyone) and until I had been there over two years I would receive very little. It seemed unlikely I would make it that far or be promoted. It is best to jump than be pushed so I looked around. Finding a job in the dotcom boom was not too hard, and I left after 18 months at Rio. A few months later all but a handful of my ex-colleagues were sacked and the facility shuttered. My timing was just right.</p>

<p>My last memories of working at Rio were having competitions with the aspiring DJ next to me over who could leave earliest. He won by leaving at 3pm, walking past the General Managers office and saying goodbye before walking out. I didn't have the balls to top that even though I had quit. On my last day we all went to the pub for lunch. I left about 4pm, my manager and most of his team were still there (and stayed late into the night). He teased me for leaving "early". </p>

<p><a href="http://www.cordinc.com/blog/2012/02/rio-tinto-rtd-continued.html">Continued with details of the tasks I performed while at Rio Tinto</a>.</p>]]>
        
    </content>
</entry>

<entry>
    <title>Bonds: Addendum</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/01/bonds-addendum.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.185</id>

    <published>2012-01-21T12:02:16Z</published>
    <updated>2012-01-21T12:04:52Z</updated>

    <summary> Part 1 - The Theory Part 2a - The Reality Part 2b - The Reality continued Part 3a - The Technology Part 3b - The Technology continued Part 4 - The Future After writing 6 long posts on my...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="finance" label="Finance" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="general" label="General" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[
<ul>
<li>Part 1  - <a href="http://www.cordinc.com/blog/2011/10/bonds-part-1-the-theory.html">The Theory</a> </li>
<li>Part 2a - <a href="http://www.cordinc.com/blog/2011/10/bonds-part-2a-the-reality.html">The Reality</a></li>
<li>Part 2b - <a href="http://www.cordinc.com/blog/2011/12/bonds-part-2b-the-reality-cont.html">The Reality continued</a></li>
<li>Part 3a - <a href="http://www.cordinc.com/blog/2011/12/bonds-part-3a-the-technology.html">The Technology</a></li>
<li>Part 3b  - <a href="http://www.cordinc.com/blog/2012/01/bonds-part-3b-the-technology-c.html">The Technology continued</a></li>
<li>Part 4 - <a href="http://www.cordinc.com/blog/2012/01/bonds-part-4-the-future.html">The Future</a></li>
</ul>



<p>After writing 6 long posts on my experiences in <span class="caps">EGB IT,</span> I realised I still missed out many points. Here they are in no particular order.</p>]]>
        <![CDATA[
<ul>
<li>Investment banks suffer from serious title inflation. I used to joke that the guy who cleaned the toilets was probably a Vice President. If someone gives you a card with Associate VP or VP on it this doesn't mean much, most of my co-workers in IT had such titles. First line managers were sometimes had the title Director - their managers definitely had at least that title. It goes without saying they didn't sit on any company board. Managing Directors are basically middle managers. Be aware of this when seeing a banking business card.</li>
</ul>




<ul>
<li>Squawkboxes are the most noisy thing on a trading floor. They are an old fashioned cross between a phone and intercom. They have a microphone, a speaker and a large set of quick-dial buttons to other squawkboxes in the same firm. They can also work as phones. When one of the buttons is pressed anything spoken into the microphone automatically comes out of the targeted squawkbox - no chance to screen or block the message. Traders love them for talking to support and salespeople - normally in a loud voice. I refused to have one on my desk once (I dismantled it and put it in my drawer). It is just too distracting to have traders contact you whenever they feel like it. </li>
</ul>




<ul>
<li>Banks are full of compliance training. Each year front office staff have to do courses on diversity, money laundering, privacy, ethics and occasionally other topics. The courses consist of simple online training followed by an even simpler multi-choice test. If you fail the test, you just take it again immediately - most of the questions are the same. Rarely does anyone fail more than twice, especially since the content is the same each year. They are generally derided by all who have to do it, passing requires little more than remembering: stealing is wrong; you should be nice to everyone; you shouldn't talk about client details; and, talk to compliance people if you are not sure about something.</li>
</ul>




<ul>
<li>The <span class="caps">FSA </span>also requires front-office staff to take two continuous weeks away from contact with the office. This is to help prevent fraud. The idea being that most frauds would be detected if the perpetrator is not around to keep it hidden. At three of the four banks I have worked this applied to front office IT people too. It's a good idea I think.</li>
</ul>




<ul>
<li>Chinese walls (how did that term get past the diversity training?) abound in banks. That is where two parts of a bank should not talk to eachother for ethical reasons. For example, staff negotiating a potential takeover shouldn't talk to people who could trade on that information. Often these Chinese walls are manifested physically with walls and restricted access doors. At one bank a chest high row of filling cabinets was used. I sat within sight of this "wall" and often saw traders having a chat with the people on the other side. I'm sure no restricted information was ever mentioned.</li>
</ul>




<ul>
<li>There is a concept in trading called "fatfinger", it is where someone enters data incorrectly, for instance buying 100 units of an instrument rather than 10. This happens often. Checking for this kind of activity is one of the reasons every keypress in a trading <span class="caps">GUI </span>is recorded.</li>
</ul>




<ul>
<li>Phone calls are recorded in banks, as I write this a trader a few desks down is complaining a client just asked him to do something slightly dodgy on a "taped line".</li>
</ul>




<ul>
<li>Slightly dodgy things happen all the time. The technology based ones that I see are accidental and tend to lose money. For instance, a bug in a trading system could result in actions that may constitute minor market manipulation - but such a situation would also most likely result in a loss for the bank, so no-one seems too concerned. Occasionally there are much bigger issues. The famous <a href="http://www.bloomberg.com/apps/news?pid=newsarchive&amp;sid=akZET4F5.H3k">Dr Evil trade by Citigroup in 2004</a> was blatant market manipulation of <span class="caps">EGB </span>futures. Although many people around at the time suggest the fines levied were smaller than the profit made.</li>
</ul>




<ul>
<li>One bank I worked at boasted that during the Dr Evil trade they didn't lose as much as other banks due to their defensive systems. Most <span class="caps">EGB </span>desks have various protections against putting out bad prices on the executable <span class="caps">D2D </span>markets. If the futures prices move too much all the quotes are pulled. If their quotes are lifted a couple of times in a few seconds all quotes are pulled (or perhaps all for a particular country). It is also common the have the spreads widen under various market conditions. Each bank has different set and they tend to change regularly. </li>
</ul>




<ul>
<li>The traders also have a button on <span class="caps">GUI </span>to turn off all quotes. It is often called the "Panic" button, although the proper name is "Bank Off" (taking the bank off the market). </li>
</ul>




<ul>
<li>The bank is normally off in the lead up to big announcements. I have never been aware of quotes being turned on over the non-farm payroll announcement. At one bank the traders were very impressed by recent changes to the pricing system and decided to try keeping quotes on through the number. We all went to watch and slowly saw liquidity dry up as the announcement approached. With just seconds to go we were the only ones left in the market and the traders decided it wasn't work the risk and hit the panic button. Commentators always talk about modern banking providing liquidity even at times of stress. My experience has been that at even times of relatively minor stress no one wants to quote, or they quote with huge spreads.</li>
</ul>




<ul>
<li>To trade an order is sent to the market. This can be of two types: Fill-and-Kill (FAK), also known as Immediate-or-Cancel (IOC), where either the order is matched immediately (creating a trade) or it is discarded; and Fill-and-Store (FAS), also known as Good-to-Date (GTD), where if the order is not matched it hangs around for a set period of time during which it could be matched. Thus with <span class="caps">FAK </span>order a trade is done straight away or not at all, but under <span class="caps">FAS </span>the trade could occur some time after the order has been sent. A trade can be complete fill or partial fill (some markets also have zero fill - which is the same as no trade at all). Complete means that all the quantity requested has been filled, while partial means that not all the volume has been filled. For instance if an order is sent for $1M and only $500K is done, then that is a partial fill. One order can result in multiple trades. For instance if you put out an order for $10M and it may be filled by two trades of $5M against different counterparties. There are also iceberg orders on some markets. Icebergs are where the order quantity shown to the other market participants is less than the true order quantity (ie. some of it is hidden). This means that you can put on an iceberg order for $10M with a display of $5M. Other banks will see $5M and when that is filled the other $5M will be automatically available to be filled too.</li>
</ul>




<ul>
<li>There are various interpolation algorithms for determining rates between points on a yield curve: cubic, splines, Gaussian. However, most places just seem to use linear (at least until recently) - that is just a straight line between points. Not particularly accurate, but good enough. Remember that market quotes are to 2 or 3 decimal places, so having your prices accurate to 7 decimal places is unnecessary and probably resulting in slow quotes.</li>
</ul>




<ul>
<li>There is a double use of the term covered. A covered bond is like an asset backed bond (I'm not sure the exact difference). A covered auction is one where all the bonds on offer have been sold and the underwriter does need to buy any themselves. </li>
</ul>




<ul>
<li>A typical trader at the places I have worked would have 6-8 screens. At least one would be showing pricing, one for positions risk, one for <span class="caps">BBG </span>and one for communication (Outlook, Bloomberg mail and/or some kind of instant messenger). Most traders would have a Bloomberg keyboard - used for its quick keys. There was always lots of Excel. They usually had 2 or 3 computers to support the large number of screens and heavy load from constant network updates. If the traders had a calculator it would always be the same HP model - easy to spot as it is wider than it is tall.</li>
</ul>

]]>
    </content>
</entry>

<entry>
    <title>Bonds: Part 4 - The Future</title>
    <link rel="alternate" type="text/html" href="http://www.cordinc.com/blog/2012/01/bonds-part-4-the-future.html" />
    <id>tag:www.cordinc.com,2012:/blog//1.184</id>

    <published>2012-01-14T12:00:37Z</published>
    <updated>2012-01-21T12:06:55Z</updated>

    <summary> Part 1 - The Theory Part 2a - The Reality Part 2b - The Reality continued Part 3a - The Technology Part 3b - The Technology continued Addendum So after nearly 7 years on EGB technology teams I have...</summary>
    <author>
        <name>Charles</name>
        
    </author>
    
    <category term="finance" label="Finance" scheme="http://www.sixapart.com/ns/types#tag" />
    <category term="general" label="General" scheme="http://www.sixapart.com/ns/types#tag" />
    
    <content type="html" xml:lang="en" xml:base="http://www.cordinc.com/blog/">
        <![CDATA[
<ul>
<li>Part 1  - <a href="http://www.cordinc.com/blog/2011/10/bonds-part-1-the-theory.html">The Theory</a> </li>
<li>Part 2a - <a href="http://www.cordinc.com/blog/2011/10/bonds-part-2a-the-reality.html">The Reality</a></li>
<li>Part 2b - <a href="http://www.cordinc.com/blog/2011/12/bonds-part-2b-the-reality-cont.html">The Reality continued</a></li>
<li>Part 3a - <a href="http://www.cordinc.com/blog/2011/12/bonds-part-3a-the-technology.html">The Technology</a></li>
<li>Part 3b  - <a href="http://www.cordinc.com/blog/2012/01/bonds-part-3b-the-technology-c.html">The Technology continued</a></li>
<li><a href="http://www.cordinc.com/blog/2012/01/bonds-addendum.html">Addendum</a></li>
</ul>



<p>So after nearly 7 years on <span class="caps">EGB </span>technology teams I have moved on. Not out of banking (at least not yet), but when the opportunity came to try a different business area I jumped. This is despite being able to earn more money if I stayed in my <span class="caps">EGB </span>niche. There are two related reasons for leaving: the industry and technology are both changing to the detriment of developers. </p>

<p>When I started in 2005, <span class="caps">EGB </span>trading was already on an upswing that lasted through 2009. I'm not sure when this upwards trajectory began, but the people around me considered it normal. Business was good throughout the mortgage and banking crisis of 2008. When times are good and the desks are making good money some of it is reinvested into technology. There was a lot of optimism and this translated into banks wanting the fastest and smartest trading platform. We got to rewrite systems. Increasingly business was relying on technology - it was becoming trade-by-wire. It seemed that there was much further to go. Algorithmic trading is big in equities, why couldn't it be big in fixed income too. There was huge potential for writing interesting code.</p>

<p>This environment no longer exists. It was only when the European debt crisis began to bite in 2011 that things trended downwards, but then they went down fast. There is a great deal less ambition among the fixed income desks. Most traders seem happy just to not be losing money - something many are not achieving. Some banks are shutting down their bonds desks. As a natural consequence there is less to spend on technology and little desire to do more than maintenance. Flow volume is king, and as far as technology development is concerned, that is not hard. Thus less developers are required and the work is less interesting.</p>

<p>Combined with this is the creeping commoditisation of bonds technology. When I started Ion provided mainly gateways, little tools and their message bus. Over time they have climbed up the product stack. Now they also sell pricing engines, autoquoters, autohedgers, risk engines, position servers - nearly everything a bank needs to trade cash bonds. The quality is fine too. Their applications won't do everything a desk requires, but it will do most of it and the desk's technology team can add the remainder quickly. Not all banks will use vendor systems (many don't like Ion or see advantage in bespoke systems), but enough will to affect the market for <span class="caps">EGB </span>technologists.</p>

<p>Thus, once again, less developers are required and the work is less interesting. I don't see the situation changing until the market improves - and I don't see that happening soon. So I thought it time to try a different business area.</p>]]>
        
    </content>
</entry>

</feed>

