<?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>OJ's rants &#187; HOWTO</title>
	<atom:link href="http://buffered.io/category/howto/feed/" rel="self" type="application/rss+xml" />
	<link>http://buffered.io</link>
	<description>What would OJ do?</description>
	<lastBuildDate>Tue, 06 Jul 2010 20:32:00 +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>Setting up Trac, Mercurial and SSH on Windows</title>
		<link>http://buffered.io/2009/05/16/setting-up-trac-mercurial-and-ssh-on-windows/</link>
		<comments>http://buffered.io/2009/05/16/setting-up-trac-mercurial-and-ssh-on-windows/#comments</comments>
		<pubDate>Sat, 16 May 2009 07:43:12 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Mercurial]]></category>
		<category><![CDATA[Software]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips/Tricks]]></category>
		<category><![CDATA[Windows]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[ssh]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://buffered.io/?p=687</guid>
		<description><![CDATA[WARNING - This blog post is long This post has been edited since it was published. Please see the end of the article for any notes/modifications Some Background Info I had the need to do this for work recently. It was nothing short of a right royal pain in the butt. It was such a [...]]]></description>
			<content:encoded><![CDATA[<p><strong>WARNING - This blog post is long <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </strong><br />
<em>This post has been edited since it was published. Please see the end of the article for any notes/modifications</em></p>
<h3>Some Background Info</h3>
<p>I had the need to do this for work recently. It was nothing short of a right royal pain in the butt. It was such a pain, in fact, that I have decided to document what I had to do to get it working so that other poor unfortunates will feel less pain if they have to do this themselves.</p>
<p>Almost regardless of the company and the software I'm working on, I use <a href="http://www.selenic.com/mercurial/" title="Mercurial">Mercurial</a> for source code control. For the work I am doing at the moment, I was also using hg because the company I am involved with is relatively new and they hadn't yet sorted out a plan for version control or <acronym title="Application Lifecycle Management">ALM</acronym>. It was working quite well and I was pushing all my changes to my <a href="http://www.google.com.au/url?q=http://www.buffalotech.com/products/network-storage/terastation/terastation-iii/&#038;ei=fioOSuLvGpu8swPl56zqAg&#038;sa=X&#038;oi=smap&#038;resnum=1&#038;ct=result&#038;cd=2&#038;usg=AFQjCNHXKMchy5tR-a-jMOFAbtxoWzfedA" title="Terastation">NAS box</a> to make sure I had other copies backed up, etc. I was <em>living the dream</em> <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>The problem, though, was that this setup was working fine for me as a sole developer, but wasn't solving the problem for the other developers. There are two other people involved in development, and until now most of the work they have been doing has been in a different area to the bits I have been doing. Sharing and merging code was done by email patches. Those developers weren't using version control as far as I'm aware.</p>
<p>So given the volume of changes and the number of merges that were happening, it was well past time to get something proper in place that we could all use. The original plan was to go with an installation of <a href="http://en.wikipedia.org/wiki/Team_Foundation_Server" title="Team Foundation Server">TFS</a> to handle all of these issues for us. Personally, I am not a huge fan of TFS. The experience I've had with it so far hasn't been great. It also has a shocking effect on the speed of my IDE (I seem to have no choice but to use integration with the IDE, which again isn't great).</p>
<p>To cut this part of the story short, we had issues getting TFS to work. We tried installing a few times, tweaking here and there, but we never managed to get it to work. I know I could have called a TFS guru, such as <a href="http://stevennagy.spaces.live.com/" title="Steven Nagy">Snagy</a> to pick his brains and perhaps ask him nicely to help out, but he's a busy man and there's no guarantee that we wouldn't have to start again from scratch. I wasn't really up for that, and neither was my boss.</p>
<p>So I told him that I thought it might just be easier to get a server running with Mercurial for the version control, and <a href="http://trac.edgewall.org/" title="The Trac Project">Trac</a> for issue tracking and project "stuff". Not only would it mean that I could just push my local repository to the server and have the entire history transferred (TFS would have been latest version only) but it would save us a substantial cost in license fees, remove the need for VS integration, and everyone could be up and running with a <acronym title="Distributed Version Control System">DVCS</acronym> in no time.</p>
<p>My boss, being the legend he is, gave me the thumbs up! Awesome.</p>
<p>So the rest of this post is dedicated to what was involved in getting things set up. If you're not interested, then go read <a href="/?random" title="Random post">something else</a> <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<h3>The need for a bit of security</h3>
<p>Needless to say, the <acronym title="Intellectual Property">IP</acronym> that we're building is something that my employer is rather protective of! And rightly so. Hence it won't come as a surprise to hear that security of this information is very important. I decided that having Mercurial run over plan old HTTP would be a bad idea. I was keen to have it tunnel via SSH, and have all clients authenticate using their own private keys. Hence, getting an SSH server was going to be part of the setup.</p>
<h3>Web server</h3>
<p>IIS is already installed on the server, and running another web server seemed like overkill. I didn't want to expose <a href="http://trac.edgewall.org/wiki/TracStandalone" title="Trac Standalone">tracd</a> directly over the web as it doesn't support SSL, so I wanted to get it running under IIS instead. This added another little bit of complexity to the install.</p>
<h3>What to download</h3>
<p>There were quite a few bits that I needed to download to get this working, they're listed below. At first it might not be obvious as to why these things are needed, just trust me <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>First, server-side components:</p>
<ol>
<li>Python 2.5.4 - Get this version, not anything earlier or later if you want this guide to work! (<a href="http://www.python.org/ftp/python/2.5.4/python-2.5.4.msi" title="Download Python">download</a>)</li>
<li>Setuptools (<a href="http://pypi.python.org/packages/2.5/s/setuptools/setuptools-0.6c9.win32-py2.5.exe#md5=602d06054ec1165e995ae54ac30884d7" title="Download setuptools">download</a>)</li>
<li>ClearSilver (<a href="http://www.clearsilver.net/downloads/win32/clearsilver-0.10.4-py2.5-win32.egg" title="Download ClearSilver">download</a>)</li>
<li>PySqlite (<a href="http://initd.org/pub/software/pysqlite/releases/2.4/2.4.1/pysqlite-2.4.1.win32-py2.5.exe" title="Download PySqlite">download</a>)</li>
<li>flup (<a href="http://www.saddi.com/software/flup/dist/flup-0.5-py2.5.egg" title="Download flup">download</a>)</li>
<li>Trac installer v0.11.4 (<a href="http://ftp.edgewall.com/pub/trac/Trac-0.11.4.win32.exe" title="Download Trac">download</a>)</li>
<li>Mercurial (<a href="http://mercurial.berkwood.com/binaries/Mercurial-1.2.1.exe" title="Download Mercurial">download</a>)</li>
<li>Subversion (<a href="http://www.collab.net/servlets/OCNDirector?id=CSVN1.6.2WINC" title="Download Subversion">download</a>)</li>
<li>Apache Tomcat AJP Isapi filter (<a href="http://www.apache.org/dist/tomcat/tomcat-connectors/jk/binaries/win32/jk-1.2.28/isapi_redirect-1.2.28.dll" title="Download isapi filter">download</a>)</li>
<li>Junction (<a href="http://technet.microsoft.com/en-us/sysinternals/bb896768.aspx" title="Download Junction">download</a>)</li>
<li>CopSSH (<a href="http://sourceforge.net/project/downloading.php?group_id=69227&#038;filename=Copssh_2.1.0_Installer.zip&#038;a=22655277" title="Download CopSSH">download</a>)</li>
<li>Windows Server 2003 Resource Kit (<a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=9D467A69-57FF-4AE7-96EE-B18C4790CFFD&#038;displaylang=en" title="Download resource kit">download</a>)</li>
</ol>
<p>Next, client-side:</p>
<ol>
<li>Mercurial (<a href="http://mercurial.berkwood.com/binaries/Mercurial-1.2.1.exe" title="Download Mercurial">download</a>)</li>
<li>PuTTy (<a href="http://the.earth.li/~sgtatham/putty/latest/x86/putty-0.60-installer.exe" title="Download PuTTy">download</a>)</li>
</ol>
<p>Quite a lot isn't it <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<h3>Server: Setting up the Python Environment</h3>
<ol>
<li>Execute the Python installer. This by default installs Python to C:\python25.</li>
<li>Modify the environment variables so that the Python install folder is included in the PATH.</li>
<li>Execute the Setuptools installer.</li>
<li>Execute the PySqlite installer.</li>
<li>Install the downloaded python eggs:</li>
<ol>
<li>Open a command prompt</li>
<li>Navigate to the folder where your .egg files are downloaded to.</li>
<li>in the command line, type: <strong>easy_install [filename.egg]</strong>.</li>
<li>Do this for ClearSilver and flup.</li>
</ol>
</ol>
<p>At this point, you should have a working installation of Python 2.5.4 with the required eggs and plug-ins.</p>
<h3>Server: Setting up Mercurial</h3>
<ol>
<li>Execute the Mercurial installer. By default this installs to %programfiles%\Mercurial. Feel free to change this if you like.</li>
<li>During the installation, the installer will ask if you want to include the install folder in the system PATH. Make sure you click "yes", otherwise you'll have to do it manually afterwards.</li>
</ol>
<p>The Mercurial client is now installed. Later on when installing Trac and getting it to work with Mercurial, I had issues because the Mercurial doesn't install the Mercurial bindings for Python. No only that, trying to use <em>easy_install</em> to install it didn't work because I didn't have Visual Studio 2003 installed on the server (nor did I want to install it!). It turns out that you can get round the issue by doing this:</p>
<ol>
<li>Go to the Mercurial installation folder using Windows Explorer.</li>
<li>Locate the file <strong>Library.zip</strong>.</li>
<li>Open this file with an application like <a href="http://rarsoft.com/" title="WinRAR">WinRAR</a> or <a href="http://www.7-zip.org/" title="7-zip">7-zip</a> (using the built-in Windows zip functionality doesn't work!).</li>
<li>Inside that archive there is a folder called <em>mercurial</em>. Extract this folder to a disk.</li>
<li>Open another Windows Explorer and navigate to your Python installation directory (eg. C:\Python25). Open up the <em>Lib</em> sub0folder (that's <em>lib</em>, not <em>lib<strong>s</strong></em>).</li>
<li>Copy or move the extracted <em>mercurial</em> folder to the <em>lib</em> folder.</li>
</ol>
<p>Done! You've just "installed" the Mercurial bindings for Python. Later down the track, Trac will not crap out when you try and use it!</p>
<h3>Server: Setting up TracMercurial</h3>
<p>Given that we're using Mercurial for the back-end version control, we're going to need to set up and install the Mercurial plugin for Trac. This is where the need for <acronym title="Subversion">SVN</acronym> comes in. Yes, it's ironic that you need SVN to get something working with Mercurial! Just do it, ok!?</p>
<ol>
<li>Execute the Subversion installer and let it go through with the default installation.</li>
<li>Make sure that the path to the SVN binaries is included in the system PATH environment variable.</li>
<li>Open up a command prompt and change directory to a temporary location.</li>
<li>run the command: <strong>svn co http://svn.edgewall.com/repos/trac/sandbox/mercurial-plugin-0.11</strong> - this gets the right version of the plug-in from source.</li>
<li>run the command: <strong>cd mercurial-plugin-0.11</strong></li>
<li>run the command: <strong>python setup.py bdist_egg</strong> - this creates an installable python egg.</li>
<li>run the command: <strong>python setup.py install</strong> - this installs the plug-in to the global location.</li>
</ol>
<p>The TracMercurial plug-in is now installed. We'll need to configure it slightly when we've installed Trac. That information is listed in the next section.</p>
<p>Next we need to create a repository which will be used to house our source code. We'll pretend we're creating a project called "Slartibartfast".</p>
<ol>
<li>Create a new folder on the file system somewhere meaningful, such as <strong>C:\Repos</strong>.</li>
<li>Open a command window, and change directory to that folder.</li>
<li>create a folder for your project: <strong>mkdir Slartibartfast</strong>.</li>
<li>Change to that folder: <strong>cd Slartibartfast</strong>.</li>
<li>Initialise the repository: <strong>hg init .</strong> (not the '.' at the end).</li>
</ol>
<p>Your repository is now ready for code!</p>
<h3>Server: Setting up Trac</h3>
<p>We'll start with the basic install:</p>
<ol>
<li>Execute the Trac installer.</li>
<li>Default installation settings are fine.</li>
<li>It will be installed to the <em>scripts</em> folder under the Python installation folder.</li>
</ol>
<p>At this point it's a good idea to also add the <em>scripts</em> folder to the system PATH. This gives us the ability to run Python scripts from anywhere.</p>
<p>Next up, let's create a Trac project for our Slartitbartfast project.</p>
<ol>
<li>Create a folder to house your Trac projects, say <strong>C:\Trac</strong></li>
<li>Open a command window and change directory to your Trac projects folder.</li>
<li>Create a folder for your new project: <strong>mkdir Slartibartfast</strong></li>
<li>Change to that folder: <strong>cd Slartibartfast</strong>.</li>
<li>Start the Trac administration application to start an interactive setup session: <strong>trac-admin . initenv</strong></li>
</ol>
<p>  You need to fill out some values as it asks for them. Here's a sample interactive session that I did as a test run:</p>
<pre>C:\Trac\Slartibartfast>trac-admin . initenv
Creating a new Trac environment at C:\Trac\Slartibartfast

Trac will first ask a few questions about your environment
in order to initialize and prepare the project database.

 Please enter the name of your project.
 This name will be used in page titles and descriptions.

Project Name [My Project]> Slartibartfast

 Please specify the connection string for the database to use.
 By default, a local SQLite database is created in the environment
 directory. It is also possible to use an already existing
 PostgreSQL database (check the Trac documentation for the exact
 connection string syntax).

Database connection string [sqlite:db/trac.db]>

 Please specify the type of version control system,
 By default, it will be svn.

 If you don't want to use Trac with version control integration,
 choose the default here and don't specify a repository directory.
 in the next question.

Repository type [svn]> hg

 Please specify the absolute path to the version control
 repository, or leave it blank to use Trac without a repository.
 You can also set the repository location later.

Path to repository [/path/to/repos]> C:\Repos\Slartibartfast

Creating and Initializing Project
 Installing default wiki pages

**
** craploads of import statements go here **
**

---------------------------------------------------------------------
Warning: couldn't index the repository.

This can happen for a variety of reasons: wrong repository type,
no appropriate third party library for this repository type,
no actual repository at the specified repository path...

You can nevertheless start using your Trac environment, but
you'll need to check again your trac.ini file and the [trac]
repository_type and repository_path settings in order to enable
the Trac repository browser.

---------------------------------------------------------------------
Project environment for 'Slartibartfast' created.

You may now configure the environment by editing the file:

  C:\TracProjects\Slartibartfast\conf\trac.ini

If you'd like to take this new project environment for a test drive,
try running the Trac standalone web server `tracd`:

  tracd --port 8000 C:\TracProjects\Slartibartfast

Then point your browser to http://localhost:8000/Slartibartfast.
There you can also browse the documentation for your installed
version of Trac, including information on further setup (such as
deploying Trac to a real web server).

The latest documentation can also always be found on the project
website:

http://trac.edgewall.org/

Congratulations!</pre>
<p>You may notice the message: <em>Warning: couldn't index the repository.</em><br />
Don't be too concerned at this point, as we need to do a bit more to make sure that the Mercurial stuff is working.</p>
<p>Now we should test to make sure we're able to start the Trac daemon and see if the project site has been set up. We do that by executing the statement they suggested in the output:<br />
<strong>tracd --port 8000 C:\TracProjects\Slartibartfast</strong><br />
Then we browse to <a href="http://localhost:8000">http://localhost:8000</a> to see if it works! If all goes well you should see a project listing. Click on Slartibartfast and you should see something like this:</p>
<p><a href="http://buffered.io/wp-content/uploads/2009/05/trac_1.png" rel="lightbox[687]"><img src="http://buffered.io/wp-content/uploads/2009/05/trac_1-640x347.png" alt="Trac Project Page - with error." title="Trac Project Page - with error." width="640" height="347" /></a></p>
<p>Trac is telling us why it's not able to index the repository, it's because we haven't enabled the plug-in yet. Let's do that now.</p>
<p>Open up the <em>Trac.ini</em> file which is located inside the <em>conf</em> folder under the main project folder (eg <em>C:\Trac\Slartibartfast\conf\Trac.ini</em>).</p>
<p>First, add the following section to the ini file:</p>
<pre>[hg]
# -- Show revision number in addition to the changeset hash
show_rev = yes

# -- Changeset hash format
node_format = short
# hex:   Show the full SHA1 hash
# short: Show a shortened hash for the changesets
</pre>
<p>Then enable the Mercurial plugin by adding the following:</p>
<pre>[components]
tracext.hg.backend.csetpropertyrenderer = enabled
tracext.hg.backend.hgdefaultpropertyrenderer = enabled
tracext.hg.backend.hgextpropertyrenderer = enabled
tracext.hg.backend.mercurialconnector = enabled
</pre>
<p><em>Note:</em>Make sure that the <kbd>[hg]</kbd> and <kbd>[components]</kbd> sections don't already exist. If they do, then add the respective lines to the existing sections rather than creating new ones. For a fresh install, these sections shouldn't already exist, so you should be safe to add them.</p>
<p>Kill the tracd instance by press CTRL+C, then restart it (press the up arrow, then enter). Refresh your browser window and this time you should see this:</p>
<p><a href="http://buffered.io/wp-content/uploads/2009/05/trac_2.png" rel="lightbox[687]"><img src="http://buffered.io/wp-content/uploads/2009/05/trac_2-640x372.png" alt="Trac Project Page - without error." title="Trac Project Page - without error." width="640" height="372" /></a></p>
<p>Excellent, our project is up and our repository is able to be read. We're done!</p>
<h3>Server: Setting up the Trac Daemon as a Service</h3>
<p>The tracd needs to run as a service. This is to make sure it's always running in a way that IIS can reference it. Given that we're later going to be hooking this up to IIS, we need to make sure it uses the <a href="http://tomcat.apache.org/connectors-doc/ajp/ajpv13a.html" title="AJP Reference">AJP</a> protocol. Here are the required steps:</p>
<ol>
<li>Install the Windows 2003 resource kit.</li>
<li>Open a command window, and navigate to where the resource kit binaries are installed. On my system that was at <em>C:\Program Files\Windows Resource Kits\Tools</em></li>
<li>Create a service called "Trac" by executing the following command: <strong>InstSrv Trac "C:\Program Files\Windows Resource Kits\Tools\SrvAny.exe"</strong> - (note the use of the full path is necessary for this to work).</li>
<li>Next we need to hack the registry a little to pass the right parameters and have the tracd started.
<ol>
<li>Open regedit.</li>
<li>Go to <strong>HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\Trac</strong></li>
<li>Create a new sub-key called <strong>Parameters</strong></li>
<li>Inside this new sub-key, create two new values:
  </li>
<ol>
<li><strong>Application</strong> of type String. Set the value to the full path of <em>python.exe</em>. Eg <strong>C:\python25\python.exe</strong></li>
<li><strong>AppParameters</strong> of type String. Set the value to <strong>C:\python25\Scripts\tracd-script.py --port 8009 C:\Trac\Slartibartfast</strong> - (note the change of port number, it's there for a reason we'll cover shortly).</li>
</ol>
</ol>
<li>Open the services tool from the Control Panel, find the <strong>Trac</strong> service and start it up! Navigate to <a href="http://localhost:8009">http://localhost:8009</a> to make sure it still works.</li>
</ol>
<p>If you get the same site as you did before, then all is going well. If not, then you revisit the steps to make sure you haven't missed anything out and that your pointing to the right location of the trac project.</p>
<p>Now that we know this works, we need to change the <strong>AppParameters</strong> value in the registry so that Trac fires up using the appropriate protocol. Edit the value, and append the following to the end of the existing value: <strong>--protocol=ajp</strong> - this forces the use of AJP. AJP's default port is 8009, which is why we chose this value in the first place.</p>
<p>Restart the Trac service. If you attempt to browse to the site now you won't get anything meaningful, but it's ready to be talked to from IIS, which brings us to the next step.</p>
<h3>Server: Setting up Apache Tomcat ISS ISAPI Filter in IIS 6.</h3>
<p>To get IIS to talk to Trac, we need to add an ISAPI filter that's able to translate to the AJP protocol. This is what we'll be doing in this section.</p>
<p>First, we prepare the filter for use:</p>
<ol>
<li>Create a folder to store the ISAPI file. I called mine <strong>C:\AJPConnector</strong>.</li>
<li>Copy the Apache Tomcat AJP ISAPI filter (isapi_redirect-1.2.28.dll) into the folder you created in the previous step, and rename it to <strong>isapi_redirect.dll</strong>.</li>
<li>Create a new text file in the same folder called <strong>isapi_redirect.properties</strong>. Open the file with a text editor and add the following content:
<pre># Configuration file for the ISAPI Redirector

# The path to the ISAPI Redirector Extension, relative to the website
# This must be in a virtual directory with execute privileges
extension_uri=/AJPConnector/isapi_redirect.dll

# Full path to the log file for the ISAPI Redirector
log_file=C:\AJPConnector\isapi_redirect.log

# Log level (debug, info, warn, error or trace)
log_level=info

# Full path to the workers.properties file
worker_file=C:\AJPConnector\workers.properties

# Full path to the uriworkermap.properties file
worker_mount_file=C:\AJPConnector\uriworkermap.properties
</pre>
</li>
<li>Create another new text file in the same folder called <strong>workers.properties</strong>. Open it, and add this content:
<pre># Define 1 real worker
worker.list=trac
# Set properties for trac (ajp13)
worker.trac.type=ajp13
worker.trac.host=localhost
worker.trac.port=8009
worker.trac.socket_keepalive=0
</pre>
</li>
<li>Create <em>another</em> new text file in the same folder called <strong>uriworkermap.properties</strong>. Open it and add the following:
<pre>
/Slartibartfast*=trac
</pre>
<p>You'll notice that the project name is what I've used here. Down the track if you want more projects, you need to add more lines to this file.</li>
</ol>
<p>Next we need to install the ISAPI filter in IIS so that it can get used. Feel free to do this on the default website if you like. I created another website in IIS running on a different port, but you don't have to. Any time I refer to <em>the website</em> I'm referring to the site you have decided to install the filter on.</p>
<p>We need to enable the filter as a web service extension first. To do that, we follow these steps:</p>
<ol>
<li>Open up the IIS manager.</li>
<li>Right-click on "Web Service Extensions" and select "Add a new web service extension".</li>
<li>In the resulting dialog box, click the "Add..." button and specify the file <strong>C:\AJPConnector\isapi_redirect.dll</strong>. Click "OK".</li>
<li>Specify the name "AJPConnector" and click "OK".</li>
</ol>
<p>Next we need to add the filter to the website.</p>
<ol>
<li>In IIS manager right-click on the website and view the properties.</li>
<li>Select the "ISAPI Filters" tab.</li>
<li>Click "Add".</li>
<li>Give the filter the name "AJPConnector".</li>
<li>Specify the full path to the dll: <strong>C:\AJPConnector\isapi_redirect.dll</strong>.</li>
<li>Click "OK".</li>
<li>Click on the "Home Directory" tab.</li>
<li>Make sure the "Execute Permissions" is set to "Scripts and Executables".</li>
<li>Make a note of the application pool that the web site is running under! You'll need this in a minute.
<li>Click "OK" to close the dialog.</li>
</ol>
<p>For the ISAPI filter to function, we need to make sure that IIS has access to the folder which the binary is stored in. To do this we need to know which account the website is running under.</p>
<ol>
<li>In IIS manager open the list of Application Pools.</li>
<li>Choose the application pool that your website is running under. Rick-click and select properties.</li>
<li>Click on the "Identity" tab. This will show you the name of the account that your site is running under.</li>
<li>Browse to <strong>C:\AJPConnector</strong>, right-click and select "Properties", then choose the "Security" tab.</li>
<li>Click "Add" and type in the name of the account that you found listed in the "Identity" tab in the application pool properties. You can also use the search feature if you want to.</li>
<li>When the user has been recognised, click "OK".</li>
<li>Select the user in the list at the top of the dialog, and make sure that they have "Full Control" selected in the list at the bottom.</li>
<li>Click on the "Advanced" button.</li>
<li>Select the check box that says "Replace permission entries on all child objects with entries shown here that apply to child objects". Then press "OK". This will apply the permissions to all child objects in the folder.</li>
<li>Click "OK" to close the dialog box.</li>
</ol>
<p>You may have noticed that in the <strong>isapi_redirect.properties</strong> file we specified an <em>extension_uri</em> property. This property specifies the path to use to get to the <strong>isapi_redirect.dll</strong> file via IIS. Notice how it's also a relative path from the root folder. Hence we need to create a virtual directory which maps to the same path.</p>
<ol>
<li>In IIS manager right-click on the website and select "New" then "Virtual Directory...".</li>
<li>Fill out the wizard making sure you use the name "AJPConnector" for the directory name, and point it at <strong>C:\AJPConnector</strong>. The site also needs to be able to execute programs, not just scripts.</li>
</ol>
<p>Restart IIS. The quickest way to do this is to type <strong>iisreset</strong> into a command prompt or into the "Run" dialog.</p>
<p>It's best at this point to make sure that the ISAPI filter has been loaded. To do this, simply open up the IIS manager again and browser to the sites "ISAPI Filters" tab. If all is working, then you should see something like this:</p>
<p><img src="http://buffered.io/wp-content/uploads/2009/05/iis_isapi.png" alt="Working IIS ISAPI Filter" title="Working IIS ISAPI Filter" /></p>
<p>Notice the green arrow. If it's red and pointing downwards, then something is wrong. You need to make sure you have followed the above steps correctly. Double-check the security of the folders and make sure executables are enabled on your site.</p>
<p>If all is well then we can test it! Make sure your Trac service is running, then open a browser and navigate to your local IIS website. You should see the Trac Project website for Slartibartfast appear in your browswer. Yay!</p>
<p>It's now very easy to change IIS to function over HTTPS instead of HTTP. That's beyond the scope of this article as there are hundreds of blog entries and how-tos out there already.</p>
<h3>Server: Setting up CopSSH</h3>
<p>This is the final step! We need to give people access to the Mercurial repositories over SSH. For that we need to set up a functional SSH server and give them access to the repository path. On the surface these both seem like easy jobs. Unfortunately setting up SSH servers on Windows isn't pleasant and pointing everyone's home folders at a certain repository is not something that comes out of the box in Windows.</p>
<p>What we need to do is use the CopSSH installer to help with the "easy" installation of SSH. Then we need to use a program like Junction to provdie symbolic-link style functionality to the user's folders.</p>
<p>First up, run the CopSSH installer program. Follow all of the prompts and feel free to use the default installation. That was easy wasn't it! It should install an SSH server service for you. I found it quite hard to locate in the Service Management dialog, but eventually found it under the name "Openssh SSHD".</p>
<p>CopSSH comes with utilities which help you manage users. Those utilities are all in the programs menu and are easy to use. For me, those utilities weren't enough, because I knew that I was going to have to make sure that the folder links were set up on creation of user accounts and removed when those accounts were deleted.</p>
<p>It's a good move at this point to download Junction, if you haven't already, and put it in an easy to reach location. Feel free to add it to it's own folder or to system32. It's up to you. I'll assume you've put it in <strong>C:\tools</strong>.</p>
<p>I then created two scripts. The first lets you add users. It looks like this:</p>
<pre>REM AddUser.bat
"C:\Program Files\ICW\Bin\copsshadm.exe" --command activateuser --user %1 --shell /bin/bash --passphrase %2
C:\tools\junction.exe "C:\Program Files\ICW\home\%1\Slartibartfast" C:\Repos\Slartibartfast
</pre>
<p>The first line of this file executes the user activation feature of CopSSH. It creates a new user from a local security login (so the users need to be accessible in Active Directory or in the local security set up). It creates a home folder for them and also creates a public/private key pair which it stores in their home folder as well. The keys have the passphrase that is passed to the script on the command line and will be used by the users to SSH in and commit changes to the repository. The public key for the user is added to the server as a recognised key which can be used to log in so we don't have to specify it manually.</p>
<p>The second line of the script executes the Junction program and links a folder called "Slartibartfast", located in the user's home folder, to the folder where the repository is stored.</p>
<p>To execute the script simply run: <strong>adduser.bat [username] [passphrase]</strong>.<br />
Please note that during my testing, I wasn't able to use a passphrase that had spaces. This isn't due to a bug in the script. Even if you replace <em>--passphrase %2</em> with <em>--passphrase "%2"</em> it still doesn't work. It also doesn't work in the user interface tools. This appears to be a bug in CopSSH. This isn't a big issue though, just make sure you don't have spaces in your passphrase and you should be fine.</p>
<p>The second script is for removing users, it looks like this:</p>
<pre>REM RemUser.bat
C:\tools\junction.exe -d "C:\Program Files\ICW\home\%1\Slartibartfast"
"C:\Program Files\ICW\Bin\copsshadm.exe" --command deactivateuser --user %1
</pre>
<p>It's obvious what this does. First it removes the symbolic link in the user's folder, then it uses CopSSH's command line tools to remove them as a valid user from the SSH server.</p>
<p>Before you assume that everything at this point is ready to rock, you may need to make sure that your firewall is updated so that the SSH port, 22, is open.</p>
<p>Congratulations, you are now finished with the server set up. Now let's get the clients working. Before you go to the next step, make sure you add a user!</p>
<h3>Client: Setting up PuTTy</h3>
<p>The first bit is easy, make sure that you've installed the PuTTy program and added the install path to the system's PATH environment variable.</p>
<p>Take a copy of the user's private key. This is generated by CopSSH and should be sitting in the user's home folder on the server. The key is usually called <strong>[username].key</strong>. Put the key on your local machine. We need to convert this key into a format that PuTTy can use.</p>
<ol>
<li>Fire up the puttygen.exe utility. It comes with the PuTTy program. Simply type "puttygen" into the Run dialog box and it should come up if you've added the install folder to the system PATH.</li>
<li>Click "Load" and select the private key file you copied from the server.</li>
<li>Enter the user's passphrase into the dialog that appears and press "OK".</li>
<li>You should get a message stating ...
<pre>Successfully imported foreign key
(OpenSSH SSH-2 private key).
To use this key with PuTTY, you need to
use the "Save private key" command to
save it in PuTTY's own format.</pre>
<p>Just press "OK".</li>
<li>Click "Save private key" and save the key in a safe location on your machine.</li>
</ol>
<p>Your key can now be used by PuTTy.</p>
<p>When using SSH, you are going to have to have to specify the passphrase each time you connect to the server. This can get annoying quickly especially if you do a lot of commits. Instead of typing this in manually every time, I prefer to use the pageant.exe utility that also comes with PuTTy. This takes charge of handling the key passphrase for you.</p>
<ol>
<li>From the command line or Run dialog, type <strong>pageant</strong>. You see a rather bland dialog appear.</li>
<li>Click "Add key". Browse to the folder where you have stored your new .ppk (the PuTTy version of your key) and select the key.</li>
<li>When prompted, specify the passphrase and click "OK".</li>
<li>You should now see an item appear in the list box. This is your private key. Pageant is now in memory and handling that key.</li>
<li>Close pageant, but you should still see it running in the system tray.</li>
</ol>
<p>I also find it helpful to add <em>pageant.exe</em> to my start-up folder so that it is always running when I log in to my machine. You may choose to do the same.</p>
<h3>Client: Setting up Mercurial</h3>
<p>If you haven't already, make sure you install Mercurial on the client machine using the default settings. Make sure you tell the installer to add the Mercurial path to the system PATH.</p>
<p>The last step of configuration for the client is to tell Mercurial to use the PuTTy tools when using SSH. Mercurial can be configured by a user-specific configuration file called <em>.hgrc</em>. On Windows it can also be called <em>Mercurial.ini</em>. The file is located in your home folder. If you don't know what your home folder is, simply open a command prompt and type <strong>echo %USERPROFILE%</strong> - this will tell you the path.</p>
<p>If you haven't set up your configuration yet, then chances are the configuration file doesn't exist. So you'll have to create it. Create a file call either <em>.hgrc</em> or <em>Mercurial.ini</em> in your home folder manually, and open it in a text editor. Here is what part of mine looks like:</p>
<pre>[ui]
username = OJ Reeves
<put your email here in the angle brackets>
editor = vim
ssh = plink -ssh -i "C:/path/to/key/id_rsa.ppk" -C -agent
</pre>
<p>The last line is the key and this is what you need to make sure it set properly. We are telling Mercurial to use the <em>plink</em> program. This also comes with PuTTy and is a command-line version of what the PuTTY program itself does behind the scenes. We also add a few parameters:</p>
<ul>
<li><em>-ssh</em> : Indicates that we're using the SSH protocol.</li>
<li><em>-i "file.ppk"</em> : Specifies the location of the private key file we want to use to log in to the remote server. Change this to point to your local putty-compatible ppk private key. Make sure you user forward-slashes for the path separators as well!</li>
<li><em>-C</em> : This switch enables compression.</li>
<li><em>-agent</em> : This tells <em>plink</em> to talk to the <em>pageant</em> utility to get the passphrase for the key instead of asking you for it interactively.</li>
</ul>
<p>The client is now ready to rock!</p>
<h3>Finale</h3>
<p>It took a while, but we got there in the end. Let's give our new-found Mercurial SSH server a spin. This should be easy as opening a command prompt at the appropriate location on disk and typing:</p>
<p><strong>hg clone ssh://url.to.your.server.com/Slartibartfast</strong></p>
<p>If everything has been configured properly, you should see Mercurial create a local folder called <strong>Slartibartfast</strong> which contains the repository. Of course, there won't be much in it because you've only created it recently! But you should be able to start using Mercurial to commit changes and push the committed changesets to the server just by running <strong>hg push</strong>.</p>
<h3>The End</h3>
<p>It took a while to figure most of this stuff out despite the documentation that exists on the web. It also took a bit of time to write this up! I hope that someone out there finds it useful.</p>
<p>The funny thing about all this, is that despite the pain, I found it easier to set up than TFS!</p>
<p>Feedback is always wanted and welcome. I hope it helps <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<hr />
<strong>Edit 11/06/2009 :</strong> I've been using this set up for a little while and I'm now aware of an issue that I'm not currently able to get around (moreso because I can't be bothered trying to!). The issue is that you have <em>any</em> files added to the Trac system which have file names containing characters which change when URL encoded (such as spaces, which become %20 for example) the you won't be able to view them through the web interface. That goes for files attached to wiki pages, and sources files viewed in the source browser. If you have a file called "My Doc.doc" behind the scenes this setup results calls being made with the file name "My%20Doc.doc", which doesn't exist! Just be warned. If you're going to use this setup, don't add files to your source or to the wiki that contain spaces or odd characters. <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<hr />
<strong>Edit 26/06/2009 :</strong><br />
Have a look at <a href="/2009/05/16/setting-up-trac-mercurial-and-ssh-on-windows/comment-page-1/#comment-1333" title="Jeremy's comment">Jeremy's comment</a> for a resolution to this escaping problem. Thanks for that mate!</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2009/05/16/setting-up-trac-mercurial-and-ssh-on-windows/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>.NET-fu: Signing an Unsigned Assembly (without Delay Signing)</title>
		<link>http://buffered.io/2008/07/09/net-fu-signing-an-unsigned-assembly-without-delay-signing/</link>
		<comments>http://buffered.io/2008/07/09/net-fu-signing-an-unsigned-assembly-without-delay-signing/#comments</comments>
		<pubDate>Wed, 09 Jul 2008 02:13:23 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Microsoft]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[Tips/Tricks]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[disassemble]]></category>
		<category><![CDATA[ilasm]]></category>
		<category><![CDATA[ildasm]]></category>
		<category><![CDATA[MSIL]]></category>
		<category><![CDATA[sign]]></category>
		<category><![CDATA[snk]]></category>
		<category><![CDATA[strong name]]></category>

		<guid isPermaLink="false">http://buffered.io/?p=373</guid>
		<description><![CDATA[This article is also available in: Italian The code-base that I am currently working with consists of a large set of binaries that are all signed. The savvy .NET devs out there will know that any assembly that's used/referenced by a signed assembly must also be signed. This is an issue when dealing with third-party [...]]]></description>
			<content:encoded><![CDATA[<p>This article is also available in: <a href="http://www.otherbit.com/modules/blog/BlogContent.aspx?ID=174" title=".NET-FU : come trasformare in SIGNED un assembly UNSIGNED (senza ricorrere al DELAY SIGNING)">Italian</a></p>
<hr/>
The code-base that I am currently working with consists of a large set of binaries that are all <a href="http://msdn.microsoft.com/en-us/library/xc31ft41.aspx" title="Sign an Assembly with a Strong Name">signed</a>. The savvy .NET devs out there will know that any assembly that's used/referenced by a signed assembly must <em>also</em> be signed.</p>
<p>This is an issue when dealing with third-party libraries that are not signed. Sometimes you'll be lucky enough to be dealing with vendor that is happy to provide a set of signed assemblies, other times you won't. If your scenario fits the latter (as a recent one did for my colleagues and I), you need to sign the assemblies yourself. Here's how.</p>
<p><em>Note:</em> <a href="http://msdn.microsoft.com/en-us/library/t07a3dye(VS.80).aspx" title="Delay Signing an Assembly">delay signing</a> is not covered in this article.</p>
<h2>Scenario 1 - Foo and Bar</h2>
<p><strong>Foo</strong> is the component that you're building which has to be signed.<br />
<strong>Bar</strong> is the third-party component that you're forced to use that <em>isn't</em>.</p>
<p><img src="http://buffered.io/wp-content/uploads/2008/07/foobar.png" alt="Relationship between Foo and Bar" /><br />
Grab <a href="http://buffered.io/wp-content/uploads/2008/07/bar.zip" title="Project/Binary for Bar"><em>Bar.dll</em> and project</a> along with <a href="http://buffered.io/wp-content/uploads/2008/07/foobar.zip" title="Project/Binary for Foo"><em>Foo.dll</em> and project</a> to see a source sample.</p>
<p>You'll notice <em>Foo</em> has a .snk which is used to sign <em>Foo.dll.</em> When you attempt to compile <em>Foo</em> you get the following error message:<br />
<blockquote>
<p>Assembly generation failed -- Referenced assembly 'Bar' does not have a strong name</p>
</blockquote>
<p>We need to sign <em>Bar</em> in order for <em>Foo</em> to compile.</p>
<p><img src="http://buffered.io/wp-content/uploads/2008/07/step1.jpg" style="float: right; margin-left: 5px; margin-bottom: 2px;" alt="Disassemble Bar" /><br />
<h3>Step 1 - Disassemble Bar</h3>
<p>We need to open a command prompt which has the .NET framework binaries in the <a href="http://en.wikipedia.org/wiki/Path_%28computing%29" title="Path">PATH</a> <a href="http://en.wikipedia.org/wiki/Environment_variable" title="Environment variable">environment variable</a>. The easiest way to do this is to open a Visual Studio command prompt (which is usually under the "Visual Studio Tools" subfolder of "Visual Studio 200X" in your programs menu). Change directory so that you're in the folder which contains <em>Bar.dll</em>.</p>
<p>Use <a href="http://msdn.microsoft.com/en-us/library/f7dy01k1(VS.80).aspx" title="MSIL Disassembly">ildasm.exe</a> to disassemble the file using the <strong>/all</strong> and <strong>/out</strong>, like so:</p>
<pre>
C:\Foo\bin> ildasm /all /out=Bar.il Bar.dll
</pre>
<p>The result of the command is a new file, <em>Bar.il</em>, which contains a dissassembled listing of <em>Bar.dll</em>.</p>
<p><img src="http://buffered.io/wp-content/uploads/2008/07/step2.jpg" style="float: right; margin-left: 5px; margin-bottom: 2px;" alt="Rebuild and Sign Bar" /><br />
<h3>Step 2 - Rebuild and Sign Bar</h3>
<p>We can now use <a href="http://msdn.microsoft.com/en-us/library/496e4ekx.aspx" title="MSIL Assembler">ilasm</a> to reassemble <em>Bar.il</em> back into <em>Bar.dll</em>, but at the same time specify a strong-name key to use to sign the resulting assembly. We pass in the value <em>Foo.snk</em> to the <strong>/key</strong> switch on the command line, like so:
<div style="clear:both;"></div>
<pre>
C:\Foo\bin> ilasm /dll /key=Foo.snk Bar.il

Microsoft (R) .NET Framework IL Assembler.  Version 2.0.50727.1434
Copyright (c) Microsoft Corporation.  All rights reserved.
Assembling 'Bar.il'  to DLL --> 'Bar.dll'
Source file is ANSI

Assembled method Bar.Bar::get_SecretMessage
Assembled method Bar.Bar::.ctor
Creating PE file

Emitting classes:
Class 1:        Bar.Bar

Emitting fields and methods:
Global
Class 1 Methods: 2;
Resolving local member refs: 1 -> 1 defs, 0 refs, 0 unresolved

Emitting events and properties:
Global
Class 1 Props: 1;
Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved
Writing PE file
Signing file with strong name
Operation completed successfully
</pre>
<p><em>Bar.dll</em> is now signed! All we have to do is reopen <em>Foo</em>'s project, remove the reference to <em>Bar.dll</em>, re-add the reference to the new signed assembly and rebuild. Sorted!</p>
<h2>Scenario 2 - Foo, Bar and Baz</h2>
<p><strong>Foo</strong> is the component that you're building which has to be signed.<br />
<strong>Bar</strong> is the third-party component that you're forced to use that <em>isn't</em>.<br />
<strong>Baz</strong> is another third-party component that is required in order for you to use <em>Bar</em>.</p>
<div class="LargeImage"><img src="http://buffered.io/wp-content/uploads/2008/07/foobarbaz.png" alt="Relationship between Foo, Bar and Baz"/></div>
<p>Grab <a href="http://buffered.io/wp-content/uploads/2008/07/baz.zip" title="Project/Binary for Baz"><em>Baz.dll</em> and project</a>, <a href="http://buffered.io/wp-content/uploads/2008/07/barbaz.zip" title="Project/Binary for Bar"><em>Bar.dll</em> and project</a> along with <a href="http://buffered.io/wp-content/uploads/2008/07/foobarbaz.zip" title="Project/Binary for Foo"><em>Foo.dll</em> and project</a> for a sample source.</p>
<p>When you attempt to build <em>Foo</em> you get the same error as you do in the previous scenario. Bear in mind that this time, <strong>both</strong> <em>Bar.dll</em> and <em>Baz.dll</em> need to be signed. So first of all, follow the steps in <strong>Scenario 1</strong> for both <em>Bar.dll</em> and <em>Baz.dll</em>.</p>
<p>Done? OK. When you attempt to build <em>Foo.dll</em> after pointing the project at the new <em>Bar.dll</em> no compiler errors will be shown. Don't get too excited <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>When you attempt to <strong>use</strong> <em>Foo.dll</em> your world will come crashing down. The reason is because <em>Bar.dll</em> was originally built with a reference to an <u>unsigned version</u> of <em>Baz.dll</em>. Now that <em>Baz.dll</em> is signed we need to force <em>Bar.dll</em> to reference the <strong>signed</strong> version of <em>Baz.dll</em>.</p>
<p><img src="http://buffered.io/wp-content/uploads/2008/07/step3.jpg" style="float: right; margin-left: 5px; margin-bottom: 2px;" alt="Hack the Disassembled IL" /><br />
<h3>Step 1 - Hack the Disassembled IL</h3>
<p>Just like we did in the previous steps we need to disassemble the binary that we need to fix. This time, make sure you disassemble the new binary that you created in the previous step (this binary has been signed, and will contain the signature block for the strong name). Once <em>Bar.il</em> has been created using ildasm, open it up in a <a href="http://www.vim.org/" title="VIM - secretGeek loves it.. no really, he does!">text editor</a>.</p>
<p>Search for the reference to <em>Baz</em> -- this should be located a fair way down the file, somewhere near the top of the actual code listing, just after the comments. Here's what it looks like on my machine:</p>
<pre>.assembly extern /*23000002*/ Baz
{
  .ver 1:0:0:0
}</pre>
<p>This external assembly reference is missing the all-important public key token reference. Before we can add it, we need to know what the public key token is for <em>Bar.dll</em>. To determine this, we can use the <a href="http://msdn.microsoft.com/en-us/library/k5b5tt23(VS.80).aspx" title="Strong Name Tool">sn.exe</a> utility, like so:</p>
<pre>C:\Foo\bin> sn -Tp Baz.dll

Microsoft (R) .NET Framework Strong Name Utility  Version 3.5.21022.8
Copyright (c) Microsoft Corporation.  All rights reserved.

Public key is
0024000004800000940000000602000000240000525341310004000001000100a59cd85e10658d
9229d54de16c69d0b53b31f60bb4404b86eb3b8804203aca9d65412a249dfb8e7b9869d09ce80b
0d9bdccd4943c0004c4e76b95fdcdbc6043765f51a1ee331fdd55ad25400d496808b792723fc76
dee74d3db67403572cddd530cadfa7fbdd974cef7700be93c00c81121d978a3398b07a9dc1077f
b331ca9c

Public key token is 2ed7bbec811020ec
</pre>
<p>Now we return to <em>Bar.il</em> and modify the assembly reference so that the public key token is specified. This is what it should look like after modification:</p>
<pre>.assembly extern /*23000002*/ Baz
{
  .publickeytoken = (2E D7 BB EC 81 10 20 EC )
  .ver 1:0:0:0
}</pre>
<p>Save your changes.</p>
<p><img src="http://buffered.io/wp-content/uploads/2008/07/step4.jpg" style="float: right; margin-left: 5px; margin-bottom: 2px;" alt="Reassemble Bar" /><br />
<h3>Step 2 - Reassemble Bar</h3>
<p>This step is just a repeat of previous steps. We are again using ilasm to reassemble <em>Bar.dll</em>, but this time from the new "hacked" <em>Bar.il</em> file. We must use the exact same command line as we did previously, and we still need to specify the <em>Foo.snk</em> for signing the assembly. To save you having to scroll up, here it is again:</p>
<pre>C:\Foo\bin> ilasm /dll /key=Foo.snk Bar.il

Microsoft (R) .NET Framework IL Assembler.  Version 2.0.50727.1434
Copyright (c) Microsoft Corporation.  All rights reserved.
Assembling 'Bar.il'  to DLL --> 'Bar.dll'
Source file is ANSI

Assembled method Bar.Bar::get_SecretMessage
Assembled method Bar.Bar::.ctor
Creating PE file

Emitting classes:
Class 1:        Bar.Bar

Emitting fields and methods:
Global
Class 1 Fields: 1;      Methods: 2;
Resolving local member refs: 3 -> 3 defs, 0 refs, 0 unresolved

Emitting events and properties:
Global
Class 1 Props: 1;
Resolving local member refs: 0 -> 0 defs, 0 refs, 0 unresolved
Writing PE file
Signing file with strong name
Operation completed successfully
</pre>
<p>Open up <em>Foo</em>'s project, remove and re-add the reference to <em>Bar.dll</em>, making sure you point to the new version that you just created. <em>Foo.dll</em> will not only build, but this time it will run!</p>
<h2>Disclaimer</h2>
<p>"Hacking" third-party binaries in this manner <strong><em>may</em> breach the license agreement</strong> of those binaries. Please make sure that you are not breaking the license agreement before adopting this technique.</p>
<p>I hope this helps!</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2008/07/09/net-fu-signing-an-unsigned-assembly-without-delay-signing/feed/</wfw:commentRss>
		<slash:comments>26</slash:comments>
		</item>
		<item>
		<title>The Magic of Unity Builds</title>
		<link>http://buffered.io/2007/12/10/the-magic-of-unity-builds/</link>
		<comments>http://buffered.io/2007/12/10/the-magic-of-unity-builds/#comments</comments>
		<pubDate>Mon, 10 Dec 2007 08:03:26 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>
		<category><![CDATA[unity builds]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/12/10/the-magic-of-unity-builds/</guid>
		<description><![CDATA[I realise that as time goes by, people are using my beloved C++ less and less. .NET (C# and VB.NET) and Java seem to be taking over the mainstream coding world. Languages such as Ruby and Python seem to be taking over the scripting world. For the most part, C and C++ seem to exist [...]]]></description>
			<content:encoded><![CDATA[<p>I realise that as time goes by, people are using my beloved <a href="http://en.wikipedia.org/wiki/C++" title="C++">C++</a> less and less. <a href="http://en.wikipedia.org/wiki/.NET_Framework" title=".NET Framework">.NET</a> (<a href="http://en.wikipedia.org/wiki/C_Sharp" title="C#">C#</a> and <a href="http://en.wikipedia.org/wiki/Visual_Basic_.NET" title="VB.NET">VB.NET</a>) and <a href="http://en.wikipedia.org/wiki/Java_%28programming_language%29" title="Java">Java</a> seem to be taking over the mainstream coding world. Languages such as <a href="http://en.wikipedia.org/wiki/Ruby_%28programming_language%29" title="Ruby">Ruby</a> and <a href="http://en.wikipedia.org/wiki/Python_%28programming_language%29" title="Python">Python</a> seem to be taking over the scripting world. For the most part, C and C++ seem to exist only in the gaming/entertainment, real-time and driver worlds.</p>
<p>In many colleges and univerties C++ is no longer taught as a core subject (along with <a href="http://en.wikipedia.org/wiki/Assembly_language" title="Assembly Language">Assembly language</a>) which I find quite galling. It's a great language to learn, even if you never use it again. But the purpose of this post is not to preach the virtues and failures of the C++ language, but instead to talk about something that might aid those people who <em>are</em> using C++.</p>
<p>Anyone who's worked on a large C++ (or C) application has felt the pain of long build times. The first "big" C++ system that I worked on took 10 minutes to build. This was much bigger than anything I had experienced up until that point. Later in my career when I joined the games industry I really felt the pain of rebuilding a <em>massive</em> code base. The game took just under an hour to build from start to finish without any distributed compiling mechanism in place. When I finally got a copy of <a href="http://www.xoreax.com/" title="Xoreax Incredibuild">Incredibuild</a> the build time dropped noticably, but not to a point where recompilation was an option every time I wanted it.</p>
<p>The solution that we implement: <strong>Unity builds</strong> (which I'll refer to as UB from now on because I'm lazy).</p>
<p>Now, a lot of C and C++ that have used these before might consider the idea of a UB to be a bit of a hack. I'm not sure if I agree or disagree. There is an air of "hackyness" about it, but it solves the problem of huge compile times on most platforms with most compilers.</p>
<p>Before I go into the definition, and give instructions on how to set up a UB, let me just state for the record that this isn't designed to replace normal builds for releasing code. The idea behind these is to dramatically reduce the build times for developers who are spending 8 hours a day modifying the code. Fixing bugs and adding enhancements generally means that a developer is constantly recompiling. Every time you compile, you have to wait (or perhaps <a href="http://xkcd.com/303/" title="Compiling">entertain yourself in some way</a>), and in waiting you are wasting precious time. Wasting time means a reduction in productivity. This can only be a bad thing. It's bad enough with short build times, but with long build times it becomes a huge problem. So please bear in mind that the normal release and product builds, builds that happen on automated build servers, etc, do <em>not</em> need to have a UB in place, they can continue to use normal builds.</p>
<p>The principle behind a UB is quite simple. It's all about reducing...
<ol>
<li>... the number of times a file is opened.</li>
<li>... the number of files that are opened.</li>
</ol>
<p>In esssence, we're going to abuse the power of the <a href="http://en.wikipedia.org/wiki/Preprocessor" title="Preprocessor">preprocessor</a> to do the above.</p>
<p>Every source file (.c, .cxx, .cc, .cpp, etc) that is compiled results in the creation of an <a href="http://en.wikipedia.org/wiki/Object_files" title="Object File">object file</a>. When all of the source files are compiled into object files, the <a href="http://en.wikipedia.org/wiki/Linker" title="Linker">linker</a> then collects up all these object files and links them together into an executable application. For those of you who don't know: reading/writing to/from disk is the slowest thing you can do on a computer. Actually, it isn't so much the reading and writing, it's more the <a href="http://en.wikipedia.org/wiki/Seeking" title="Seeking">seeking</a>. But the point remains the same. Disks are the only core parts of your system that have moving parts, so they're going to be slow! So if you want to speed things up, a good place to start is reducing I/O.</p>
<p>I don't want to turn this into a lesson on how C and C++ programs are compiled, so I'm going to cut to the chase. We know that the preprocessor parses each file before it's compiled which means that each file is going to be opened. When those parsed source files are then compiled, they're essentially opened again. Each of those files requires another seek. When the object file is generated, that's another seek. When the file is linked, that's another seek. There's lots of disk activity going on here!</p>
<p>If you haven't caught on yet, let me give you another hint. Each source file results in a couple of new files and a stack of seeks. We also have a neat preprocessor statement at our disposal (<em>*cough*</em> <a href="http://en.wikipedia.org/wiki/Header_file" title="Header File">include</a> <em>*cough*</em>).</p>
<p>That's right guys, we don't actually compile every file individually. We instead create a master file (or set of master files, depending on how big your source base is), which <em>includes</em> all of the other source files. This file (or set of files) is compiled instead.</p>
<p><a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-01.png" rel="lightbox[unitybuild]" title="Sample Project"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-01.thumbnail.png" class="InlineImageLeft" alt="Sample Project" /></a>To make it clear I'm going to show you the principle in action on a fake project in Visual Studio 2008. However, the principle can be applied regardless of the compiler and platform. Check out the screenshot on the left. This shows a standard C++ with a few files in it. Ordinarily each of those files will be compiled individually, and hence slowly.</p>
<p>The first step in creating a UB is to make a new project configuration which you can play with. Doing so will allow you to set up an area you can modify without breaking the "normal" project which will continue to be built as usual. So let's do that now. Create a new project configuration based on the debug build. See the following screenies:<br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-02.png" rel="lightbox[unitybuild]" title="Configuration Manager - New Config"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-02.thumbnail.png" class="InlineImageLeft" alt="Configuration Manager - New Config" /></a><br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-03.png" rel="lightbox[unitybuild]" title="New Solution Configuration"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-03.thumbnail.png" class="InlineImageLeft" alt="New Solution Configuration" /></a><br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-04.png" rel="lightbox[unitybuild]" title="Configuration Manager - Config Added and Selected"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-04.thumbnail.png" class="InlineImageLeft" alt="Configuration Manager - Config Added and Selected" /></a></p>
<div style="float: none; clear: both;"></div>
<p><a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-05.png" rel="lightbox[unitybuild]" title="Build Toolbar - Config Selected"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-05.thumbnail.png" class="InlineImageRight" alt="Build Toolbar - Config Selected" /></a>When you've created the new configuration, make sure you have it set as the active configuration as shown on the right.</p>
<p><a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-06.png" rel="lightbox[unitybuild]" title="Solution with Unity Build File"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-06.thumbnail.png" class="InlineImageLeft" alt="Solution with Unity Build File" /></a>Then, you need to add a new file which will be the master UB file. I usually create a sub-folder in the project and add the file there. Both folder and file I tend to call UnityBuild.</p>
<p><a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-07.png" rel="lightbox[unitybuild]" title="Unity Build File Contents"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-07.thumbnail.png" class="InlineImageRight" alt="Unity Build File Contents" /></a>When the file is created, the first thing we need to do is make sure that we edit the UnityBuild.cpp so that it includes <em>all</em> of the other files in the project. Check out the image for the example.</p>
<p>If we attempted to compile at this point, we have all kinds of issues. Everything right now is being included twice. So we need to fix that so that we don't have issues in <em>every</em> configuration. Let's start by fixing up the Unity build project. Select all of the source files <em>except</em> UnityBuild.cpp, and <strong>exclude them</strong> from the project (right-click on them to see the properties). Check out the pics below to see how it's done.<br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-08.png" rel="lightbox[unitybuild]" title="Files selected"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-08.thumbnail.png" class="InlineImageLeft" alt="Files selected" /></a><br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-09.png" rel="lightbox[unitybuild]" title="Exclude from build"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-09.thumbnail.png" class="InlineImageLeft" alt="Exclude from build" /></a><br />
<a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-10.png" rel="lightbox[unitybuild]" title="Solution with files excluded"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-10.thumbnail.png" class="InlineImageLeft" alt="Solution with files excluded" /></a></p>
<div style="float: none; clear: both;"></div>
<p>So that this point you've excluded the files from the UnityDebug configuration, and hence the unity configuration <em>should</em> build.</p>
<p><strong>Note:</strong> if you're implementing this in a large existing source base you may find that the UB doesn't actually compile. You need to bear in mind that the preprocessor is making <strong>one large file</strong> out of all of your source files. Which means global variables, static variables, global functions, etc that appear more than once in the source code will now tread all over each other. Technically you shouldn't have this problem if you're writing "proper" code <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> But the harsh reality is that lots of devs copy and paste code, duplicate function names, and all kinds of other horrible things. To get it working, you're going to have to do a bit of housekeeping! But since this is going to affect the source in a positive way, it can only be a good thing!</p>
<p><a href="http://buffered.io/wp-content/uploads/2007/12/unitybuild-11.png" rel="lightbox[unitybuild]" title="Unity build file excluded"><img src="http://buffered.io/wp-content/uploads/2007/12/unitybuild-11.thumbnail.png" class="InlineImageLeft" alt="Unity build file excluded" /></a>OK, next up let's get the other builds working again. You need to exclude the UnityBuild.cpp file from the build in both the Debug and Release builds (not the UnityDebug configuration). I won't show you how to do that, as it should be obvious. When you're done, you should see similar to the image on the left when you use the Debug or Release configurations from this point on.</p>
<p>You're done! The old builds should work just fine because your UB file isn't included in the configuration. Once you've sorted out the code duplication issues with the UB configuration, you should have a perfectly working configuration.</p>
<p>You may find that the whole process is much easier if you're building from the command line, especially using <a href="http://en.wikipedia.org/wiki/Make_%28software%29" title="make">make</a> on <a href="http://en.wikipedia.org/wiki/%2Anix" title="Unix-like">*nix</a> machines, as you don't have to worry about excluding things from configurations. Instead, you just simply need to pass in a single file to the compiler - the UB file!</p>
<p>So after all that, what kind of improvements should expect to find? Well let me give you a few stats. When the UB was implemented at the game company I worked for, the build time dropped from 55 minutes to <strong>just over 6 minutes</strong>. When I implemented UB in a previous job the build time dropped from 10 minutes to <strong>less than 3 minutes</strong>. When I put them in place at home the build times dropped on average by <strong>60%</strong>.</p>
<p>I'd be very surprised if you didn't notice a huge improvement in your build times if you use this mechanism.</p>
<p>Before I finish up, I need to highlight a few issues around housekeeping. As already stated, these builds are not used to replace the normal compilations. They should sit alongside to make it faster for the developer to do his or her work. This means that you need to make sure that both types of builds are <em>working all the time</em>. Keep your automatic builds using the normal build type, and you'll soon find out if you've not been maintaining your configurations properly.</p>
<p>Make sure that every time you add a new source file you <strong>exclude it from the UB configuration</strong>, and that you <strong>add it to the content of the UnityBuild.cpp file</strong> otherwise it won't be compiled and included in the build properly.</p>
<p>On the whole, UBs have really improved the speed in which I've been able to do things. My wait time for compilations is generally a third of what it was. That, in my view, is worth the "hack" <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>Thanks for reading!</p>
<p>PS. Please let me know of any typos, grammar errors, etc. It was a hefty post to put together and I might have missed a couple of obvious stuff-ups!</p>
<p><em>EDIT: I have fixed up a few grammar and spelling errors. Thank you Yoann and Bryce <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </em></p>
<hr/>
<strong>This post is a bit old, and some of the images are missing. While it's still got a valid description of Unity Builds it's not really complete without the piccies. So I've created a full screencast and posted that <a href="http://buffered.io/2008/06/19/screencast-setting-up-unity-builds/" title="Screencast - Setting up Unity Builds">over here</a> to clear up any confusion. Cheers!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/12/10/the-magic-of-unity-builds/feed/</wfw:commentRss>
		<slash:comments>32</slash:comments>
		</item>
		<item>
		<title>Avoid Writing Unintuitive Code</title>
		<link>http://buffered.io/2007/07/20/avoid-writing-unintuitive-code/</link>
		<comments>http://buffered.io/2007/07/20/avoid-writing-unintuitive-code/#comments</comments>
		<pubDate>Fri, 20 Jul 2007 00:33:45 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/07/20/avoid-writing-unintuitive-code/</guid>
		<description><![CDATA[This blog post was inspired by a brief chat I had recently with Kirupa of kirupa.com. I subscribe to his blog's RSS feed as he comes out with some really good stuff. His recent post which showed a way of shuffling a List of strings (using C#) inspired a bit of thought on the topic [...]]]></description>
			<content:encoded><![CDATA[<p>This blog post was inspired by a brief chat I had recently with Kirupa of <a href="http://www.kirupa.com/" title="Kirupa">kirupa.com</a>. I subscribe to his <a href="http://blog.kirupa.com/" title"Kirupa Blog">blog's</a> <a href="http://blog.kirupa.com/?feed=rss2" title="Kirupa Blog RSS">RSS feed</a> as he comes out with some really good stuff. His <a href="http://blog.kirupa.com/?p=111" title="Randomizing Elements in a List (C#)">recent post</a> which showed a way of shuffling a List of strings (using C#) inspired a bit of thought on the topic of code readability, how and when it's learned (if at all) and why there is so little of it around.</p>
<p>Code quality and readability is something that isn't necessarily learned at University, nor is it something that can be mastered in a short period of time. It <em>is</em> something that <strong>anyone</strong> can learn. The main ingredients that are required are a bit of self-scrutiny, and the removal of the assumption that working code is the same as finished code. </p>
<p>Let me start by applauding Kirupa for the effort he puts into his posts, and the level of quality he achieves. This is by no means a stab at his work. I'm grateful that he's happy to discuss how his code can be improved. It's rare to find someone who's open to constructive criticism! Like me, he appears to be keen to learn from other people - if only there were more of those people around!</p>
<p>To avoid confusion, I think I should clarify exactly what I mean by "Unintuitive Code". In a nutshell, what I mean is: <em>Code which fails to imply its purpose/functionality through poor use of language features, semantics, structure, naming conventions and natural language</em>. Phew!</p>
<p>I'd like to share my thoughts on the steps that you can take to aid in writing more readable and maintainable code, developing interfaces to objects that are intuitive, and imply the right kinds of things with regards to the way the functions operate.</p>
<h3>Solve the problem first</h3>
<p>This doesn't mean write code! This means get a pen and paper, or a white board and a marker! Write down what you think the problem really is and break it into smaller chunks which can be broken down into a set of logical steps. When you give yourself a clearer understanding of what the problem is you'll increase the chance of writing more meaningful code with a much clearer interface.</p>
<p>When you've broken the problem down into smaller chunks, it's highly likely you'll then find issues that you wouldn't have seen or considered if you'd just fired up your code editor first. This is good because you've now got a greater understanding of the problem space, and can now create a more meaningful and appropriate code architecture while keeping in mind the issues that you've already stumbled across. The amount of "coding in the dark" you have to do has already been minimised.</p>
<p>At this point you've already prevented the need to refactor your code before you've even finished the first iteration. Your interfaces will be cleaner, and the number of 'hacks' that you'll have to put in to fix things you hadn't initially thought of will be substantially reduced. Don't underestimate how valuable a bit of up-front analysis and design can help with keeping your code clean.</p>
<p>Once you're done with improving your understanding of the problem space, you're ready to open your editor and start writing code. Writing defensively from the start is a good idea, particularly if the code is going to end up being maintained by someone else.</p>
<h3>Write your first iteration</h3>
<p>Put your ideas down in code. Try your best to make an intuitive model, using <a href="http://buffered.io/2007/07/14/creating-concrete-objects/trackback/" title="Creating Concrete Objects">concrete objects</a> where applicable, trying your best to reduce coupling, and separating implementation from interface. While this is a key phase, it's not as key as the next one! Make sure that when you're done writing your first version, you prepare yourself to be happy to rip out a large portion of what you write - because you're going to be replacing it with something better.</p>
<h3>Call a spade a spade</h3>
<p>If you want the marks, state the bloody obvious! That is, your funtions should state exactly what they do. I'm not suggesting that you have function names like <em>GetAReferenceToTheNormalVectorAndUseItToCalculateTheLightingForThePolygon()</em> as that's a bit over the top. Try to avoid names like <em>DoStuff()</em>, <em>ProcessData()</em>, <em>DoEvents()</em> (yes, that's <a href="http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.doevents.aspx" title="DoEvents">a stab at you, Microsoft</a>) and <em>GetDoohicky()</em>. Names like <em>CalculateLighting()</em> and <em>GetNormal()</em> are descriptive enough and do a good job of implying their function. Don't mislead the user of your class by using names that quite clearly suck.</p>
<h3>Review your interfaces and functions</h3>
<p>There's a strong possibility that even though you've put a great deal of thought into your solution, you've still managed to imply certain things that you didn't necessarily mean.</p>
<p>The interface to an object and the signature of your functions can (and should) say more about your code than you think. So ask yourself the following:
<ul>
<li>Does your object name reflect the functionality that it encapsulates?</li>
<li>Does the function imply operations that don't happen?</li>
<li>Does the function not imply functions that <em>do</em> happen?</li>
<li>Is the function's name descriptive of the type of function that it actually is?</li>
<li>Does your function return a meaningful value based on the context?</li>
<li>Does your function require intuitive parameters for it to function?</li>
<li>Is the parameter list as minimal as possible without affecting the functionality?</li>
</ul>
<p>I'm sure there are more, but I can't think of them off the top of my head.</p>
<p>When you've finished with your review, ask someone else to have a read of it. Ask them to give you a brief overview of your classes/functions as if you didn't know the code and they did. If they give a pretty good picture of what the object does, then you've done well. If they can't tell you what goes on at a high-level then you'll have to go through another review iteration.</p>
<h3>Add comments that clarify, and remove comments that don't</h3>
<p>I'm almost certain that every maintenance coder on the planet has been faced with the nasty combination of confusing code and invalid comments. It not only doesn't help, it makes things <em>worse</em>. Here is an example of a "WTF comment":</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #ff0000; font-style: italic;">/* this class handles date formats */</span>
<span style="color: #0000ff;">class</span> Profile
<span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">// code goes here</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>If you didn't say "WTF!?" to the above code, then please go to the start of this post, and reread!</p>
<h3>Iterate</h3>
<p>Make sure that you don't stop working when the code starts working. Working code is <em>not</em> the same as finished code. Keep reviewing your work. Look for possible improvements. Be critical of your own work. Treat your own code as if it was someone else's and treat the task as though the result is going to be shown to a stack of other developers.</p>
<h3>Be receptive to post-release feedback</h3>
<p>When your code gets used by other people, you'll end up with more suggestions and possible tweaks to make it less unintuitive. Don't be ignorant, even if the suggestions are petty. Take them on board and see if you can utilise those bits of feedback to aid in production of even better quality code!</p>
<p>Good luck <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/07/20/avoid-writing-unintuitive-code/feed/</wfw:commentRss>
		<slash:comments>11</slash:comments>
		</item>
		<item>
		<title>And Help You I Shall!</title>
		<link>http://buffered.io/2007/07/18/and-help-you-i-shall/</link>
		<comments>http://buffered.io/2007/07/18/and-help-you-i-shall/#comments</comments>
		<pubDate>Wed, 18 Jul 2007 02:15:37 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/07/18/and-help-you-i-shall/</guid>
		<description><![CDATA[My previous post on constructing meaningful questions was inspired by years of frustrating experiences on forums and bulletin boards, but it wasn't until I had a chat with me ol' mucka Dan that I realised that there are actually quite a few cases where good quality questions are given inappropriate or completely misleading answers. The [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://buffered.io/2007/07/14/help-me-help-you/" title="Help me help you!">previous post</a> on constructing meaningful questions was inspired by years of frustrating experiences on forums and bulletin boards, but it wasn't until I had a chat with me ol' mucka <a href="http://www.shiftperception.com/blog/" title="Shifty Blog">Dan</a> that I realised that there are actually quite a few cases where good quality questions are given inappropriate or completely misleading answers.</p>
<p>The intent of this post is to cover that side of the argument. How do you give a meaningful answer to a well constructed question? </p>
<p>I'd like to start by sharing an example of a recent forum thread that I saw which highlights the issue nicely.<br />
<blockquote>
<p><strong>Asker:</strong> I've recently been given the task of creating a C++/Win32 version of application <em>appname</em>. Unfortunatley I've never written any Win32 code before, so I need a few pointers to get started. Can someone please show me an example how to create a Window using Win32 and C++?</p>
<p><strong>Answerer 1:</strong> Download .NET and use managed C++ to create your form.</p>
<p><strong>Answerer 2:</strong> I use allegro for everything, and I think it's great. Download allegro and use the tutorials.</p>
<p><strong>Answerer 3:</strong> Managed DirectX extensions make it easy to GUIs, try using that.</p>
<p><strong>Answerer 4:</strong>Using Win32 is a pain, why are you using it? Why not use Java?</p>
<p><strong>Answerer 5:</strong> If you're going to use a graphics API then you're better off using something like SDL which is cross-platform.</p>
</blockquote>
<p>Is it just me, or are all of those answers total and utter shit?</p>
<p>The bloke who asked the question clearly wanted an example of window creation using the <a href="http://en.wikipedia.org/wiki/Win32" title="Windows API">Win32 API</a> and C++. What did he get in response? Recommendations for 5 other technologies that people like to use for their own projects. Not one meaningful answer.</p>
<p>As far as I'm concerned this is the same as having someone ask "<em>I'm really in the mood for fish and chips, does anyone know a good shop to get some?</em>" and have a few people respond with "<em>Well, if you're going to eat food, then you should consider a Thai Green Curry with Lamb</em>" or "<em>When I eat, I like to have lots of sugar. So go to Dreamy Donuts, and try the super heart-stopping, 3-hour-old, artery-blocking cardboard donut. It's fantastic!</em>". WTF has that got to do with fish and chips?!</p>
<p>One of the universal issues we face is the fact that people do not have the ability to <strong>read the question</strong>. It's something that people have had a problem with since the early days of school. They fail to read the question properly, and instead come up with their own version of the question that isn't the same, and hence their answer is poor.</p>
<p>In the case of coders, there's a bit more to it. People like to preach and evangelise technology, languages or applications that they like to use, as it makes them feel good. Most people like to push form threads and conversations towards a topic they consider themselves to be experts in because it gives them the chance to get on a soap box.</p>
<p>Now, I'm not going to say that I don't get on a soap box, because I quite clearly do! <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> But the point I'm trying to make is that people who ask specific questions deserve specific answers. So here are my rules of thumb for answering peoples questions.
<ol>
<li><strong>Read the question. Then read it again.</strong> There is no way you're going to be able to give a meaningful answer to a well constructed question without fully understanding what's being asked. Try to adhere to the golden rule of answering questions: <em>If all else fails, <u>READ THE QUESTION</u>.</em></li>
<li><strong>Answer the question, but don't post the response.</strong> Answers to questions are like solutions to problems in development. Your first iteration is going to be a solution, but it's not going to be the best solution. Reread your answer. Scrutinise it. Look for as many holes as you can find. Any that you miss will be picked up by someone else!</li>
<li><strong>Rewrite your answer.</strong> After you've answered, and you've found the holes. You'll no doubt have to rewrite it. Make sure you use grammar, punctuation and well constructed sentences. Try to keep sentences as short as possible. Be as clear as you can without being verbose. Provide examples of code or references to cases where your view has worked in the past. Provide links to documentation to support your answer.</li>
<li><strong>Direct your answer at the question!</strong> Make sure that your answer does actually answer the question. Make specific references to the parts of the question that you're answering and point out how it's of benefit, or how it actually relates to the problem.</li>
<li><strong>Don't evanglise your favourite technology.</strong> If you come across as an evangelist, then people will tend not to take your response seriously. It's easy to see whether someone has an open view, or whether they're biased towards something they have a passion for. Don't be a preacher!</li>
<li><strong>Don't answer if you don't know!</strong> Lots of people seem to put their $0.02 into the conversation even if they don't know what they're talking about. It's quite simple: if you don't know the answer, do not respond to the question. You won't be adding anything of value to the discussion and you'll end making yourself look stupid. Instead, you should monitor the thread and wait for someone else to respond. Chances are you'll end up learning something!</li>
</ol>
<p>Thoughts?</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/07/18/and-help-you-i-shall/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Creating Concrete Objects</title>
		<link>http://buffered.io/2007/07/14/creating-concrete-objects/</link>
		<comments>http://buffered.io/2007/07/14/creating-concrete-objects/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 10:21:05 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Software Development]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/07/14/creating-concrete-objects/</guid>
		<description><![CDATA[Being a fan of OOP, I tend to write a lot of object-oriented code. Coming up with a meaningful object model that behaves in an appropriate way is just as important as having a meaningful interface to your objects. A concrete object is an object that actually behaves in the manner you'd expect without any [...]]]></description>
			<content:encoded><![CDATA[<p>Being a fan of <a href="http://en.wikipedia.org/wiki/Object-oriented_programming" title="Object-oriented Programming">OOP</a>, I tend to write a lot of object-oriented code. Coming up with a meaningful object model that behaves in an appropriate way is just as important as having a meaningful interface to your objects. A concrete object is an object that actually behaves in the manner you'd expect without any wierd side-effects, and has the same kind of attributes that you'd expect of a primitive data type.</p>
<p>Creating concrete data objects/classes is a good thing to do, as it reduces the probability of bugs, and crazy side-effects. It's also an important first step in writing intuitive code - which will be the topic of a later blog post. </p>
<p>I'd like to quote one of my lecturers that I learned from during my time at <a href="http://www.uts.edu.au/" title="University of Technology, Sydney">UTS</a>...<br />
<blockquote>
<p>If in doubt, do as the ints do.</p>
</blockquote>
<p>I realise the meaning of this point isn't obvious on the surface, but with some example code it'll all become clear.</p>
<h3>An example concrete data type - a 3D Vector class</h3>
<p>Let's say you're writing some code to do some 3D rendering, and you're in need of a class that can handle the functionality and behaviour of Vectors in 3D space. The first and most obvious thing that you need to handle are x, y and z coordinates. Let's start with a very basic Vector3 class:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #0000ff;">float</span> X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> Z<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>At this point you've got an object that gives public access to its internal workings. Can we say that's what the int datatype does? Are you able to mess around with its inner workings? No, you're not. Not just that, but the idea of public member variables breaks the whole notion of <a href="http://en.wikipedia.org/wiki/Information_hiding" title="Information Hiding">encapsulation/information hiding</a>. We need to hide the internal workings, but in doing so we remove the ability to set and get the values on the object. We need to expose some functions that will allow us to do that. Our improved version of the code might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This is an improvement, as we now have control over the inner workings of the object without exposing the implementation to external classes. Now let's say that we want to be able to construct a new Vector3 object through a variety of ways, ie. in exactly the same way we can with int. For example:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// this is what we can do with ints:</span>
<span style="color: #0000ff;">int</span> a<span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">1</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> b <span style="color: #000080;">=</span> a<span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> c<span style="color: #008000;">&#40;</span> b <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #0000ff;">int</span> d, e<span style="color: #008080;">;</span>
d <span style="color: #000080;">=</span> e <span style="color: #000080;">=</span> c<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// we want do the same kind of things with our</span>
<span style="color: #666666;">// own class</span>
Vector3 a<span style="color: #008000;">&#40;</span> <span style="color:#800080;">1.0</span>, <span style="color:#800080;">0.0</span>, <span style="color: #000040;">-</span><span style="color:#800080;">1.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
Vector3 b <span style="color: #000080;">=</span> a<span style="color: #008080;">;</span>
Vector3 c<span style="color: #008000;">&#40;</span> b <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
Vector3 d, e<span style="color: #008080;">;</span>
d <span style="color: #000080;">=</span> e <span style="color: #000080;">=</span> c<span style="color: #008080;">;</span></pre></div></div>

<p>We need to expose some options for construction and assignment. So our next iteration might look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operator</span>
  <span style="color: #0000ff;">void</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The above interface should do what we need it to... or should it? A more careful examination will reveal that it doesn't actually behave exactly as you'd expect. The copy constructor takes a reference to another Vector3, which <em>could be modified</em> inside the copy constructor. We have the same issue with our assignment operator. Integers do not behave this way, so we need to modify our interface a bit more to tidy it up:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operator</span>
  <span style="color: #0000ff;">void</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>We've now made sure that the Vector3 class does not modify anything that doesn't belong to it, which again is how the integers behave. But there is still something missing. The assignment operator doesn't allow for chaining (eg. int a = b = c = d;) just like the ints do, so we need to make a slight adjustment to the overload:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// return a const reference to ourself</span>
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>There, much better.</p>
<p>We're now at the stage where we want to be able to add/subtract/multiply/divide vectors together, but before we start overloading the operators we should look at the way integers behave when they go through the same operations:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">int</span> a, b, c, d<span style="color: #008080;">;</span>
a <span style="color: #000080;">=</span> b<span style="color: #008080;">;</span> <span style="color: #666666;">// b doesn't change, a does.</span>
a <span style="color: #000040;">*</span> b<span style="color: #008080;">;</span> <span style="color: #666666;">// both a and b do not change.</span>
a <span style="color: #000080;">=</span> b <span style="color: #000040;">*</span> c<span style="color: #008080;">;</span> <span style="color: #666666;">// both b and c do not change, but a does.</span>
a <span style="color: #000080;">=</span> <span style="color: #008000;">&#40;</span> b <span style="color: #000040;">+</span> c <span style="color: #008000;">&#41;</span> <span style="color: #000040;">*</span> d<span style="color: #008080;">;</span> <span style="color: #666666;">// a is the only thing that changes</span>
a <span style="color: #000040;">+</span><span style="color: #000080;">=</span> b <span style="color: #000040;">/</span> c<span style="color: #008080;">;</span> <span style="color: #666666;">// again, a is the only thing that changes.</span></pre></div></div>

<p>It's obvious from this that when we overload the operators, we only modify the content of the object if it is on the left hand side of one of the assignment operators. Our interface should make this obvious:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operators - not const because the current object</span>
  <span style="color: #666666;">// needs to change</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// other operators - all const functions to make sure that the</span>
  <span style="color: #666666;">// internal state of the object doesn't get modified when the</span>
  <span style="color: #666666;">// function is called. Separate temporary instances of Vector3</span>
  <span style="color: #666666;">// objects are created and  returned when executed.</span>
  Vector3 operator<span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 + v2</span>
  Vector3 operator<span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 - v2</span>
  Vector3 operator<span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 * v2</span>
  Vector3 operator<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 / v2</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The class is starting to take shape, but there are some other functions missing that are an integral part of any Vector class: normalise(), dot() and cross().</p>
<p>The normalise function is used to create a <a href="http://en.wikipedia.org/wiki/Unit_vector" title="Unit Vector">unit vector</a> (ie. a vector with a length of 1.0). But the question here is: when calling the function, should the object be modified, or should it return a copy of the Vector with a unit length? Let's look at the difference in function signatures:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// this function would modify the object directly</span>
<span style="color: #0000ff;">void</span> Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #666666;">// this function would return a new vector that is normalised</span>
Vector3 Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span></pre></div></div>

<p>Making a decision like this can be a bit of a pain in the butt, but we're fortunate in this case because we can deduce what should be done! Generally when dealing with normalised vectors, we tend to retain a reference to the normal while dealing with a stack of other vectors. So another instance of a vector is used alongside the other vectors. Let's look at how this might be done with both above functions if we had a vector that we wanted to reuse, but get a normalise version of at the same time:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #666666;">// this is the vector we want to keep as is, but need a</span>
<span style="color: #666666;">// normalised copy of</span>
Vector3 someVector<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// here's how we'd do it with the first option:</span>
Vector3 normal1 <span style="color: #000080;">=</span> someVector<span style="color: #008080;">;</span>
normal1.<span style="color: #007788;">Normalise</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
<span style="color: #666666;">// here's how we'd do it with the second option:</span>
Vector3 normal2 <span style="color: #000080;">=</span> someVector.<span style="color: #007788;">Normalise</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>In my view, the second option is easier to read, and is a bit more intuitive. Not just that, but it's less code! So based on this, we'll utilise the second version of the function. Our class now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operators - not const because the current object</span>
  <span style="color: #666666;">// needs to change</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// other operators - all const functions to make sure that the</span>
  <span style="color: #666666;">// internal state of the object doesn't get modified when the</span>
  <span style="color: #666666;">// function is called. Separate temporary instances of Vector3</span>
  <span style="color: #666666;">// objects are created and  returned when executed.</span>
  Vector3 operator<span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 + v2</span>
  Vector3 operator<span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 - v2</span>
  Vector3 operator<span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 * v2</span>
  Vector3 operator<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 / v2</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// helpers</span>
  Vector3 Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>So, next up we need the dot() function, which gives us the <a href="http://en.wikipedia.org/wiki/Dot_product" title="Dot Product">dot product</a> of two vectors. The dot product is a single value which represents the angle between the two vectors, so that's what the function should return. Since the dot product requires two vectors, it would make sense for the function to be given a reference to the secont vector that is part of the dot product equation. <strong>None</strong> of the objects should be modified at all during the course of the function, so we should make that obvious in the function signature. Our class now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operators - not const because the current object</span>
  <span style="color: #666666;">// needs to change</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// other operators - all const functions to make sure that the</span>
  <span style="color: #666666;">// internal state of the object doesn't get modified when the</span>
  <span style="color: #666666;">// function is called. Separate temporary instances of Vector3</span>
  <span style="color: #666666;">// objects are created and  returned when executed.</span>
  Vector3 operator<span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 + v2</span>
  Vector3 operator<span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 - v2</span>
  Vector3 operator<span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 * v2</span>
  Vector3 operator<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 / v2</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// helpers</span>
  Vector3 Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">double</span> Dot<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>Note that the function is marked as const to imply that the object will <em>not</em> have a different state when it's called, and the parameter is a const reference to imply that the parameter will not be modified as well.</p>
<p>Finally, we need a function which will determine the <a href="http://en.wikipedia.org/wiki/Cross_product" title="Cross Product">cross product</a> of two vectors (commonly used to determine the vector that is perpendicular to two input vectors. The cross product equation takes two vectors and results in another vector, which again implies that the two input vectors do not change. Based on this implication, our function signature should be easy to deduce. While we're there, let's just chuck in a cheeky length() function which will give us the magnitude of the vector. Our class now looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operators - not const because the current object</span>
  <span style="color: #666666;">// needs to change</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// other operators - all const functions to make sure that the</span>
  <span style="color: #666666;">// internal state of the object doesn't get modified when the</span>
  <span style="color: #666666;">// function is called. Separate temporary instances of Vector3</span>
  <span style="color: #666666;">// objects are created and  returned when executed.</span>
  Vector3 operator<span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 + v2</span>
  Vector3 operator<span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 - v2</span>
  Vector3 operator<span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 * v2</span>
  Vector3 operator<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 / v2</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// helpers</span>
  Vector3 Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">double</span> Dot<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">double</span> Length<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  Vector3 Cross<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>The interface to our class now looks fine.. except for one small omission. Const objects are read-only objects, and hence reading values from a const object should be legal. On the flip side, when we read a given x, y, or z value from a vector the vector shouldn't be modified at all. So with that in mind, we should mark each of the getter function as const as well:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000ff;">class</span> Vector3
<span style="color: #008000;">&#123;</span>
<span style="color: #0000ff;">private</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// change the variable names to make it obvious that</span>
  <span style="color: #666666;">// they are member variables, not local or global.</span>
  <span style="color: #0000ff;">float</span> m_X<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Y<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> m_Z<span style="color: #008080;">;</span>
&nbsp;
<span style="color: #0000ff;">public</span><span style="color: #008080;">:</span>
  <span style="color: #666666;">// construction - default to zero if nothing is passed in</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> y <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span>, <span style="color: #0000ff;">float</span> z <span style="color: #000080;">=</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  Vector3<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// assigment operators - not const because the current object</span>
  <span style="color: #666666;">// needs to change</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> operator<span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// other operators - all const functions to make sure that the</span>
  <span style="color: #666666;">// internal state of the object doesn't get modified when the</span>
  <span style="color: #666666;">// function is called. Separate temporary instances of Vector3</span>
  <span style="color: #666666;">// objects are created and  returned when executed.</span>
  Vector3 operator<span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 + v2</span>
  Vector3 operator<span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 - v2</span>
  Vector3 operator<span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 * v2</span>
  Vector3 operator<span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span> <span style="color: #666666;">// v1 / v2</span>
&nbsp;
  <span style="color: #666666;">// getters</span>
  <span style="color: #0000ff;">float</span> GetX<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetY<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">float</span> GetZ<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// setters</span>
  <span style="color: #0000ff;">void</span> SetX<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetY<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">void</span> SetZ<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #666666;">// helpers</span>
  Vector3 Normalise<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">double</span> Dot<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">double</span> Length<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
  Vector3 Cross<span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span><span style="color: #008080;">;</span></pre></div></div>

<p>We're done! Our class looks complete (enough), so let's pump out a definition for the functions (just for the sake of clarity).</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;">Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Vector3</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x, <span style="color: #0000ff;">float</span> y, <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span>
<span style="color: #008080;">:</span> m_X<span style="color: #008000;">&#40;</span> x <span style="color: #008000;">&#41;</span>,
  m_Y<span style="color: #008000;">&#40;</span> y <span style="color: #008000;">&#41;</span>,
  m_Z<span style="color: #008000;">&#40;</span> z <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">// don't need to do anything in the body of the</span>
  <span style="color: #666666;">// function because we're using the initialisation</span>
  <span style="color: #666666;">// lists instaed.</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Vector3</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008080;">:</span> m_X<span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">m_X</span> <span style="color: #008000;">&#41;</span>,
  m_Y<span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">m_Y</span> <span style="color: #008000;">&#41;</span>,
  m_Z<span style="color: #008000;">&#40;</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">// don't need to do anything in the body of the</span>
  <span style="color: #666666;">// function because we're using the initialisation</span>
  <span style="color: #666666;">// lists instaed.</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #666666;">// check for self-assignment</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> <span style="color: #0000dd;">this</span> <span style="color: #000040;">!</span><span style="color: #000080;">=</span> <span style="color: #000040;">&amp;</span>v <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    m_X <span style="color: #000080;">=</span> v.<span style="color: #007788;">m_X</span><span style="color: #008080;">;</span>
    m_Y <span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Y</span><span style="color: #008080;">;</span>
    m_Z <span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Z</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
&nbsp;
  <span style="color: #666666;">// return a reference to ourselves for chaining</span>
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">+</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_X <span style="color: #000040;">+</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_X</span><span style="color: #008080;">;</span>
  m_Y <span style="color: #000040;">+</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Y</span><span style="color: #008080;">;</span>
  m_Z <span style="color: #000040;">+</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Z</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">-</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_X <span style="color: #000040;">-</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_X</span><span style="color: #008080;">;</span>
  m_Y <span style="color: #000040;">-</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Y</span><span style="color: #008080;">;</span>
  m_Z <span style="color: #000040;">-</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Z</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">*</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_X <span style="color: #000040;">*</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_X</span><span style="color: #008080;">;</span>
  m_Y <span style="color: #000040;">*</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Y</span><span style="color: #008080;">;</span>
  m_Z <span style="color: #000040;">*</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Z</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">/</span><span style="color: #000080;">=</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_X <span style="color: #000040;">/</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_X</span><span style="color: #008080;">;</span>
  m_Y <span style="color: #000040;">/</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Y</span><span style="color: #008080;">;</span>
  m_Z <span style="color: #000040;">/</span><span style="color: #000080;">=</span> v.<span style="color: #007788;">m_Z</span><span style="color: #008080;">;</span>
&nbsp;
  <span style="color: #0000ff;">return</span> <span style="color: #000040;">*</span><span style="color: #0000dd;">this</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">+</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">+</span> v.<span style="color: #007788;">m_X</span>, m_Y <span style="color: #000040;">+</span> v.<span style="color: #007788;">m_Y</span>, m_Z <span style="color: #000040;">+</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">-</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">-</span> v.<span style="color: #007788;">m_X</span>, m_Y <span style="color: #000040;">-</span> v.<span style="color: #007788;">m_Y</span>, m_Z <span style="color: #000040;">-</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">/</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">/</span> v.<span style="color: #007788;">m_X</span>, m_Y <span style="color: #000040;">/</span> v.<span style="color: #007788;">m_Y</span>, m_Z <span style="color: #000040;">/</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">operator</span><span style="color: #000040;">*</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_X</span>, m_Y <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Y</span>, m_Z <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">float</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">GetX</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> m_X<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">float</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">GetY</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> m_Y<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">float</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">GetZ</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> m_Z<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">SetX</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> x <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_X <span style="color: #000080;">=</span> x<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">SetY</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> y <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_Y <span style="color: #000080;">=</span> y<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">void</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">SetZ</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">float</span> z <span style="color: #008000;">&#41;</span>
<span style="color: #008000;">&#123;</span>
  m_Z <span style="color: #000080;">=</span> z<span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Normalise</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">double</span> length <span style="color: #000080;">=</span> Length<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #0000ff;">if</span><span style="color: #008000;">&#40;</span> length <span style="color: #000080;">==</span> <span style="color:#800080;">0.0</span> <span style="color: #008000;">&#41;</span>
  <span style="color: #008000;">&#123;</span>
    <span style="color: #666666;">// return a zero vector if it's got zero length</span>
    <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
  <span style="color: #008000;">&#125;</span>
  <span style="color: #0000ff;">double</span> invLength <span style="color: #000080;">=</span> <span style="color:#800080;">1.0</span> <span style="color: #000040;">/</span> length<span style="color: #008080;">;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">*</span> invLength, m_Y <span style="color: #000040;">*</span> invLength, m_Z <span style="color: #000040;">*</span> invLength <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">double</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Dot</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span>  m_X <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_X</span> <span style="color: #000040;">+</span> m_Y <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Y</span> <span style="color: #000040;">+</span> mZ <span style="color: #000040;">*</span> v.<span style="color: #007788;">mZ</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
<span style="color: #0000ff;">double</span> Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Length</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> <span style="color: #0000dd;">sqrt</span><span style="color: #008000;">&#40;</span> m_X <span style="color: #000040;">*</span> m_X <span style="color: #000040;">+</span> m_Y <span style="color: #000040;">*</span> m_Y <span style="color: #000040;">+</span> mZ <span style="color: #000040;">*</span> mZ <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span>
&nbsp;
Vector3 Vector3<span style="color: #008080;">::</span><span style="color: #007788;">Cross</span><span style="color: #008000;">&#40;</span> <span style="color: #0000ff;">const</span> Vector3<span style="color: #000040;">&amp;</span> v <span style="color: #008000;">&#41;</span> <span style="color: #0000ff;">const</span>
<span style="color: #008000;">&#123;</span>
  <span style="color: #0000ff;">return</span> Vector3<span style="color: #008000;">&#40;</span> m_Y <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Z</span> <span style="color: #000040;">-</span> m_Z <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Y</span>,
                  m_Z <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_X</span> <span style="color: #000040;">-</span> m_X <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Z</span>,
                  m_X <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_Y</span> <span style="color: #000040;">-</span> m_Y <span style="color: #000040;">*</span> v.<span style="color: #007788;">m_X</span> <span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span>
<span style="color: #008000;">&#125;</span></pre></div></div>

<p>Now that we have a functional class, we should have no problem using it in all of the above scenarios without any crazy side-effects. The class <em>should</em> be concrete! <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>Disclaimer: This code hasn't been compiled, and might not run without a few tweaks. I wrote this off the top of my head while sitting in front of the TV! Comments, questions and flames are welcome.</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/07/14/creating-concrete-objects/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Help Me Help You!</title>
		<link>http://buffered.io/2007/07/14/help-me-help-you/</link>
		<comments>http://buffered.io/2007/07/14/help-me-help-you/#comments</comments>
		<pubDate>Sat, 14 Jul 2007 05:29:51 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Miscellaneous]]></category>
		<category><![CDATA[Tips/Tricks]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/07/14/help-me-help-you/</guid>
		<description><![CDATA[Help!!I need somebody...Help!Not just any body...Help!You know I need someone...HEEEELP! I have lost count of the times I've heard this (and not just when playing The Beatles). In fact, to be honest, I never kept count, but I know it's a lot. On a daily basis I lose a fair bit of time helping my [...]]]></description>
			<content:encoded><![CDATA[<blockquote><p>Help!!<br />I need somebody...<br />Help!<br />Not just any body...<br />Help!<br />You know I need someone...<br />HEEEELP!</p>
</blockquote>
<p>I have lost count of the times I've heard this (and not just when playing The Beatles). In fact, to be honest, I never kept count, but I know it's a lot.</p>
<p>On a daily basis I lose a fair bit of time helping my workmates. I get asked for help while I'm on IM from various "students" and friends I have around the web. I also get to help out family and friends on a regular basis face to face when I vist them or they visit me. I'm basically a constant source of solutions for I.T. and development related problems.</p>
<p>This is something I <em>like</em>! I enjoy helping people solve their problems. I enjoy helping them learn about something they don't know enough about. I like to see them take their new knowledge and apply it to other problems. It's a very satisfying experience. </p>
<p>But there is one problem. The <strong>questions</strong>. For some reason, most people don't seem to think too hard before they speak, and the questions they are ask so esoteric, vague and/or broad that it's close to impossible to give a meaningful answer. This post is about those questions! The target of this post is anyone who needs to ask for help - geeks, non-geeks, students, etc. This will also help those who, on more than one occasion, have asked for help and received <u>none</u>.</p>
<h3>An example of a bad question</h3>
<blockquote><p>Oliver, I have an issue with my code. It isn't adding the item to the list when a button is clicked, what's wrong?</p>
</blockquote>
<p>Some of you might argue that this a fair question, and I'll agree, it <em>is</em> a fair question. But what it lacks is <strong>context</strong>.</p>
<p>My response to the above question was:<br />
<blockquote>
<p>OK, there are quite a few answers to the question, so can you please clarify a few things for me so I can give you a meaningful answer:
<ul>
<li>What is "it"?</li>
<li>What is the "item"? Is it a primitive type, or a class you've created?</li>
<li>Is the application a fat-client app, or a web application?</li>
<li>Which button are you clicking?</li>
<li>...etc</li>
</ul>
</blockquote>
<p>You get the idea. I could have answered straight away with a massive rant about the possible reasons why a given scenario results when a button is pressed, but no doubt it would have been a huge waste of time. Instead, I went for the other option, which was to get a better idea of the problem. After a bit of a digging around, it turns out that the above question <em>should</em> have been:<br />
<blockquote>
<p>Oliver, I have an issue with my web form application. When I press the 'add' button, it is supposed to create a new instance of type <em>Mytype</em>, add that new instance to a collection that is stored in the session, and then post back with the data table populated with the new list of items. When I press the button, the application posts back, but the contents of the list doesn't change. Do you have any idea what's wrong?</p>
</blockquote>
<p>Man what a difference that made!</p>
<p>The essence of getting a good answer to a question is to make sure that the question is a <strong>good question</strong> in the first place.</p>
<h3>An example of a not-so-bad-but-could-be-better question</h3>
<blockquote><p>hey, any idea where i could get an example html for world timezones? pref with country/region and offset?</p>
</blockquote>
<p>Now this certainly isn't bad, and it is possible to deduce the intended meaning of the question from the question! But it turns out that the question should have been:<br />
<blockquote>
<p>hey, do you have any idea where i could get a list of timezones mapped to cities/countries which I can use inside a <em>&lt;select&gt;</em> tag in HTML?</p>
</blockquote>
<h3>The art of meaningful question construction</h3>
<p>You wouldn't think that this could be considered an 'art', but it is. I'm sure there are lots of people out there who have written up a question on a programming forum only to find that it is totally ignored. Nobody responds, and your post simply makes it way to the bottom of the forum pile regardless of the number of times you bounce it to the top again. If this happens, you've asked a shit question. It's that simple.</p>
<p>There are only a few subtle yet important differences that make a question bad instead of good:</p>
<ol>
<li><strong>Assumed knowledge.</strong> 9 out of every 10 questions that are asked are ruined by the fact that the asker assumes that the answerer knows enough about the problem space to just belt it out without too much difficulty. Well, here's a newsflash: <em>they don't!</em>. People who are spending time on forums, or at work, helping people solve their problems require more than just a generic set of information to be able to answer the question properly. In my view, you should always do what my old high-school English teacher told me before going into my final exams: "<em>To get the marks, state the bloody obvious!</em>". Thank you Mrs Price, you're dead right. Too much information on the topic is better than not enough. So be forthcoming, don't assume that the person you're asking is already in the loop.</li>
<li><strong>Vague terminology.</strong> In short, don't use words that don't make sense, that are vague, or that don't add to the meaning. Some examples are: <em>it, item, object, doohicky, thingy, whatsit, dooverlacky, thingamajig, woozit, etc</em>. Be specific. Be direct. Be helpful!</li>
<li><strong>Specific terminology.</strong> This is the total opposite to the previous point. Don't bombard someone with jargon, large words, and acronyms. Eg. instead of saying that you've broken your <em>pre-regulation destroyer-class solid-fuel recoil booster</em> you should instead use the word <em>spring</em>. Large words won't make you look smart, they'll just piss people off and prevent you getting the help you need.</li>
<li><strong>Give a good example.</strong> A lot of the time, the problem that you have is one that's come about from being in the depths of your code. If you can, break it out into a separate application, or "spike" as they like to call it in an <a href="http://en.wikipedia.org/wiki/Agile_software_development" title"Agile Software Development">Agile</a> world, and demonstrate the issue in a much cleaner environment/situation. You're more likely to receive help if you post a snippet of code than if you dump your entire application in source form on a forum.</li>
<li><strong>Think before you speak.</strong> You're in a rush. We know that. Everyone's always in a rush. People tend to jump headfirst into a question without really thinking about what they're asking, and it doesn't benefit them or the person they're speaking to. Take that extra 10 seconds to think about what it is you actually need to ask. When you're able to word in such a way that almost anyone would be able to understand you without prior knowledge, your question is ready to be asked.</li>
<li><strong>Keep it as short as possible without losing information.</strong> Yes, this point slightly contradicts the point I made earlier about too much information being better than not enough. But the point is that you needn't be verbose. Keep it as short as you can, but make sure you've got enough information out to make things clear. Pages and pages of text, and/or a 10 minute ear-bashing is enough to put anyone off helping you.</li>
<li><strong>Do a bit of research first.</strong> This is more for those technical problems than anything, but the rule does generally apply to anything. Chances are that someone else out there has had the same problem as you. It's highly likely that the problem has been solved, and there is information out there which is freely available should you make an effort to seek it out. If you can't find it after a few minutes of searching, then get your thoughts together and write up a decent question. One guaranteed way of pissing someone off is to ask them a question which can be answered by the first result of a basic a Google search. Make the effort to help yourself before you take up someone else's time.</li>
<li><strong>Try to solve the problem yourself first.</strong> This will not only give you a better understanding of the problem, but it will show that you've actually made an effort to solve the problem rather than just getting someone else to do your homework for you.</li>
<li><strong>Be polite.</strong> Be rude, be blunt, be expecting, and you'll be ignored (and rightly so). Don't expect help from people if you're not going to be courteous and/or use manners. If you get help, express appreciation. If someone takes the time to respond to get clarification on your problem, again you should make it obvious that you are grateful. They're on your side, so try and keep them there.</li>
<li><strong>Look at the question from the perspective of the listener.</strong> This is probably the most important point. While writing your question ask yourself:
<ul>
<li>Do they know what *BLAH* actually is?</li>
<li>Do they need to know what *BLAH* actually is?</li>
<li>Are they aware of the environment I'm working in?</li>
<li>Would they need to know your hardware specs?</li>
<li>Should they be made aware of the language you're using?</li>
<li>Is there enough context in my question to remove confusion?</li>
<li>Is there evidence of the fact that I've tried to solve the problem myself?</li>
</ul>
<p>..the list goes on.</li>
<li><strong>Post a meaningful title.</strong> Again this applies in the online world when posting to forums. If you're going to write a post to ask for help, give some context to your problem in your post heading. Here are some things that you should avoid:
<ul>
<li>HELP!! URGENT HELP REQUIRED!!</li>
<li>Stupid homework problem</li>
<li>Why won't this work?</li>
<li>I have 15 mins to finish this.. plz help!</li>
<li>GIVE ME HELP NOW!</li>
</ul>
<p>You don't have to be a rocket scientist to know why those titles are bad. Most regular forum users will just skip your post, and the moderators will probably tear you a new a**eshole for being stupid. Instead, try something like the following:
<ul>
<li>Memory allocation problem using malloc() in C++</li>
<li>CSS problem with IE, works in Firefox</li>
</ul>
<p> These kinds of topic headings are going to not only help give context, but will most likely attract people who are experts in those respective areas.</li>
</ol>
<h3>Questions that should never be asked</h3>
<p>There are some questions that should never, <em>ever</em> be asked.</p>
<ul>
<li><strong>How do I write Quake XVI?</strong> You don't. You're not smart enough.</li>
<li><strong>How do I stop my console program from disappearing when it finishes?</strong> Ask <a href="http://www.google.com.au/search?q=C%2B%2B+pause" title="C++ pause">Google</a>.</li>
<li><strong>Where can I download *insert application name*?</strong> You don't. Go and buy it.</li>
<li><strong>How do I hack into Hotmail?</strong> The authors of Hotmail are much smarter than you. Instead, go outside and look at something shiny.</li>
<li><strong>Can you do my homework for me?</strong> Errr.. no.</li>
</ul>
<p>...etc.</p>
<h3>A final thought...</h3>
<p>Most of the time, people who give a great deal of thought to a problem before asking for someone's help end up solving the problem themselves. You may find that before you even get to voice your question, the answer becomes clear because you've put effort into defining your question!</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/07/14/help-me-help-you/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Becoming a Geek Part 3: The Game Geek</title>
		<link>http://buffered.io/2007/07/13/becoming-a-geek-part-3-the-game-geek/</link>
		<comments>http://buffered.io/2007/07/13/becoming-a-geek-part-3-the-game-geek/#comments</comments>
		<pubDate>Fri, 13 Jul 2007 04:05:07 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[Being in the Industry]]></category>
		<category><![CDATA[HOWTO]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/07/13/becoming-a-geek-part-3-the-game-geek/</guid>
		<description><![CDATA[Welcome to the next in the Becoming a Geek series. Today I'm going to cover the areas which I think a budding Game Geek needs to be adept in for him/her to be a true Game Geek. I'd like to make a clear distinction from the start that the Game Geek is a different beast [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to the next in the Becoming a Geek series. Today I'm going to cover the areas which I think a budding Game Geek needs to be adept in for him/her to be a true Game Geek. I'd like to make a clear distinction from the start that the Game Geek is a different beast to a Game <em>Development</em> Geek, and hence I won't be covering the development side in this post. I will, however, be covering the game development details in a later post in this series on the Development Geek. </p>
<p>As a general overview, a Game Geek is a geek who has strong knowledge in most areas of gaming technology, understands the bits of the computer which make games run and run <em>fast</em>, and is aware of a plethora of gaming sites which he/she can use to make sure they're up to date with what's coming out, when, and what's hot. So let's go into a bit more depth...
<ol>
<li><strong>Know your game types.</strong> There are many types of games out there, not just the standard FPS or RPG. Read up on the various categories of <a href="http://en.wikipedia.org/wiki/Video_game" title="Video Games">games</a>, and understand the differences.</li>
<li><strong>Know the guts of a game.</strong> Games are very hard to build! The developers of games are really on the cutting edge of technology and making the most of the hardware is a very difficult task from a development perspective. Read up on the major components of a game (eg. engine, graphics, artificial intelligence, physics, etc). Learn to appreciate the effort that goes into creating the worlds that you explore when you create them.</li>
<li><strong>Get involved in an online clan.</strong> Many online games allow team play, and becoming part of a regular group (or <em>clan</em>) is a good way of learning more about the game, and becoming a better team player.</li>
<li><strong>Learn the difference between fixed-function TNL, vertex shaders and pixel shaders.</strong> Back in the good old days before graphics hardware became what it is at the moment, games developers were stuck working with a <a href="http://en.wikipedia.org/wiki/Transform_and_lighting" title="Transform and Lighting">fixed-function transform and lighting (TNL)</a> pipeline. This didn't give a great deal of flexibility when outputting funky graphics. These days we have <a href="http://en.wikipedia.org/wiki/Vertex_shader" title="Vertex Shader">Vertex Shaders</a> and <a href="http://en.wikipedia.org/wiki/Pixel_shader" title="Pixel Shader">Pixel/Fragment Shaders</a> which give developers a <em>lot</em> move power and control over the end result. Figure out what it all means. Learn why the programmable shaders have had such an impact, and become familiar with the different shader model versions.</li>
<li><strong>Learn your graphics hardware.</strong> Yes, the <a href="http://en.wikipedia.org/wiki/Central_processing_unit" title="Central Processing Uni">CPU</a> is a key part of the machine when you're playing games, but arguably the most important these days is your graphics card (<a href="http://en.wikipedia.org/wiki/Graphics_processing_unit" title="Graphics Processing Unit">GPU</a>). If you're keen on staying in touch with gaming and playing the lateste and greatest, you're going to need know the capabilities of the cards. You should be able to understand what the specifications of the cards mean, and whether or not it's going to suit your needs for a given title.</li>
<li><strong>Familiarise yourself with the major graphics APIs.</strong> In short, <a href="http://en.wikipedia.org/wiki/OpenGL" title="OpenGL">OpenGL</a> and <a href="http://en.wikipedia.org/wiki/DirectX#Direct3D" title="DirectX">Direct3D</a>! Read, learn, use. You'll need to know about these when you're building your computers and making sure that your cards are compatible.</li>
<li><strong>Get a fairly beefy machine.</strong> How can you be a true Game Geek without having a large ePenis? Pimp your machine, get some kick-ass hardware, and tell everyone about it while you're mowing them down with your <a href="http://en.wikipedia.org/wiki/MG42" title="MG42">MG42</a>. A <a href="http://en.wikipedia.org/wiki/Personal_computer" title="Personal Computer">PC</a> is by far the best option for playing <a href="http://en.wikipedia.org/wiki/First-person_shooter" title="First-Person Shooter">FPS</a> games, and anyone who says otherwise is an idiot. FPS games are fun on consoles, but the level of control you get with a keyboard/mouse combination by far surpasses that which you get with a controller. <a href="http://en.wikipedia.org/wiki/Real-time_strategy" title="Real-Time Strategy">RTS</a> can also be a pain on console, so I think PC really is the best option for this kind of game too.</li>
<li><strong>Get yourself a console or two.</strong> Some games really lend themselves to playing on consoles. <a href="http://en.wikipedia.org/wiki/Role-playing_game" title="Role-Playing Game">RPG</a>, Adventure, and Sports are general categories where the console shines over the PC. Some examples of games which are much better on consoles are <a href="http://en.wikipedia.org/wiki/Pro_Evolution_Soccer" title="Pro Evolution Soccer">PES</a>, <a href="http://en.wikipedia.org/wiki/Mortal_Kombat" title="Mortal Kombat">Mortal Kombat</a>, <a href="http://en.wikipedia.org/wiki/Prince_of_Persia:_The_Sands_of_Time" title="Prince of Persia: Sands of Time">Prince of Persia: Sands of Time</a>, and <a href="http://en.wikipedia.org/wiki/Geometry_Wars" title="Geometry Wards">Geometry Wars</a>!</li>
<li><strong>Get yourself a hand-held.</strong> There many options these days ranging from the old school <a href="http://en.wikipedia.org/wiki/Game_Boy" title="Game Boy">Game Boys</a> through to the <a href="http://en.wikipedia.org/wiki/Nintendo_DS" title="Nintendo DS">NDS</a> and <a href="http://en.wikipedia.org/wiki/PlayStation_Portable" title="PlayStation Portable">PSP</a>. Mobile gaming at its best!</li>
<li><strong>Read gaming sites.</strong> Some of my personal favs are <a href="http://www.gamespy.com/" title="GameSpy">GameSpy</a>, <a href="http://www.gamesindustry.biz/" title="GamesIndustry.biz">GamesIndustry.biz</a>, <a href="http://www.ign.com/" title="IGN">IGN</a>, <a href="http://www.gt.tv/" title="GT.tv">GT.tv</a>. This will give you good coverage of what's going on, what's coming out, what's hot and what's not.</li>
<li><strong>Read some games mags.</strong> Yes, sometimes a great deal of content that you get on the web for nothing is regurgitated in mags. The good gaming mags don't do that. Get yourself a subscription to something like <a href="http://en.wikipedia.org/wiki/Atomic_(magazine)" title="AtomicMPC">AtomicMPC</a>, <a href="http://en.wikipedia.org/wiki/PC_Powerplay" title="PC Powerplay">PC Powerplay</a>, <a href="http://en.wikipedia.org/wiki/Edge_(magazine)" title="Edge">Edge</a>, or <a href="http://en.wikipedia.org/wiki/GamesTM" title="games&trade;">games&trade;</a>. You won't be disappointed.</li>
<li><strong>Get the low down on the devs/publishers.</strong> Learn about the major players such as <a href="http://www.ea.com/" title="Electronic Arts">EA</a>, <a href="http://www.valvesoftware.com/" title="Valve Software">Valve</a>, <a href="http://www.ubi.com/" title="Ubisoft">Ubisoft</a>, <a href="http://www.sierra.com/" title="Sierra Entertainment">Sierra</a>, <a href="http://www.midway.com/" title="Midway">Midway</a>, <a href="http://www.epicgames.com/" title="Epic Games">Epic</a>, etc. Learn where they fit into the big picture. Why? Because you may find that the attitude and methods of a particular company may just have an effect on which games you buy <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </li>
<li><strong>Support some indies!</strong> There are a lot of smaller game houses out there making some really funky games, but they don't get the coverage that they should because the market is swamped by titles made by the bigwigs.</li>
<li><strong>Play games.</strong> This may seem obvious, but you'd be surprised how many apparent Game Geeks don't actually play that many games. Play online, offline, single-player, multiplayer, console, hand-held, mobile phone, PC, and board games!</li>
<li><strong>Don't pirate!</strong> Gaming piracy is a huge issue. If you love games you should support the people who make them. When you consider the cost of a game these days against the level of entertainment they give you, they're actually quite cheap. Keep the industry going, and <em>pay for the games you play</em>. This is more of an issue for the smaller players who invest more in original IP than the likes of EA, because their budgets are smaller and their pockets aren't anywhere near as full.</li>
<li><strong>Don't cheat!</strong> Cheaters suck. They're losers. Just... just don't do it!</li>
</ol>
<p>There are more things you can do, but this small list should get you underway. If being a Game Geek isn't quite your thing, then perhaps you're more interested in being a Hardware Geek? If so, stay tuned - The Hardware Geek is next up in the series!</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/07/13/becoming-a-geek-part-3-the-game-geek/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Becoming a Geek Part 2: The Web Geek</title>
		<link>http://buffered.io/2007/06/22/becoming-a-geek-part-2-the-web-geek/</link>
		<comments>http://buffered.io/2007/06/22/becoming-a-geek-part-2-the-web-geek/#comments</comments>
		<pubDate>Fri, 22 Jun 2007 10:40:17 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[Being in the Industry]]></category>
		<category><![CDATA[HOWTO]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/06/22/becoming-a-geek-part-2-the-web-geek/</guid>
		<description><![CDATA[Welcome to part 2 of my Becoming a Geek series. If you haven't already read part 1, I suggest you read it first. Before you can be a web geek, you'll need to be a General Geek. If you're already on the way to becoming a General Geek, here are a stack of hints to [...]]]></description>
			<content:encoded><![CDATA[<p>Welcome to part 2 of my Becoming a Geek series. If you haven't already read part 1, I suggest you read it first. Before you can be a web geek, you'll need to be a <a href="http://buffered.io/2007/06/14/becoming-a-geek-part-1-the-general-geek/" title="Becoming a Geek Part 1: The General Geek">General Geek</a>. If you're already on the way to becoming a General Geek, here are a stack of hints to help you become a Web Geek. </p>
<p>For the record, I consider a "Web Geek" to be a geek with a heavy focus on all things <a href="http://en.wikipedia.org/wiki/World_Wide_Web" title="World Wide Web">Web</a>/<a href="http://en.wikipedia.org/wiki/Internet" title="Internet">Internet</a>. They have a strong understanding of most (if not all) areas of web and web use, good knowledge of Internet software applications and their functions, and have experience with things such as web servers, different operating systems, and web programming languages. You should be able to diagnose, debug and fix issues with internet connections, and be able to configure a router/modem. You should also have an idea of the different types of Internet connections that you can get at home. Coverage of web languages, and other technologies that support them is also key.</p>
<p>So to become the beast that is the Web Geek, all you need to do is...
<ol>
<li><strong>Know the <em>real</em> answer to the question "How do I get on the Internet?".</strong> Lots of Internet newcomers lack understanding of the Internet, and they ask questions such as this. As a Web Geek, you should know the proper answer. Most people would think the answer is "Open a web browser". Until then you're not "on" the Internet. This is totally wrong. Any computer that has a network connection which is in some way connected to the Internet physically. The Internet is more than just the Web! As you're about to find out :). So the real answer is: <em>Sign up with an <a href="http://en.wikipedia.org/wiki/Internet_service_provider" title="Internet Service Provider">ISP</a>, and get your computer physically connected. If you're computer has a network connection to the Internet, you're "on" the Internet. What you do from here is up to you, and browsing the web is but one of the options.</em></li>
<li><strong>Set up a router and modem.</strong> Get familiar with what a <a href="http://en.wikipedia.org/wiki/Router" title="Router">router</a> is, and what a <a href="http://en.wikipedia.org/wiki/Modem" title="Modem">modem</a> is, and understand what's different and why they're important. Fiddle around with them and see how they work. Set them up to work with your network and Internet connection. Learn about the protocols that lie underneath (<a href="http://en.wikipedia.org/wiki/Point-to-Point_Protocol" title="Point-to-Point Protocol">PPP</a>, <a href="http://en.wikipedia.org/wiki/Point-to-Point_Protocol_over_ATM" title="Point-to-Point Protocol over ATM">PPPoA</a>, <a href="http://en.wikipedia.org/wiki/Point-to-Point_Protocol_over_Ethernet" title="Point-to-Point Protocol over Ethernet">PPPoE</a>, etc) which allow your Internet connection to work.
</li>
<li><strong>Protocols, protocols, protocols!</strong> You don't have to know them all, and you don't have to be able to regurgitate their specifications off the top of your head, but knowing what they are and what they're used for is important. Some examples are:
<ul>
<li><a href="http://en.wikipedia.org/wiki/User_Datagram_Protocol" title="User Datagram Protocol">UDP</a>, <a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol" title="Transmission Control Protocol">TCP</a>, <a href="http://en.wikipedia.org/wiki/TELNET" title="TELNET">TELNET</a>, <a href="http://en.wikipedia.org/wiki/Secure_Shell" title="Secure Shell">SSH</a>, <a href="http://en.wikipedia.org/wiki/Trivial_File_Transfer_Protocol" title="Trivial File Transfer Protocol">TFTP</a>, <a href="http://en.wikipedia.org/wiki/File_Transfer_Protocol" title="File Transfer Protocol">FTP</a>, <a href="http://en.wikipedia.org/wiki/SSH_file_transfer_protocol" title="Secure/SSH File Transfer Protocol">SFTP</a>, <a href="http://en.wikipedia.org/wiki/Secure_Sockets_Layer" title="Secure Sockets Layer">SSL</a>, <a href="http://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol" title="Simple Mail Transfer Protocol">SMTP</a>, <a href="http://en.wikipedia.org/wiki/Post_Office_Protocol" title="Post Office Protocol">POP3</a>, <a href="http://en.wikipedia.org/wiki/Internet_Message_Access_Protocol" title="Internet Message Access Protocol">IMAP</a>, <a href="http://en.wikipedia.org/wiki/Transport_Layer_Security" title="Transport Layer Security">TLS</a>, <a href="http://en.wikipedia.org/wiki/Internet_Control_Message_Protocol" title="Internet Control Message Protocol">ICMP</a>, <a href="http://en.wikipedia.org/wiki/Simple_Network_Management_Protocol" title="Simple Network Management Protocol">SNMP</a>, <a href="http://en.wikipedia.org/wiki/Network_Time_Protocol" title="Network Time Protocol">NTP</a>, <a href="http://en.wikipedia.org/wiki/Network_News_Transfer_Protocol" title="Network News Transfer Protocol">NNTP</a>, <a href="http://en.wikipedia.org/wiki/Session_Initiation_Protocol" title="Session Initiation Protocol">SIP</a>, <a href="http://en.wikipedia.org/wiki/ECHO_protocol" title="ECHO">ECHO</a>, <a href="http://en.wikipedia.org/wiki/Domain_Name_System" title="Domain Name System">DNS</a>, <a href="http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol" title="Dynamic Host Configuration Protocol">DHCP</a>, <a href="http://en.wikipedia.org/wiki/Routing_Information_Protocol" title="Rougint Information Protocol">RIP</a> ... plus many more!</li>
</ul>
</li>
<li><strong>Know your applications.</strong> So you need to read email? Browse the web? Copy some files? Download some stuff? Find a game server? You should be familiar with at least one of each type of application that can perform each of these tasks. Get familiar with the options, some are operating system specific, others aren't. This is a massive area to cover, and the only thing that will help here is to play. A lot.
</li>
<li><strong>Get on IM.</strong> Being on and understanding the various Internet Messaging applications/protocols is very key (<a href="http://en.wikipedia.org/wiki/AOL_Instant_Messenger" title="AOL Instant Messenger">AIM</a>, <a href="http://en.wikipedia.org/wiki/Extensible_Messaging_and_Presence_Protocol" title="Jabber">Jabber (EMPP)</a>, <a href="http://en.wikipedia.org/wiki/MSN_Messenger" title="MSN Messenger">MSN</a>, etc), particularly if you plan on being in touch with many other Web Geeks. There are lots of clients that will connect to the various networks, so have a play with a few and pick the one that matches your needs the most.</li>
<li><strong>Learn your web languages.</strong> Before you jump the gun, I'm not talking about <a href="http://en.wikipedia.org/wiki/Leet" title="Leet">Leetspeak</a> or the apparent "LOL" phenomenon (lolcats, lolcode, lolgeeks, lolpresident, etc - note that I refuse to link to them). I'm talking about web programming and markup languages. Get to know them, they are you friend:
<ul>
<li><a href="http://en.wikipedia.org/wiki/Cascading_Style_Sheets" title="Cascading Style Sheets">CSS</a>, <a href="http://en.wikipedia.org/wiki/HTML" title="HTML">HTML</a>, <a href="http://en.wikipedia.org/wiki/XML" title="XML">XML</a>, <a href="http://en.wikipedia.org/wiki/XHTML" title="XHTML">XHTML</a>, <a href="http://en.wikipedia.org/wiki/PHP" title="PHP">PHP</a>, <a href="http://en.wikipedia.org/wiki/Ruby_programming_language" title="Ruby">Ruby</a>, <a href="http://en.wikipedia.org/wiki/C_Sharp" title="C#">C#</a>, <a href="http://en.wikipedia.org/wiki/Java_(programming_language)" title="Java">Java</a>, <a href="http://en.wikipedia.org/wiki/JavaScript" title="JavaScript">JavaScript</a>, <a href="http://en.wikipedia.org/wiki/Python_(programming_language)" title="Python">Python</a>, <a href="http://en.wikipedia.org/wiki/Perl" title="Perl">Perl</a> ... and lots, <em>lots</em> more.</li>
</ul>
</li>
<li><strong>Know that browsers aren't the same.</strong> All of the major browsers <a href="http://en.wikipedia.org/wiki/Mozilla_Firefox" title="Firefox">Firefox</a>, <a href="http://en.wikipedia.org/wiki/Internet_Explorer" title="Internet Explorer">IE</a>, <a href="http://en.wikipedia.org/wiki/Safari_(web_browser)" title="Safari">Safari</a>, etc) behave differently. When you make websites, or browse websites, you'll get to know how different they actually are. So, if the site you're reading looks funny, give another browser a spin. If you're writing your own site, make sure you test your site in as many browsers as possible.</li>
<li><strong>Play with the servers.</strong> It'd be a good idea to get familiar with the well-known (<a href="http://en.wikipedia.org/wiki/Apache_HTTP_Server" title="Apache">Apache</a>, <a href="http://en.wikipedia.org/wiki/Internet_Information_Services" title="IIS">IIS</a>, etc) and the not-so-well-known (<a href="http://en.wikipedia.org/wiki/LiteSpeed_Web_Server" title="Litespeed">Litespeed</a>, <a href="http://en.wikipedia.org/wiki/Lighttpd" title="LightTPD">LightTPD</a>, etc) web servers. Learn about their pros and cons. Get familiar with their characteristics - particularly those that focus on extensibility, security, speed, resource usage and portability.</li>
<li><strong>Learn what a webserver machine really is.</strong> A webserver isn't a machine that just dishes out web content. It has a stack of software installed on it including (but not limited to) web content servers, database servers, mail servers, DNS servers, spam filters, caching mechanisms, load balancers, etc. Get intimate with the meaning of each of these applications, make sure you know why they exist, what they're for, and which ones you should be using!</li>
<li><strong>Use the command line.</strong> If you're doing any administration of a web server then you're probably going to have to get used to dealing with the command line (especially if the system is remote). Get familiar with your web server operating system, and learn about how to manipulate your applications. It's a long, hard road but well worth the effort.</li>
<li><strong>Put special time aside to get familiar with web security.</strong> Read some <a href="http://www.amazon.com/Tangled-Web-Digital-Shadows-Cyberspace/dp/078972443X" title="Tangled Web">interesting stories</a> on cyber crime, learn how the pros managed to pull off the jobs they did, find out what the flaws of the systems were, learn why systems are vulnerable. The idea is to get familiar with the massively broad range of methods that attackers can use to break into or bring down your computer. The best way to make your system secure is to understand how the "bad" guys work <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> While you're there, read up on how the good guys have faught back! Get yourself some knowledge that crosses the <a href="http://www.amazon.co.uk/Crypto-Secrecy-Privacy-New-Code/dp/0713993464" title="Crypto">history of information security</a>. You might think it's not important, but it is!</li>
<li><strong>Read a lot of web stuff.</strong> You should be an avid subscriber to RSS feeds. Focus on web design, web standards, web development, accessibility, web technologies, languages, and security.</li>
<li><strong>Know how to search properly.</strong> Searching is more than just pumping a few words into a search engine. Get to know a few different engines, and find the ones that are specific to the kind of content that you're interested in. Practice with different search terms. For a hint, check out my <a href="http://buffered.io/2007/04/28/the-art-of-googling/" title="The Art of Googling">earlier post on searching</a>.</li>
</ol>
<p>Again, this is only covering the basics of what it would take to become (what I consider) a Web Geek. The big-wigs in the web world know all this and more, so if this is what you're aiming for, best get going, there's a lot to do <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> </p>
<p>Next up, I'll be covering the Game Geek!</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/06/22/becoming-a-geek-part-2-the-web-geek/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Becoming a Geek Part 1: The General Geek</title>
		<link>http://buffered.io/2007/06/14/becoming-a-geek-part-1-the-general-geek/</link>
		<comments>http://buffered.io/2007/06/14/becoming-a-geek-part-1-the-general-geek/#comments</comments>
		<pubDate>Thu, 14 Jun 2007 07:14:38 +0000</pubDate>
		<dc:creator>OJ</dc:creator>
				<category><![CDATA[Being in the Industry]]></category>
		<category><![CDATA[HOWTO]]></category>

		<guid isPermaLink="false">http://buffered.io/2007/06/14/becoming-a-geek-part-1-the-general-geek/</guid>
		<description><![CDATA[Contrary to popular belief, there are many types of geek. In this series, I'm going to give some basic tips on how to become one! This is the first part in the series, and so I'm covering the 'General Geek'. Before I even went to university to get qualifications to become an official "paid" geek, [...]]]></description>
			<content:encoded><![CDATA[<p>Contrary to popular belief, there are many types of geek. In this series, I'm going to give some basic tips on how to become one!  This is the first part in the series, and so I'm covering the 'General Geek'.</p>
<p>Before I even went to university to get qualifications to become an official "paid" geek, I put a great deal of time and effort into tuning my skills in other areas that would help me excel at my job. Below is a list of things that I did which I believe really helped me achieve my goal, and I would recommend doing the same if you're looking to become a paid geek yourself! </p>
<ol>
<li><strong>Learn to touch-type.</strong> When I say touch-type, what I mean is "typing without having to look at the keyboard for <em>any</em> reason". Fast typing while looking at the keyboard doesn't count <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_wink.png' alt=';)' class='wp-smiley' /> Get yourself a typing tutor and invest half an hour per day for a few months. Before you know it, you'll be setting the keyboard on fire. (<em>Hint: if you can't stop looking at the keys, put a tea-towel over your hands and keyboard!</em>)</li>
<li><strong>Learn an operating system (or two).</strong> It doesn't matter which one it is, but it's probably a good idea to go for the one that you plan to work with. I'm sure we've all had our fair share of meetings with people who consider themselves to be computer literate, and yet they struggle with basic file management tasks. Using a computer during the day does <em>not</em> make you computer literate. Do yourself a favour, get down and dirty with your OS, and learn how to:
<ul>
<li>... install the OS from scratch.</li>
<li>... manage files.</li>
<li>... manage disks.</li>
<li>... install/uninstall applications.</li>
<li>... upgrade and patch your OS.</li>
<li>... add/remove users.</li>
<li>... write files to DVD/CD.</li>
<li>... rip albums to a music player.</li>
<li>... move around applications in general (ie. get used to common menu items, and where to find them)</li>
<li>... etc</li>
</ul>
<p>Getting this kind of knowledge puts you ahead of a surprising amount of people! It's also a good idea to get an idea of the different operating systems that are avialable, as you'll never know when you might be thrown in front of one of them!</li>
<li><strong>Learn your hardware.</strong> By this I don't mean that you need to be able to recite tech specs as they would appear on <a href="http://www.tomshardware.com/" title="Tom's Hardware">Tom's Hardware</a>. What I mean is learn what your computer is made of (<a href="http://en.wikipedia.org/wiki/Motherboard" title="Motherboard">motherboard</a>, <a href="http://en.wikipedia.org/wiki/Random_access_memory" title="Random Access Memory">RAM</a>, <a href="http://en.wikipedia.org/wiki/Central_processing_unit" title="Central Processing Unit">CPU</a>, etc). Determine the function of each of the bits, and the affect that they all have on your system. Understand what it means to upgrade something (eg. add more RAM) and how that will affect your computing experience.</li>
<li><strong>Set up a home network.</strong> This will give you the grounding that you'll need to understand the basics of networking (<a href="http://en.wikipedia.org/wiki/List_of_network_protocols" title="List of Networking Protocols">networking protocols</a>, <a href="http://en.wikipedia.org/wiki/List_of_network_protocols" title="IP Address">IP addresses</a>, <a href="http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol" title="Dynamic Host Configuration Protocol">DHCP</a>, etc). This is particularly handy for anyone who is going to build web applications, or spend a lot of time in a networked environment.</li>
<li><strong>Learn about the web.</strong> Find out what that '<a href="http://en.wikipedia.org/wiki/HTTP" title="HTTP">http</a>' thing means, and figure out the difference between that and '<a href="http://en.wikipedia.org/wiki/HTTPS" title="HTTPS">https</a>'. Get a basic idea of what happens when you click on a link in your browser. Understand the stages that the whole process goes through from the point you've pressed the mouse button to the point where you've got a fully loaded page on screen.</li>
<li><strong>Get familiar with a programming language.</strong> This is obviously geared towards the potential coders out there. If you're going to learn to write software, then you're better off playing with one or two languages before you start any formal work or training.</li>
<li><strong>Speak to some geeks.</strong> Jump on some online forums. Read some blogs. Communicate with the geek community. Learn from their mistakes!</li>
<li><strong>Make your own mistakes.</strong> This is by far the best way to learn. If things just work first-time/every-time you'll miss out. There's no better way to learn how something works than fixing it when it's broken!</li>
<li><strong>Stay in touch.</strong> Make sure you keep up to speed with tech, by reading news and RSS feeds (such as <a href="http://www.engadget.com/" title="Engadget">Engadget</a> and <a href="http://www.slashdot.org/" title="/.">Slashdot</a>).</li>
<li><strong>Give something back</strong> Write a blog yourself. Write a tutorial. Help people on forums on topics that you've struggled with. This will force you to make sure you know what it is you're talking about <img src='http://buffered.io/wp-content/plugins/smilies-themer/Silk/emoticon_smile.png' alt=':)' class='wp-smiley' /> It's also very rewarding.</li>
</ol>
<p>Do you guys have any other suggestions?</p>
]]></content:encoded>
			<wfw:commentRss>http://buffered.io/2007/06/14/becoming-a-geek-part-1-the-general-geek/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
