<?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>Daniel Hall&#039;s Website &#187; Programming</title>
	<atom:link href="http://www.danielhall.me/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.danielhall.me</link>
	<description>Because the Internet doesn&#039;t have enough opinions already</description>
	<lastBuildDate>Thu, 29 Jul 2010 11:52:51 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
<atom:link rel="hub" href="http://pubsubhubbub.appspot.com"/><atom:link rel="hub" href="http://superfeedr.com/hubbub"/>		<item>
		<title>Programming In Javascript</title>
		<link>http://www.danielhall.me/2010/07/programming-in-javascript/</link>
		<comments>http://www.danielhall.me/2010/07/programming-in-javascript/#comments</comments>
		<pubDate>Thu, 29 Jul 2010 11:48:36 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Web Programming]]></category>
		<category><![CDATA[Chrome]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[Internet Explorer]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[JScript]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Safari]]></category>
		<category><![CDATA[WebKit]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=657</guid>
		<description><![CDATA[<p>Javascript is an interesting language. Its partly a functional programming language and part object oriented. It uses a C style syntax but borrows its naming conventions from Java (mostly). Personally I find Javascript language to be one of the most interesting languages that I have played with. The complaints I hear most often regarding Javascript [...]]]></description>
			<content:encoded><![CDATA[<p>Javascript is an interesting language. Its partly a functional programming language and part object oriented. It uses a C style syntax but borrows its naming conventions from Java (mostly). Personally I find Javascript language to be one of the most interesting languages that I have played with. The complaints I hear most often regarding Javascript are that it is very hard to learn and that there are many subtle differences between the interpreters.</p>
<h2>Difficult to learn</h2>
<p>This used to be mostly true. Javascript was a poorly documented language, often only documented in tutorial form by w3schools, or technically documented as ECMAScript. The absolute wealth of tutorials and blog posts made the good information few and far between. Largely when looking for information on how to perform a particular function you had to download some sample code and figure out how it was done based on that.</p>
<p>More recently though Javascript has caught the wave that is trying to standardize the web and this has somewhat improved the situation. Browser manufacturers are documenting their Javascript implementations and largely converging on a common standard. Additionally many helper libraries have been introduced to make the task of working on Javascript even easier. Once Javascript may have been difficult to learn, but as of late this is no longer true.</p>
<p>Javascript Documentation:</p>
<ul>
<li><a href="https://developer.mozilla.org/en/javascript">Mozilla Developer Center &#8211; Javascript</a></li>
<li><a href="http://developer.apple.com/safari/library/documentation/AppleApplications/Reference/WebKitDOMRef/index.html">WebKit DOM Reference</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/yek4tbz0%28VS.85%29.aspx">MSDN &#8211; JScript Language Reference</a></li>
<li><a href="http://dev.opera.com/libraries/">Opera Libraries</a></li>
</ul>
<h2>Subtle differences in interpretation</h2>
<p>This is is one of the biggest problems you still see in Javascript today. You will often find developers writing functions to simply deal with the differences between browsers, there are even entire libraries dedicate to to abstracting away the differences. If I had a dollar for every implementation of a function to get a XMLHttpRequest object across browsers, I wouldn&#8217;t need my job.</p>
<p>﻿﻿﻿﻿﻿Unfortunately it is still however very important to know the differences between implementations of Javascript if you plan on writing anything that will run on more than one browser. These difference may be in the features available in the language, in the Document Object Model or in the way the browser handles CSS. Thankfully many people work on documenting the difference and abstracting around them in libraries.</p>
<p>Javascript Implementations Differences:</p>
<ul>
<li><a href="http://quirksmode.org/">Quirks Mode</a></li>
<li><a href="https://developer.mozilla.org/en/Migrate_apps_from_Internet_Explorer_to_Mozilla">Browser Migration &#8211; MDN</a></li>
<li><a href="http://www.webdevout.net/browser-support-css">Web Browser CSS Support</a></li>
</ul>
<p>Javascript Libraries:</p>
<ul>
<li><a href="http://dojotoolkit.org/">DOJO ToolKit</a></li>
<li><a href="http://www.prototypejs.org/">Prototype</a></li>
<li><a href="http://jquery.com/">jQuery</a></li>
<li><a href="http://script.aculo.us/">script.aculo.us</a></li>
<li><a href="http://miniajax.com/">MiniAJAX</a></li>
</ul>
<p><b>Random Thought:</b> If only Facebook didn&#8217;t get in the way of Javascript all the time&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2010/07/programming-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Writing a Daemon in C</title>
		<link>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/</link>
		<comments>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/#comments</comments>
		<pubDate>Fri, 01 Jan 2010 12:14:35 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Daemon]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Unix]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=466</guid>
		<description><![CDATA[What is a Daemon?
<p>A daemon is a program that runs in the background. A daemon will usually be started at system startup and end at system shutdown. The exceptions to this rule are programs like the Bluetooth SDP daemon, which is activated when a new Bluetooth HCI is found,, and ends when it is removed. [...]]]></description>
			<content:encoded><![CDATA[<h2>What is a Daemon?</h2>
<p>A daemon is a program that runs in the background. A daemon will usually be started at system startup and end at system shutdown. The exceptions to this rule are programs like the Bluetooth SDP daemon, which is activated when a new Bluetooth HCI is found,, and ends when it is removed. Daemons run transparently and do not normally interact with the user directly.</p>
<p>Daemons start as ordinary processes but they eventually &#8216;fork and die&#8217; to start running in the background. Some daemons do only the &#8216;fork and die&#8217; step but ignore other important steps. Here is a list of what a daemon should do:</p>
<ol>
<li>Fork to create a child, and exit the parent process.</li>
<li>Change the umask so that we aren&#8217;t relying on the one set in the parent.</li>
<li>Open logs to write to in the case of an error.</li>
<li>Create a new session id and detach from the current session.</li>
<li>Change the working directory to somewhere that won&#8217;t get unmounted.</li>
<li>Close STDIN, STDOUT and STDERR.</li>
</ol>
<p>These steps ensure that our association with the calling environment is destroyed and our daemon is now free to run as a completely separate process.</p>
<p>Lastly before writing the daemon you should make sure the code is written securely and in a way that fails gracefully. If your daemon crashes it will not be able to prompt the user about what action to take. The user may not even notice until it is too late.</p>
<h2>Forking a child process</h2>
<p>In Unix fork() is the only system call with two return values. When you call fork a child process is created which is a near copy of its parent (some things will be different in the child eg. process id). The fork command then returns a 0 in the child and the childs process id in the parent, on failure a -1 is sent to the parent. Generally a program will then check whether it is the child or parent by these return values (just like in movies when a cloned character will check to see if he has a belly button and hence is the original). Here is a snippet of code to do this:</p>
<pre class="brush: cpp;">
pid_t pid;

/* Clone ourselves to make a child */
pid = fork(); 

/* If the pid is less than zero,
   something went wrong when forking */
if (pid &lt; 0) {
    exit(EXIT_FAILURE);
}

/* If the pid we got back was greater
   than zero, then the clone was
   successful and we are the parent. */
if (pid &gt; 0) {
    exit(EXIT_SUCCESS);
}

/* If execution reaches this point we are the child */
</pre>
<h2>Changing the umask</h2>
<p>Because we are a clone of our parent we&#8217;ve inherited its umask. This means the child doesn&#8217;t know what permissions files will end up with when it tries to create them. We do this by simply calling umask like this:</p>
<pre class="brush: cpp;">
/* Set the umask to zero */
umask(0);
</pre>
<h2>Open logs to write to</h2>
<p>This part can be done in several different ways. You could open text files, log to a database or use syslog. The method I&#8217;m going to demonstrate here is to log using syslog. Syslog sends your log messages to a system wide logger, where they can be configured to be written to a file, send to a network server or filtered away entirely.</p>
<pre class="brush: cpp;">
/* Open a connection to the syslog server */
openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER); 

/* Sends a message to the syslog daemon */
syslog(LOG_NOTICE, &quot;Successfully started daemon\n&quot;); 

/* this is optional and only needs to be done when your daemon exits */
closelog();
</pre>
<h2>Create a new session id</h2>
<p>Each process on a Unix system is a member of a process group (or session). The id of each group is the process id of its owner. When we forked from our parent earlier we will have inherited its process group, and our process group leader will still be its parent process. We want to create our own process group and become our own process leader otherwise we will look like an orphan. We can do this easily as follows:</p>
<pre class="brush: cpp;">
pid_t sid;

/* Try to create our own process group */
sid = setsid();
if (sid &lt; 0) {
    syslog(LOG_ERR, &quot;Could not create process group\n&quot;);
    exit(EXIT_FAILURE);
}
</pre>
<h2>Changing the working directory</h2>
<p>At the moment we have the working directory we inherited from our parent. This working directory could be a network mount, a removable drive or somewhere the administrator may want to unmount at some point. To unmount any of these the system will have to kill any processes still using them, which would be unfortunate for our daemon. For this reason we set our working directory to the root directory, which we are sure will always exist and can&#8217;t be unmounted.</p>
<pre class="brush: cpp;">
/* Change the current working directory */
if ((chdir(&quot;/&quot;)) &lt; 0) {
    syslog(LOG_ERR, &quot;Could not change working directory to /\n&quot;);
    exit(EXIT_FAILURE);
}
</pre>
<h2>Closing the standard file descriptors</h2>
<p>A daemon doesn&#8217;t interact with the user directly it has no use for STDIN, STDOUT and STDERR and we really have no idea where these are connected or where anything we write to them will end up. As these file descriptors are not required and effectively useless we should close them to save some system resources and prevent any related security problems. We close these descriptors like this:</p>
<pre class="brush: cpp;">
/* Close the standard file descriptors */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
</pre>
<h2>Writing the payload</h2>
<p>Now you have a C program that is capable of becoming a daemon, but its a pretty useless daemon if it exits immediately. Payload code is really up to you to design. I&#8217;ll offer you a few tips on designing your payload.</p>
<ul>
<li>Put your payload in a loop. Generally in a daemon you want to perform the same action over and over again until you&#8217;re killed. If you have to cleanup (such as closing syslog) when the daemon is about to be killed you should add an exit clause that will be activated by a SIGTERM signal handler.</li>
<li>Make your code as fast an efficient as possible. This is something you should do with any program, but with daemons it is important that you do not hamper the performance of the rest of the system. This is especially true if you&#8217;re going to be running this daemon on desktop systems.</li>
<li>Be aware that your code may be preempted very often. As your daemon is going to be running for the amount of time the system is up, it is likely that its execution will be preempted.</li>
<li>Be paranoid about security. Daemons are common attack vectors and can be used to gain privileged access to a system. You should consider dropping any privileges that you don&#8217;t require.</li>
</ul>
<h2>Conclusion</h2>
<p>So if we take all the code I&#8217;ve mentioned in this post and put it all together you have a simple daemon. You can download the source from the link here: <a href='http://www.danielhall.me/wp-content/uploads/2010/01/daemon.c'>daemon.c</a>.<br />
If your daemon is only going to be run on Linux and not on a System V style system such as Solaris you can use the <a href="http://www.manpagez.com/man/3/daemon/">daemon</a> function to do a lot of this work for you.</p>
<h2>References</h2>
<p><a href="http://www.netzmafia.de/skripten/unix/linux-daemon-howto.html">Linux Daemon Writing HOWTO in C</a><br />
<a href="http://blog.emptycrate.com/node/219">Linux Daemon writing in C++</a></p>
<p><strong>Random Thought:</strong> It appears the <a href="http://objectiveministries.org/creation/propaganda.html#">devil uses a Unix</a> based OS, probably OSX.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2010/01/writing-a-daemon-in-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Paramaterized Java Classes</title>
		<link>http://www.danielhall.me/2009/10/paramaterized-java-classes/</link>
		<comments>http://www.danielhall.me/2009/10/paramaterized-java-classes/#comments</comments>
		<pubDate>Sat, 03 Oct 2009 03:01:22 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[HOWTO]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Type Safety]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=364</guid>
		<description><![CDATA[<p>One of the biggest features of Java 1.5 was generics. In particular all the collection classes had been extended to use parametrized classes. Normally the collection classes accepted and returned Objects which is the class all other Java classes descend from. Unfortunately this meant that you had to cast everything you got back out of [...]]]></description>
			<content:encoded><![CDATA[<p>One of the biggest features of Java 1.5 was generics. In particular all the collection classes had been extended to use parametrized classes. Normally the collection classes accepted and returned Objects which is the class all other Java classes descend from. Unfortunately this meant that you had to cast everything you got back out of a collection to what you expected it to be. and until you did you would only be able to call methods that were provided by Object. You also had to be ready to catch an exception in case the class could not be cast because it was the wrong object.</p>
<p>Generics and parametrized classes allow Java programmers to place a type on a class and have that type inherited by its methods. For example you can now declare an ArrayList class with a type String. This alters the ArrayList class so that its add method now only accepts objects of type String, the get method now also returns objects of type String. This makes everything type safe which means you don&#8217;t have to cast anything and your code won&#8217;t compile if you try to put something in the ArrayList that doesn&#8217;t match its class.</p>
<p>Java uses parametrized classes to build its collections and you&#8217;ll want to use them too if you&#8217;re making your own collection class. For example if you were implementing a stack, a queue or a multi-priority FIFO queue are good cases for parametrized classes. Be careful though of the lure parametrized classes can have. They are not a replacement for polymorphism and shouldn&#8217;t be used when polymorphism would make more sense. For example if your multi-priority queue gets the priority out of the object itself then you&#8217;d need an interface that provides a method to get the priority. Then your class will only be able to accept items that implement that interface, which makes sense in this case as we need to priority to be able to store it.</p>
<p>A parametrized class is really simple to use. Here is an example implementation of a stack collection backed by an ArrayList:</p>
<pre class="brush: java;">import java.util.ArrayList;
import java.util.Collection;

/**
 * This class acts as a stack. Items can be 'pushed' which adds them to the top
 * of the stack. items can also be 'popped' which removes and returns the top
 * item on the stack and removes it. This means only the most recently added
 * item is available at the current time. To get to older items you need to
 * first remove the others.
 *
 * Note: Java already has a stack object that should probably be used in
 *       preference to this one. This is only an example implementation.
 *
 * @author Daniel Hall &lt;daniel@danielhall.me&gt;
 *
 * @param &lt;T&gt; The type of items that can be stored in the Stack.
 */
public class Stack&lt;T&gt; {
	/* Uses the same type as this class to store the items */
	private ArrayList&lt;T&gt; array = new ArrayList&lt;T&gt;();

	/**
	 * Creates a Stack containing items already in a collection. The collection
	 * must have the same parameterized type as this class to ensure that we get
	 * the right objects.
	 * @param c The Collection to initialize with
	 */
	public Stack(Collection&lt;T&gt; c) {
		array.addAll(c);
	}

	/**
	 * Creates an empty Stack object
	 */
	public Stack() {

	}

	/**
	 * Adds an item to the top of the stack.
	 * @param item The item which will be added to the top of the stack.
	 */
	public void push(T item) {
		array.add(item);
	}

	/**
	 * Removes the first item from the stack
	 * @return The item that was on the top of the stack.
	 */
	public T pop() {
		/* This gets the size so we don't have to do it twice. */
		int count = array.size();

		/* If the stack is empty return null, note that the Java implementation
		 * of stack throws an Exception instead.
		 */
		if (count == 0) {
			return null;
		}

		/* Remove the last added object (which will have index count - 1) */
		return array.remove(count - 1);
	}
}</pre>
<p><strong>Random thought: </strong><a href="http://www.cse.unsw.edu.au/JohnLions/">John Lions</a> wrote a book about the Unix source code, in the seventies, which because it also included some code, was blocked from being published until 1996.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/10/paramaterized-java-classes/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Cryptographically Secure Random Numbers in Java</title>
		<link>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/</link>
		<comments>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/#comments</comments>
		<pubDate>Tue, 29 Sep 2009 20:58:06 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Java]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Security]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=367</guid>
		<description><![CDATA[The Random Class
<p>Most people wanting to generate random numbers in Java do something similar to the following:</p>
public static void main(String[] args) {
  Random generator = new Random();
  int randomnumber = generator.nextInt(5) + 1;
  System.out.println(&#34;Dice rolled: &#34; + randomnumber);
}
<p>This is perfectly fine for a simple dice rolling application where there isn&#8217;t going to [...]]]></description>
			<content:encoded><![CDATA[<h1>The Random Class</h1>
<p>Most people wanting to generate random numbers in Java do something similar to the following:</p>
<pre class="brush: java;">public static void main(String[] args) {
  Random generator = new Random();
  int randomnumber = generator.nextInt(5) + 1;
  System.out.println(&quot;Dice rolled: &quot; + randomnumber);
}</pre>
<p>This is perfectly fine for a simple dice rolling application where there isn&#8217;t going to be much effort put into cracking it. For example in this application the only real reason you would bother cracking it would be to show off a neat party trick to your geeky friends. No doubt though the effort wouldn&#8217;t be worth it.</p>
<p>Java states that the Random class and its subclasses must produce predictable results when seeded with the same data. This however is not why this is insecure, and it is useful when testing. The reason that this class is predictable though is the way in which it is seeded. The Random class, in the absence of a seed in its constructor it will seed its random number generator with the current time in milliseconds. This means that if somebody knows the time that the Random object was seeded and has several consecutive bytes of output then they can reasonably predict the next numbers. Once somebody has discovered the seed for the generator all number produced from it can be seen as compromised.</p>
<h1>The SecureRandom Class</h1>
<p>The SecureRandom class is different, it again uses algorithms that when seeded will produce predictable results, but the algorithm is much more complex. It uses a digest algorithm such as SHA-1 on the seed and a counter to generate random data. SHA-1 is much more costly than the simple algorithm used in the Random class and as such it is much harder to brute force.</p>
<p>Its true strength however lies in the method in which it is seeded. The SecureRandom class is seeded using true random data gathered by the operating system. This is data gathered by the OS from sources of true randomisation, such as mouse movements, network packet arrival times, IO statistics and interrupts. On Linux the data is gathered from /dev/random and on Windows via the CryptGenRandom() call in Windows.</p>
<p>When using SecureRandom though you should be aware of a few things:</p>
<ul>
<li>The more random numbers some can get a hold of the more likely they can figure out the seed. You should either throw away the SecureRandom object every now and then or reseed it. Keeping in mind the next point though.</li>
<li>The seeding the generator takes entropy out of the system, if it cannot get any entropy it will block until the system has some. This means if you&#8217;re reseeding the generator too often your program will hang along with anything else on the system requiring entropy.</li>
<li>Don&#8217;t seed the SecureRandom class yourself, unless you are 100% absolutely sure you are seeding it with purely random data, or you are testing and need repeatable results. Whatever you do, don&#8217;t let your testing code leak into a production system.</li>
</ul>
<h1>How to decide</h1>
<p>Generally when you&#8217;re coding you don&#8217;t need secure random numbers. For example if you&#8217;re writing a number guessing game, or a quiz generating program then high quality random numbers aren&#8217;t required. It should be noted though that if money is involved people will often go to greater lengths and a more secure generator will be required, such as in a slot machine.</p>
<p>Again generally if what you are generating is a security token of some sort then you will need a secure generator. For example a session id, a one time password or an encryption key. The exception here is a salt for a password, salts can be generated using predictable entropy sources, even a simple time stamp would work here (especially if your also storing the time stamp to measure password expiry).</p>
<p><strong>Random Thought:</strong> For those of you who don&#8217;t know <a href="http://en.wikipedia.org/wiki/Bruce_Schneier">Bruce Schneier</a> is the <a href="http://www.schneierfacts.com/">Chuck Norris</a> of cryptography.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/09/cryptographically-secure-random-numbers-in-java/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C++ Internal Classes</title>
		<link>http://www.danielhall.me/2009/08/c-internal-classes/</link>
		<comments>http://www.danielhall.me/2009/08/c-internal-classes/#comments</comments>
		<pubDate>Wed, 26 Aug 2009 03:16:49 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[C/C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[OOP]]></category>
		<category><![CDATA[Programming]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=266</guid>
		<description><![CDATA[<p>C++, like Java, allows you to have internal classes. You can implement them by simply including the class in the .cpp file and not in the header file. Yep, its that simple. If you try this you will probably realise that you cant include the class as a data member. This is because when you [...]]]></description>
			<content:encoded><![CDATA[<p>C++, like Java, allows you to have internal classes. You can implement them by simply including the class in the .cpp file and not in the header file. Yep, its that simple. If you try this you will probably realise that you cant include the class as a data member. This is because when you try to include it in the class the internal class hasn&#8217;t been declared yet. That&#8217;s easy to fix, you can prototype a class by simply adding class ClassName;. Why am I telling you this? Because its an interesting design pattern, and that inner class is called a &#8220;Cheshire Class&#8221;.</p>
<p>The Cheshire Class is a hidden internal class. This doesn&#8217;t immediately sound useful, until you think about how C++ handles private variables. When you add a private variable to a class, even though it is not visible to the calling application, it still affects the structure of the class and hence all the code that links against it will need to be recompiled. The Cheshire class prevents this by keeping all your private variables in a private internal class. See this Example:</p>
<h1>outerclass.h</h1>
<pre lang="c++">#ifndef OUTERCLASS_H_
#define OUTERCLASS_H_

class InnerClass;

class OuterClass {
private:
  InnerClass *internal;
public:
  OuterClass();
  virtual ~OuterClass();
};

#endif /* OUTERCLASS_H_ */</pre>
<h1>outerclass.cpp</h1>
<pre lang="c++">class InnerClass {
public:
  int privateVariable;
};</pre>
<pre>OuterClass::OuterClass() {
  internal.privateVariable = 0;
}

OuterClass::~OuterClass() {

}</pre>
<p>Now instead of adding new private data to the outer class, you add it to the inner class. This way your header stays the exact same, the data structure never changes.</p>
<p>Note that this does take up more space, and takes a little longer to resolve because it has to jump via and extra pointer but sometimes it is worth it for that nicer solution.<br />
<strong>Random Thought:</strong> Which is more valuable, bread or gold? Why? Which is more useful?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/08/c-internal-classes/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Pet Projects</title>
		<link>http://www.danielhall.me/2009/08/pet-projects/</link>
		<comments>http://www.danielhall.me/2009/08/pet-projects/#comments</comments>
		<pubDate>Tue, 18 Aug 2009 23:57:13 +0000</pubDate>
		<dc:creator>Daniel</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Career]]></category>
		<category><![CDATA[Linux]]></category>

		<guid isPermaLink="false">http://www.danielhall.me/?p=253</guid>
		<description><![CDATA[<p>One thing I&#8217;ve observed of people around me who are extremely passionate about computers is that they all have pet projects. For some its their work on an open source project, some maintain distribution packages, others run useful websites and some even attempt to found companies. I&#8217;ve had a few pet projects through my years.</p>
<p>Early [...]]]></description>
			<content:encoded><![CDATA[<p>One thing I&#8217;ve observed of people around me who are extremely passionate about computers is that they all have pet projects. For some its their work on an open source project, some maintain distribution packages, others run useful websites and some even attempt to found companies. I&#8217;ve had a few pet projects through my years.</p>
<p>Early in my high school education I discovered Microsoft Visual Basic 6.0. This was my original programming language and where I learnt the basis of my programming skills. Using Visual Basic I wrote many programs, some useful some utterly useless. I remember writing a chat program, a scrabble optimiser, a remote PC control application and several games. Unfortunately an over zealous system administrator saw many executables in my home directory and decided I had been infected by a virus and wiped the whole directory. Unfortunately as much as I protested and complained the files were never restored and they are all lost forever.</p>
<p>As I was completing my high school years I ran a web game with two fellow classmates of mine. We spend most of the second half of the year designing it and I spent my exam period implementing it. We managed to keep it running for a year until we ran out of funds (we were all studying) to support it. The game had several limitations and some major design flaws. I&#8217;ve entertained thoughts of setting it up once again many times, but ultimately without my two partners (one of who I&#8217;ve lost touch with) it would never work. In addition all copies of the original source code have been lost.</p>
<p>Now we come to my favourite project of all. <a href="http://www.danielhall.me/WeatherMon">WeatherMon</a> was written for my Dad. He had bought a weather station that had a PC link and this enabled me to get the data into our server. Not only is <a href="http://www.danielhall.me/WeatherMon">WeatherMon</a>&#8216;s source code still available it is still running to this day. It was also my first foray into AJAX and XML. WeatherMon does not reload the page at all, and all data transferred is either images or XML. I&#8217;ve got a write up all about it <a href="http://www.danielhall.me/projects/about-weathermon/">here</a>.</p>
<p>Finally, it began as a school assignment but I took it way too far. Originally I had implemented it as a web service, which I then extended to a website, then I made the XHTML so that it could easily be themed and finally I implemented several themes. You can read about converter <a href="http://www.danielhall.me/projects/about-converter/">here</a>.</p>
<p>I think pet projects are what differentiates the passionate from the crowd. Anybody can write programs, and anybody can go to work and do it there. It takes the right person to want to toil outside hours on something that isn&#8217;t earning them any money. I think the best thing you can do to further your abilities and your career is to start a pet project. It doesn&#8217;t have to be thankless, or useless but that doesn&#8217;t mean it can&#8217;t be. Its easy, submit a patch to an open source project, become a maintainer for a project lacking development, fork a project, start a website or even start your own open source project.</p>
<p><strong>Random Thought:</strong> How tasty is the definitive <a href="http://recipes.wikia.com/wiki/Tomato_sauce">Open Sauce</a>?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.danielhall.me/2009/08/pet-projects/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>
