<?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>Entertaining Code &#187; Learning</title>
	<atom:link href="http://www.entertainingcode.com/tags/learning/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.entertainingcode.com</link>
	<description>Coding and the games industry</description>
	<lastBuildDate>Mon, 28 Jun 2010 16:56:33 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Black Box Black Box Testing</title>
		<link>http://www.entertainingcode.com/archives/black-box-black-box-testing/</link>
		<comments>http://www.entertainingcode.com/archives/black-box-black-box-testing/#comments</comments>
		<pubDate>Thu, 17 Sep 2009 14:29:32 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Debugging]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Testing]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=934</guid>
		<description><![CDATA[One of my friends is in College, and is currently feeli [...]]]></description>
			<content:encoded><![CDATA[<p>One of my friends is in College, and is currently feeling the full idiocy of a system that was only beginning to be rolled out as I left. Let me explain how it works.</p>
<p>Essentially, <a href="https://kattis.csc.kth.se/about">the system</a> is meant to test the students&#8217; solutions to homework problems. This is done by providing a solid definition of what the input and output of the application are supposed to be on the standard in/out channels, and setting up a whole bunch of test cases, including a memory limit and a CPU time limit. Students submit their source code to the system, which compiles it and runs all the test cases against the application in a black box test. So far, so good.</p>
<p>Seeing these guys at work, compared to me and my colleagues at work, makes a few things very apparent: even with a fairly solid grasp of algorithms and datastructure, their number one problem is code. Where professional programmers swim through code like sharks in the sea, the students appear to be more or less drowning. Theoretical learning aside, the education lacks practical programming, debugging, practical programming and some more practical programming.</p>
<p>It would seem that these programming exercises would be the perfect opportunity to get that kind of experience, if it wasn&#8217;t for the fact that the test system is itself a black box. You put in your code, and it tells you yes or no. It&#8217;s not quite a boolean pass/fail answer, but close enough: you will get told a result from the set: Didn&#8217;t compile, Passed, Failed, Crashed, Time Limit Exceeded. When I first heard of the system, it was motivated with the fact that sometimes in professional programming, that&#8217;s all you get.</p>
<p>I agree. Sometimes, you get gnarly bugs that give you less information than a world pro&#8217;s poker face. I&#8217;ve spent weeks tracking bugs like that sometimes, using all kinds of tools at my disposal to try to wring more  information out of the error, until finally the knot was untied. But &#8212; for all the bugs like that I&#8217;ve been through, none of them were eventually solved by guessing what was wrong and how to fix it.</p>
<p>Supposedly, the tool is meant to teach the students to debug their code&#8230; which it somehow does by disallowing all normal debugging tools. You can&#8217;t run a debugger on it, you can&#8217;t print traces, you&#8217;re not allowed to log to a file or socket, you&#8217;re not even allowed to know what input caused the error. The only tools you have at your disposal are your wit in coming up with your own test cases and code reviews.</p>
<p>Any attempts at normal debugging would be classified as cheating. If I was faced with a bug under those circumstances, I would do whatever I could to get more information out of it. Hey, I can crash it with different signals &#8212; that&#8217;s a few bits of information I could get back from it. All those kinds of tricks of the trade that real programmers use to, you know, solve problems&#8230; would be cheating.</p>
<p>This leads to a skewing of results&#8230; very simple bugs turn into monster problems, since you can&#8217;t identify and fix them. What they are learning is not how to debug their programs but how to painstakingly solve the very specific problem of pleasing the system. By artificially making easy things hard, the system has effectively found a way to avoid teaching the students essential skills in programming: simple debugging tools like tracing and breaking into a debugger. Instead, they learn programming by coincidence: poke something until you (hopefully, eventually) get a green light.</p>
<p>That&#8217;s not a lesson to learn.</p>
<p>The only way to go about this, faced by the obstacle made up of this system, is to learn a different skill: testing. More on that later.</p>
<p>More on studies: <a href="http://www.entertainingcode.com/archives/an-exceptionally-stupid-idea/">An Exceptionally Stupid Idea</a>, <a href="http://www.entertainingcode.com/archives/go-tinker/">Go Tinker</a>, <a href="http://www.entertainingcode.com/archives/whats-a-good-final-year-project/">What’s a Good Final Year Project?</a></p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2919823884810618";
/* Links */
google_ad_slot = "5892302561";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/black-box-black-box-testing/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t Be an Open Source Douchebag</title>
		<link>http://www.entertainingcode.com/archives/dont-be-an-open-source-douchebag/</link>
		<comments>http://www.entertainingcode.com/archives/dont-be-an-open-source-douchebag/#comments</comments>
		<pubDate>Sat, 22 Aug 2009 21:28:48 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Asshole]]></category>
		<category><![CDATA[Communication]]></category>
		<category><![CDATA[Learning]]></category>
		<category><![CDATA[Open Source]]></category>
		<category><![CDATA[Software]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=879</guid>
		<description><![CDATA[I love open source software. It provides both a neat tr [...]]]></description>
			<content:encoded><![CDATA[<p>I love open source software. It provides both a neat training ground for programmers, a good place to go <a href="http://www.entertainingcode.com/archives/go-tinker/">scratch that itch</a>. On the other side of things, it provides awesome software for people, including some software that would never come out of a big development house.</p>
<p>Still, there are some issues with free software that don&#8217;t really show up to the same degree with commercial software. One such thing is documentation. It&#8217;s painfully obvious that documentation is written by people who:</p>
<ol>
<li>Already know the software in and out.</li>
<li>Don&#8217;t like writing documentation.</li>
<li>Know nothing about how people learn.</li>
</ol>
<p>For instance, when I started a side project a few months back, I was looking for a build system. After settling on <a href="http://www.cmake.org/">CMake</a>, I set about trying to make sense of it. There&#8217;s the ever-present <a href="http://www.cmake.org/cmake/help/examples.html">getting started example</a>, of course. And then there&#8217;s the <a href="http://www.cmake.org/cmake/help/cmake2.6docs.html">full reference</a> of everything you could possibly want (almost).</p>
<p>But in between those, there&#8217;s nothing. Well, nothing except a book, which just goes to show you that there&#8217;s something missing &#8212; a professional writer could obviously make some money out of explaining things in a reasonable way.</p>
<p>The problem with this is that it <strong>doesn&#8217;t match how people learn</strong>. Getting started is a good step, but a relatively small one. Most of the time will be spent incrementally expanding the knowledge, moving from beginner to expert. Most time will thus be spend in some kind of zone in between the &#8220;getting started&#8221; and &#8220;reference of everything&#8221; levels.</p>
<p>Worse than that, some open source programmers have a tendency to view their full reference documentation as an appropriate resource for everyone. &#8220;It&#8217;s all in there,&#8221; right? But pointing a beginner at a 40-page document detailing all the options of some application when all they want is to run it properly isn&#8217;t very helpful. I&#8217;m sure you know what I&#8217;m talking about if you&#8217;ve ever used an open source command line tool.</p>
<p>That ends us up with the really dark side of free software culture. The true douchebags out there will not only be extremely smartass in their RTFM comments, they&#8217;ll also be incredibly sensitive and defensive about the software they&#8217;re working on.</p>
<p>I ran into a problem with cygwin&#8217;s SSHD implementation last week. In searching for the solution, I found <a href="http://www.mail-archive.com/cygwin@cygwin.com/msg99637.html">this mail list answer</a>:</p>
<blockquote>
<pre>  Wrong.  That is uninformed speculation and guesswork.  Stop
spreading misinformation.

  Cygwin SSHD has had the support for fully logging in as any
user since 1.7, as you have already been told and completely
ignored.  Go and read the manual.  The link was in the previous
email I sent in this thread.

  freesshd works exactly as Cygwin *used* to before it got
subauth support: when you log in with a key, rather than a
password, you just end up as an admin user.</pre>
</blockquote>
<p>Wow. This kind of answer is wrong on so many levels. First of all, while he makes it seem like the functionality has been there forever, cygwin 1.7 is still not even out of beta. The chance that an end user has it is about 0. So, with the current version (1.5),  supposedly cygwin sshd works just like freesshd. This is clearly false, because the original poster reports one working and the other not (which is, by the way, exactly the same results that I had).</p>
<p>So, a user reporting a problem about logging in gets pointed to a long documentation about security settings in a beta version, doesn&#8217;t understand a word from that document (no surprise there), and as a result gets told to &#8220;stop spreading misinformation&#8221;. Truth is, simply installed like any normal user installs applications, one works and the other doesn&#8217;t, something made quite clear by an answer from the original poster in a <a href="http://www.mail-archive.com/cygwin@cygwin.com/msg99616.html">different place</a> in the thread:</p>
<blockquote>
<pre>&gt; Are you talking about password or public key authentication?
&gt; If the latter, Have you tried the LSA authentication package
&gt; in Cygwin 1.7?</pre>
<pre>I don't know. I'll try to deciper that. Sounds complicated. In
the meantime, friend is using freesshd.</pre>
</blockquote>
<p>The essence of what he&#8217;s saying (which has been completely missed by the cygwin developers) is that the effort required to get cygwin to work like one would reasonably expect of it is much higher than the effort required to just google for something that <a href="http://www.codinghorror.com/blog/archives/000290.html">just works out of the box</a>. The fact that you could potentially make it work is irrelevant, because he&#8217;s not getting any help <em>actually making it work</em>.</p>
<p>He might as well just have said, &#8220;I don&#8217;t care about making it work for you. It works for me.&#8221;</p>
<p>Software companies usually compensate for their complete lack of useful technical support with a good (or at least reasonably decent) amount of help documentation. Free software usually has neither.</p>
<p>I encourage any programmer to practice their technical skills on an open source project. But while you do so, take the opportunity to practice your people skills a bit as well, or why not your writing skills? Don&#8217;t be an open source douchebag &#8212; someone reporting your software&#8217;s flaws is not attacking you personally.</p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '409';
var flattr_url = 'http://www.entertainingcode.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Entertaining Code';
var flattr_dsc = 'Coding and the games industry';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script>]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/dont-be-an-open-source-douchebag/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>What&#8217;s a Good Final Year Project?</title>
		<link>http://www.entertainingcode.com/archives/whats-a-good-final-year-project/</link>
		<comments>http://www.entertainingcode.com/archives/whats-a-good-final-year-project/#comments</comments>
		<pubDate>Tue, 11 Aug 2009 20:20:43 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[The Games Industry]]></category>
		<category><![CDATA[Career]]></category>
		<category><![CDATA[Code]]></category>
		<category><![CDATA[Games]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=861</guid>
		<description><![CDATA[Here's a question from the mailbag, coming from a stude [...]]]></description>
			<content:encoded><![CDATA[<p>Here&#8217;s a question from the mailbag, coming from a student doing games programming at a university, gearing up for his final-year project:</p>
<blockquote><p>The degree I&#8217;m doing currently has been very much centered around graphical programming, aswell as using various programming languages to bolster our CV&#8217;s I would imagine. We&#8217;ve not really touched on networking, or AI at all. Our main language in graphical programming has been OpenGL too, we&#8217;ve dabbled with DirectX a little, mostly managed directX with XNA.</p>
<p>As a programmer already in the industry, could you give me any advice on the type, and level of project I should aim for, for it to be a suitable demo project to show to prospective employers? It&#8217;s difficult enough as students to find our way into the games industry; if we don&#8217;t know what employers <em>want,</em> or what is considered worthy in the eyes of the employer, it lowers our odds tenfold.</p></blockquote>
<p>In a way, the answer to the question depends on what kind of position you&#8217;re trying for. I&#8217;ll try to answer with regards to as many positions as I know.</p>
<p>For starters, is graphics programming what you want to be doing? If it is, things like what graphics APIs you know become a lot more important. From what I know, most games studios that do windows game development have gravitated towards DirectX. With that in mind, having done a large(ish) project on DirectX could definitely be a plus. If all other things are equal, I&#8217;d definitely go for learning DirectX.</p>
<p>Not having experience with networking or AI isn&#8217;t all that much of an issue, unless you imagine going specifically for a networking or AI programming position (and even then, it&#8217;s more of a bonus than a requirement). One thing is clear however&#8230; if you&#8217;re looking to get into professional development at a large studio, you should be going for C++.</p>
<p>Now if we look past the technical requirements, there are a few things that can be said about such a project in itself. What you get from a good project is a nice entry into your demo reel &#8212; something to show off. This has a few implications, but most importantly something I&#8217;ve touched on before, in <a href="http://www.entertainingcode.com/archives/a-spectacular-failure/">A Spectacular Failure</a>: your project is going to be judged on emotional first impressions, not how technologically advanced it is or how nicely coded it is.</p>
<p>Your number one enemy is over-scoping the project, ending up with something that does lots of things, but does none of them in a great way. Come up with a good core gameplay for the game, and then polish it to a great shine. Fix all those annoying glitches and bugs, make sure everything looks as impressive as possible. It doesn&#8217;t need to be rocket science, as long as it&#8217;s well executed. In the end, what a games studio is looking for is a programmer who knows how to finish projects in a good way.</p>
<p>That doesn&#8217;t mean your project should be Space Invaders, but in general trying for something too big is more of a problem than overdoing something too small.</p>
<p>Finally, as an entry on your demo reel, make sure you make the game available in an easy manner. Have a page with plenty of screen shots, videos and preferably the game itself easily downloadable. Your coding ability will definitely be tested with some form of work sample as you apply to studios, so the code itself being available is less important. Reading code is hard, so <a href="http://www.entertainingcode.com/archives/trying-the-open-source-shortcut/">it&#8217;s unlikely that someone will have time to read yours</a>. However, having a finished game to show off is worth a lot, as is the experience of going through all the phases in finishing a game.</p>
<p>Other posts you may find interesting, relating to getting into the games industry and getting started with games:</p>
<ul>
<li><a href="http://www.entertainingcode.com/archives/getting-into-games-a-follow-up/">Getting Into Games</a></li>
<li><a href="http://www.entertainingcode.com/archives/an-exceptionally-stupid-idea/">An Exceptionally Stupid Idea</a></li>
<li><a href="http://www.entertainingcode.com/archives/lets-make-a-game-engine/">Let&#8217;s Make a Game Engine</a></li>
</ul>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2919823884810618";
/* Links */
google_ad_slot = "5892302561";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/whats-a-good-final-year-project/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Design Fundamentals: Abstraction</title>
		<link>http://www.entertainingcode.com/archives/design-fundamentals-abstraction/</link>
		<comments>http://www.entertainingcode.com/archives/design-fundamentals-abstraction/#comments</comments>
		<pubDate>Sat, 09 May 2009 16:45:48 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Design Fundamentals]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=446</guid>
		<description><![CDATA[Design Fundamentals is my series on code design aimed a [...]]]></description>
			<content:encoded><![CDATA[<p><em><a href="http://www.entertainingcode.com/archives/design-fundamentals/">Design Fundamentals</a> is my series on code design aimed at people who may have done some code in school, but haven&#8217;t done much code design, or who haven&#8217;t read much about design before.  This is the second article of the series.</em></p>
<p>Code design is all about making sense of a system. Any software worth mentioning quickly grows larger than your brain can easily track. A good design will ensure that each piece of the program can be safely worked on in isolation &#8212; that whatever you need to do, it&#8217;ll fit within your working memory.</p>
<p>Abstraction is a key component to keeping the amount of details you need to remember at once at a minimum. By abstracting a piece of code, you remove the details and only have to think about the abstract interface to the code, which should be smaller (or the abstraction was a bad idea).</p>
<p>So exactly how does abstraction work? I&#8217;m sure you&#8217;ve done some version of it before, maybe even without being aware of it. At a low level of abstraction, the code is filled with all the details. At a high level of abstraction, code uses concepts that hide details. So in abstracting code, we lift out the details to some other place &#8212; maybe a class or a function.</p>
<h3>When to abstract</h3>
<p>While you can debate any kind of rules for when to abstract (just like most things in code), I&#8217;ll attempt to give you some guidelines. Adapt them as they suit you and change them if they don&#8217;t make sense in your context.</p>
<p>For functions, what you can keep in your head is strongly related to what you can see on your screen. As soon as a function has you scrolling up and down, you&#8217;ve got a good sign that the function is too long and that you should abstract something away. For me, the maximum length of a function that is normally reasonable is about 50 lines &#8212; the exact number will vary with personal preference and the content of the function.</p>
<p>For both functions and classes, the relationship with other classes or functions also matters &#8212; specifically the fan-out (amount of other classes your class uses, for instance). You want to keep the fan-out low, since otherwise you risk forgetting the details of something while working on the code (or confusing the next coder who works with it). Steve McConnell has this to say about it in <a href="http://www.amazon.com/gp/product/0735619670?ie=UTF8&amp;tag=entercode-20&amp;linkCode=as2&amp;camp=1789&amp;creative=9325&amp;creativeASIN=0735619670">Code Complete</a><img style="border:none !important; margin:0px !important;" src="http://www.assoc-amazon.com/e/ir?t=entercode-20&amp;l=as2&amp;o=1&amp;a=0735619670" border="0" alt="" width="1" height="1" /> (a recommended book if you&#8217;re interested in code and design):</p>
<blockquote><p><em><strong>Low-to-medium fan-out</strong></em> Low-to-medium fan-out means having a given class use a low-to-medium number of other classes. High fan-out (more than about seven) indicates that a class uses a large number of other classes and may therefore be overly complex. Researchers have found that the principle of low fan-out  us beneficial whether you&#8217;re considering the number of routines called from within a routine or from within a class.</p></blockquote>
<p>The same thing applies with the number seven as with the above line count &#8212; use your judgement, but keep in mind when the fan-out is starting to increase that you might want to look at your design again.</p>
<h3>Common abstraction mistakes</h3>
<p>The number one mistake people do when it comes to abstraction is to confuse the need to abstract with the interface of classes that is exposed to others. Often, when abstracting a part of a function to a new function, it doesn&#8217;t need to go into the interface of the class you&#8217;re working with at all &#8212; it can simply be placed in an anonymous namespace at the top of the file you&#8217;re working on.</p>
<p>Another mistake that is fairly common is to treat abstraction as a simple cut and paste activity, where a number of lines of code are simply moved to another place. Stop to consider where to make the cut &#8212; what part of the code you&#8217;re working on is a logical unit that does something reasonable? If you end  up with a function named partOfMyOtherFunction() or something similar, you haven&#8217;t really achieved anything.</p>
<p>Keep thinking about your abstracted functions &#8212; do they share characteristics? Often you might find yourself creating helper functions that would fit better grouped together in a helper class. This class can also reside in the same file &#8212; there&#8217;s nothing which forces you to create a new header file and source file in order to abstract code.</p>
<h3>Building abstract code</h3>
<p>If possible, build your code in abstract layers from the start. Consider what parts you might need when implementing your functionality, and make sure implementation details are well partitioned off. Especially things like system differences and interfaces towards the operating system is good targets for an abstraction layer.</p>
<p><a href="http://www.entertainingcode.com/archives/design-fundamentals-encapsulation/">Encapsulate</a> the system functionality in order to not have to bother with details everywhere in the code. This is especially useful when interfacing with badly designed APIs, to ensure that this doesn&#8217;t spread to all of your code. This lets the rest of your code think about the system functionality at a higher level, without the details.</p>
<p><script type="text/javascript"><!--
google_ad_client = "pub-2919823884810618";
/* Links */
google_ad_slot = "5892302561";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '409';
var flattr_url = 'http://www.entertainingcode.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Entertaining Code';
var flattr_dsc = 'Coding and the games industry';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script>]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/design-fundamentals-abstraction/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Design Fundamentals: Encapsulation</title>
		<link>http://www.entertainingcode.com/archives/design-fundamentals-encapsulation/</link>
		<comments>http://www.entertainingcode.com/archives/design-fundamentals-encapsulation/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 20:32:38 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Design Fundamentals]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=423</guid>
		<description><![CDATA[Encapsulation is one of the core design patterns of Obj [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignright size-full wp-image-428" title="Encapsulation" src="http://www.entertainingcode.com/wp-content/uploads/2009/04/encapsulation.jpg" alt="Encapsulation" width="160" height="160" />Encapsulation is one of the core design patterns of Object Oriented programming. The point of encapsulation is to split a large program into a number of smaller, <strong>independent</strong> parts to reduce complexity. In a sentence, encapsulation is hiding the implementation details of a module from its user.</p>
<p>The point of doing this is that it&#8217;s easier to use a module with a <strong>well defined interface</strong> and it&#8217;s easier to change the implementation if fewer things depend on it. If you expose the implementation of a module to its user, you can bet the user is going to end up in some way or other dependent on the implementation details. This means that the risk of breaking <em>something </em>increases every time you make a change to the module.</p>
<p>Why does this not become an apparent problem for a new programmer? There are two major contributing factors. One is that new programmers tend to write small to medium sized programs, and that dependency-based problems tend to become apparent only in large applications. In a small application, you&#8217;ll have a few users of your module, and when you break the implementation dependency, maybe one of them breaks. You fix the error and move on. Simply put: You don&#8217;t need design skills to write &#8220;Hello, World!&#8221; applications.</p>
<p>Experienced Software Engineers tend to write large to massive program systems. If you have a lot of things dependent on the implementation details you&#8217;re changing, chances are a lot of things will break, and maybe some of the errors won&#8217;t be apparent until much later. Even better, if all your components are dependent of implementation details of others, every change you make is virtually guaranteed to break <em>something</em>.</p>
<p>The second reason initiate coders fail to notice the need for encapsulation is that the errors that spring from this are delayed. There&#8217;s nothing immediately wrong with your code &#8212; it works. That&#8217;s why this is a question of design, not of code.</p>
<p>So how do you properly encapsulate code? Start by looking at your interface for the class. How does one interact with it? Consider what it means &#8212; does the interface tell you <strong>what it&#8217;s doing</strong>, or <strong>how it&#8217;s doing it</strong>? If you find it&#8217;s telling you anything at all about how it does things, consider what you could do to hide it.</p>
<p>Another useful way to think about a class interface in terms of encapsulation is &#8220;<em>how could I break this object&#8217;s functionality</em>&#8220;? If you find you could break it, something&#8217;s wrong with your encapsulation. A properly encapsulated object guarantees the consistency of its own state at all times. This way of thinking about a module leads to robust interfaces and code.</p>
<p>A good starting point for encapsulation is to make all your internal data private, and to expose only retrieval methods for those things the outside world has any business knowing about (languages with <a href="http://www.entertainingcode.com/archives/but-bad-programmers-will-abuse-it/">Properties</a> like C# avoid this, but without them you&#8217;re better off doing this). Remember, one point of encapsulation is that you should be able to change the implementation without changing the interface, and if your internal variable are public, you can&#8217;t change how you store data.</p>
<p>There&#8217;s a tendency to expose other complex objects that your class owns by direct accessor functions as well. This is usually a mistake. In essence, you&#8217;re giving up control over these objects, which means you can no longer guarantee your internal state is consistent and you can&#8217;t switch to a different kind of object.</p>
<p>Consider an example of a logging facility that has an output stream. There might be a temptation to do something like this:</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000dd;">log</span>.<span style="color: #007788;">getOutStream</span><span style="color: #008000;">&#40;</span><span style="color: #008000;">&#41;</span> <span style="color: #000080;">&lt;&lt;</span> <span style="color: #FF0000;">&quot;Testing, testing&quot;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This is where you break encapsulation, becaue suddenly you have no idea what&#8217;s being done to the log stream. Maybe someone saved a reference to it somewhere? Is it safe to delete it? Did someone start a row and leave it unfinished (like I did above)? Dunno.</p>
<p>Also, you&#8217;re now stuck unable to change to logging over a network, onto a printer, into a GUI or whatever else could be useful to do (unless you want to <a href="http://spec.winprog.org/streams/">derive your own iostream</a>, which I wouldn&#8217;t recommend).</p>
<p>An option is to encapsulate the logging service fully, and only provide an interface to do things with (log text):</p>

<div class="wp_syntax"><div class="code"><pre class="cpp" style="font-family:monospace;"><span style="color: #0000dd;">log</span>.<span style="color: #007788;">addTextRow</span><span style="color: #008000;">&#40;</span><span style="color: #FF0000;">&quot;Testing, testing&quot;</span><span style="color: #008000;">&#41;</span><span style="color: #008080;">;</span></pre></div></div>

<p>This way, whatever you do in addTextRow() is your own business, as long as logs get made.</p>
<p>As with most design issues, getting the design right when it comes to encapsulation is hard the first time around. You&#8217;ll almost never get it right the <a href="http://www.entertainingcode.com/archives/lets-make-a-game-engine/">first time around</a>. That doesn&#8217;t mean you shouldn&#8217;t try your best though &#8212; the reason you get it right the second time is that you notice what happened the first time you tried.</p>
<p>Many new coders tend to mix up project process with design process. Hearing about waterfall (and it&#8217;s negative sides), they say &#8220;I&#8217;m not doing waterfall&#8221;, which to them means not to do any design up front. This is a big mistake &#8212; think about your design all the time. When you sit down to write a new class, you should have a design idea in mind &#8212; trying to nail on design onto a kludge of code is a lot harder than to rework a bad design into a good one.</p>
<p>What does this have to do with encapsulation? It means you should make your variables private from the start, and immediately start thinking about your interface. That way, you&#8217;re not going to have to realize halfway through that you&#8217;ve missed encapsulating things. Nearly always, <strong>the key to getting the design right is to start thinking about the design</strong>.</p>
<p>When I recently sat down to implement a new feature of a side project I&#8217;m working on, the first thing I did was create 10 empty files, because I&#8217;d already thought the design through enough to know I&#8217;d need those classes. That doesn&#8217;t mean you should do all your design up front, and never touch it again (waterfall-style), it just means there&#8217;s nothing wrong with thinking about design before you start coding. In fact, I very much encourage it.</p>
<p></p>
]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/design-fundamentals-encapsulation/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Design Fundamentals</title>
		<link>http://www.entertainingcode.com/archives/design-fundamentals/</link>
		<comments>http://www.entertainingcode.com/archives/design-fundamentals/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 19:52:10 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[Design Fundamentals]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=418</guid>
		<description><![CDATA[I've been working on a new side project with a friend o [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on a new side project with a friend of mine. I&#8217;m thrilled to have found something that&#8217;s both an interesting challenge and something good to have on the side. It&#8217;s already teaching me new things that I would probably never have the opportunity to explore at work, for various reasons.</p>
<p>One of these things I&#8217;ve learned is that there are many things that I use in my coding are things that I take for granted but that are not natural or obvious to initiate coders. My friend is a coder who&#8217;s got some experience of coding through College, but I&#8217;ve realized that going from initiate coder to Software Engineer takes a lot of experience and that there are many things I&#8217;ve picked up along the way.</p>
<p>I got my share of that experience by creating a game engine in a startup, and doing a lot of other mildly complicated things. I had the fortunate position of having a colleague with whom I could discuss all design decisions to the bitter end, and the time to make a fair few mistakes and figure out how to turn them into successes.</p>
<p>What your path to getting that experience is, I can&#8217;t tell. <strong>Only you can walk that path</strong>, but at least I can set up some signs along the way to help. I&#8217;ll be starting a new series of posts called Design Fundamentals, where I&#8217;ll explore design concept that are fundamental to wrap your head around. Hopefully even experienced coders can gain something from these posts.</p>
<p>The posts will try to gather in one place only what a given design technique or pattern means, but also how to use it, why it&#8217;s useful and various tips and trips.</p>
<p>I&#8217;ll be using C++ as the language for these posts, as it&#8217;s my language of choice. Much of the information may benefit you if you&#8217;re coding in another language, and in fact the only recommendations I have for you when it comes to languages is pick one, and make it your native one. Become an expert in one language, don&#8217;t try to go wide. There&#8217;s a good point in learning to code in a few languages &#8212; but don&#8217;t make it your focus to become as good in all of them.</p>
<p>This post will serve as an index &#8212; all future posts in the series will be linked from here.</p>
<ul>
<li><a href="http://www.entertainingcode.com/archives/design-fundamentals-encapsulation/">Design Fundamentals: Encapsulation</a></li>
<li><a href="http://www.entertainingcode.com/archives/design-fundamentals-abstraction/">Design Fundamentals: Abstraction</a></li>
</ul>
<p></p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '409';
var flattr_url = 'http://www.entertainingcode.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Entertaining Code';
var flattr_dsc = 'Coding and the games industry';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script>]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/design-fundamentals/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Programming Culture</title>
		<link>http://www.entertainingcode.com/archives/programming-culture/</link>
		<comments>http://www.entertainingcode.com/archives/programming-culture/#comments</comments>
		<pubDate>Tue, 17 Mar 2009 00:14:52 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=264</guid>
		<description><![CDATA[I decided to learn Common Lisp.

After feeling like I [...]]]></description>
			<content:encoded><![CDATA[<p><em>I decided to learn Common Lisp.</em></p>
<p>After feeling like I&#8217;d somewhat gotten stuck in my programming development, I decided I needed to do something well outside my comfort zone in order to get off the plateau. So after a quick look around, I decided Lisp was probably a good target.</p>
<p><em>Then I decided not to learn Common Lisp.</em></p>
<p><strong>Here&#8217;s why</strong>:</p>
<p>I&#8217;ve learnt a fair few languages in my days&#8230; some have been incredibly useful but scorned by others like Visual Basic, some are popular and have a great following like C++ or Perl. Some are small but surrounded by friendly enthousiasts, like Lua. Some are just generally strange but well documented, like tcl. All of these are different experiences to learn, because not only do the languages differ but their communities differ.</p>
<p>It&#8217;s a lot like learning to speak a new language and at the same time discovering the exciting culture that comes with it.</p>
<p>But some programming languages seem to have <strong>a more or less arrogant culture </strong>surrounding them. They tend to be small languages that claim to be <strong>revolutionary yet no one uses them</strong>. They&#8217;re small and they&#8217;ve been small for a long time. Lisp falls into this category. One article I read strongly asserted that after decades, the time for Lisp was just about to come. Soon, Lisp would be the mainstream choice. Pity the article was 20 years old, and the use of Lisp has hardly increased since.</p>
<p><a href="http://xkcd.com/297/"><img class="aligncenter size-full wp-image-329" title="Lisp" src="http://www.entertainingcode.com/wp-content/uploads/2009/03/lisp_cycles1.png" alt="Lisp" width="376" height="425" /></a></p>
<p>It&#8217;s weird that this is the case, if the languages themselves are so revolutionary as their followers claim. I&#8217;ve seen it with both Lisp and Smalltalk, and after going through it a second time, I think can explain why: Their programming culture has <strong>confused teaching with preaching</strong>.</p>
<p>And learning new stuff is <a href="http://www.entertainingcode.com/archives/level-up/">really important</a> when it comes to programming&#8230; which means teaching is equally important.</p>
<p>Let&#8217;s back up a bit&#8230; I learned Lua. If you try it, your first move will probably be a <a href="http://www.google.se/search?q=learn+lua">google search</a> and you&#8217;ll find books online and help pages that in a friendly tone go &#8220;here&#8217;s lua, have a try, plunge in&#8221;. But when you try to learn Smalltalk, the same method will get you pages on why Smalltalk&#8217;s design is great. Starting to browse forums about Smalltalk, most of the discussions I ended up reading were about how <span style="text-decoration: line-through;">God</span> <a href="http://en.wikipedia.org/wiki/Alan_Kay">Alan Kay</a> certainly didn&#8217;t mean for object oriented programming to look like C++ (&#8220;lol, what a thought&#8221;).</p>
<p>The same thing happened to me when I tried to learn Lisp. Finding several books online was not a problem, Google kindly sent me to a site on learning lisp, and following the advice on that site I started reading through a book online, and in parallel started reading a couple of sample chapters of another book. The sample chapters gave me nothing &#8212; some code examples, some interesting stuff, but mainly the focus was on why Lisp is so much better than all the other languages.</p>
<p>When I was halfway into chapter two of the book, it had still not finished motivating why Lisp was such a wonderful language, that the absence of a syntax really is the only way to extend a language and build bottom-up rather than just top-down and how you worked in a completely new way with Lisp and that all other languages were <a href="http://www.pluralsight.com/community/blogs/craig/archive/2008/07/08/lisp-too-is-mainstream.aspx">nothing but shallow copies</a> and could your language really do <strong>this</strong>? And at that point I gave up.</p>
<p>The only feeling I get from this furious defense of the language is a feeling of <strong>uncertainty</strong>. Why do you need to tell me it&#8217;s so superior when all I want is to be shown how it works? Surely actually showing me would be the best way to convince me, especially once I&#8217;ve already taken the interest and initiative to go looking for a place to learn?</p>
<p><strong>I have no doubt that Lisp is a good language</strong>. I&#8217;m still interested in functional programming languages. But I&#8217;d rather take on one where the culture and community is open-minded and busy <strong>doing kick-ass things</strong> with their language rather than telling others how kick-ass it is (or worse, how everything else is crap).</p>
<p>Oh well, <a href="http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/">F#</a> looks interesting. In the meantime, I learnt a different language and did some really cool stuff.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/programming-culture/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Level Up</title>
		<link>http://www.entertainingcode.com/archives/level-up/</link>
		<comments>http://www.entertainingcode.com/archives/level-up/#comments</comments>
		<pubDate>Wed, 28 Jan 2009 23:40:59 +0000</pubDate>
		<dc:creator>slicedlime</dc:creator>
				<category><![CDATA[Code]]></category>
		<category><![CDATA[Learning]]></category>

		<guid isPermaLink="false">http://www.entertainingcode.com/?p=132</guid>
		<description><![CDATA[Good programmers continously learn. The defining charac [...]]]></description>
			<content:encoded><![CDATA[<p>Good programmers <a href="http://www.codinghorror.com/blog/archives/000895.html">continously learn</a>. The defining characteristic about the top coders I&#8217;ve met is their complete and never-ending thirst for knowledge of almost any kind. The best way I can think of to describe them would be to say that they&#8217;re &#8220;<strong>interested</strong>&#8220;.</p>
<p>In the games industry especially, multi-talented people tend to be the ones that rise to the top. The people who essentially pulled Battlefield: Bad Company together during its darkest moments in production were the coder with an eye for game design, the ex-programmer designer, the artist with a feel for level design&#8230; and so on.</p>
<p>Looking at the famous people in the industry they tend to have been brilliant hackers that coded a game for the early PCs or Amigas in a basement somewhere, only to go on to become a lead designer for a massive latest-generation console game, not even touching the code. I firmly believe this is because of a never-ending desire to expand their skill set, explore new things, and as such not only aquire a view on how lots of things work, but also on <strong>how lots of people think</strong>.</p>
<p>Becoming a better programmer has a lot to do with a deep desire to learn, a thirst for knowledge. People often find me curious when I get stuck to a documentary about some esoteric subject like a <a href="http://2dboy.com/games.php">World of Goo</a> gooball to a cliff&#8230; but it&#8217;s yet another manifestation of this desire. It doesn&#8217;t have to even come remotely close to a subject about code or computers. So in a way, it&#8217;s no surprise that the best coders I know tend to also be musicians, artists or have other creative hobbies. World of Goo was made by just a few multi-talented people.</p>
<p>But a good programmer doesn&#8217;t stop at learning about things by passive reading or watching&#8230; they&#8217;ll inevitably have a deep desire to <strong>do stuff</strong>, and to keep exploring possibilities. And they won&#8217;t stop at doing stuff either, they&#8217;ll strive to perfect the art of whatever they&#8217;re doing.</p>
<p>At the same time, one of the first things one needs to learn is that perfection is ultimately unattainable. It&#8217;s this inherent conflict between &#8220;refactor&#8221; and &#8220;hack&#8221; that leads to systems improving in iterations, and each step towards perfection is a manifestation of the sum of the learning that&#8217;s happened this far.</p>
<p>On the flip side, one of the worst programmers I&#8217;ve ever worked with was a guy who (openly) refused to learn, and had lost all interest in learning. He said he just wanted to make cool games, and wasn&#8217;t interested in education. The result was that when the rest of the coding team would learn something about the system and advance a small bit, he&#8217;d remain behind.</p>
<p>The problem with programmer skill is that it&#8217;s <strong>incredibly hard to judge </strong>without at least peripherally working with the person in question and reading their code. The result of this was that this guy would be given a task, implement it quickly with no regard to all the rules and guidelines everyone else had learned to apply to prevent bugs &#8212; in essense he&#8217;d do what the rest of us would always consider as hacks. He was well regarded among designers and producers &#8212; almost seen as a miracle worker, because he was so quick at getting things done.</p>
<p>Then he left at 5 pm and the rest of us spent late evenings fixing his bugs by essentially removing what he&#8217;d done (which was always causing bugs that were hard to track down and pinpoint) and re-implementing the features.</p>
<p>What&#8217;s the lesson to take away from this story then? Well, first of all, keep learning! Don&#8217;t let yourself fall into a trap of thinking you&#8217;re pretty good at what you do, thinking that there&#8217;s no reason to learn C#, to look at functional programming or to learn to build levels or even that there&#8217;s nothing interesting about Penguins.</p>
<p>And, second, most of the people you work with have no idea whether the coders on your team are all excellent coders or if some are really bad. Shocking as it may sound, <strong>it&#8217;s up to you </strong>to tell them, because in the end you&#8217;ll inevitably be the one fixing the bugs at 11 pm as your ship date approaches.</p>
<p></p>
<script type="text/javascript">
var flattr_wp_ver = '0.9.11';
var flattr_uid = '409';
var flattr_url = 'http://www.entertainingcode.com';
var flattr_lng = 'en_GB';
var flattr_cat = 'text';
var flattr_tag = 'blog,wordpress,rss,feed';
var flattr_btn = 'large';
var flattr_tle = 'Entertaining Code';
var flattr_dsc = 'Coding and the games industry';
</script>
<script src="http://api.flattr.com/button/load.js?v=0.2" type="text/javascript"></script>]]></content:encoded>
			<wfw:commentRss>http://www.entertainingcode.com/archives/level-up/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
