tag:blogger.com,1999:blog-68728273782533708432024-03-22T03:22:09.260+00:00In the Coding ZoneI'm sorry, I'm currently "in the zone". Please try again later...Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.comBlogger34125tag:blogger.com,1999:blog-6872827378253370843.post-47279225727951333682013-05-23T13:27:00.001+01:002013-05-23T13:27:50.697+01:00Session Expiration in ASP.NET MVC<p>The other day a colleague of mine asked me for some help fixing a bug. The issue was that our web sessions are configured to last 30 minutes and after 30 minutes of inactivity ASP.NET should redirect the user back to the login page (in our case at least), but this was not happening in our latest ASP.NET MVC website. I wandered over to his screen and saw it for myself, it just let the request complete as usual, defying my understanding of how session expiration worked.</p> <p>So I searched around and found out the following:</p> <h3>Authorization</h3> <p>In our case the session timeout and the forms authentication timeout are different: sessions timeout at 30 minutes while forms authentication can last much longer. So it seems that what ASP.NET MVC does by default (using the <a href="http://msdn.microsoft.com/en-us/library/system.web.mvc.authorizeattribute(v=vs.108).aspx">[Authorize] attribute</a>) is to authorize the request coming in because that has not expired yet but a new session is set up for the user. This means that any previous data you had stored is missing which will no doubt affect the functionality of your website.</p> <h3>Solution</h3> <p>So how can we solve this? This solution is actually quite simple, a custom authorization attribute can be implemented which can both authorize and check the session. For example let’s assume that your session contains something which you know means that a user is logged in, for instance a user ID; that means you can write something like the following:</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:7ffbbe88-bd88-4415-90b3-d701a9367a92" class="wlWriterEditableSmartContent"><pre style=" width: 727px; height: 589px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">[AttributeUsage(<br /> AttributeTargets.Class </span><span style="color: #000000;">|</span><span style="color: #000000;"> AttributeTargets.Method, <br /> Inherited </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">, <br /> AllowMultiple </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;"><br />)]<br /></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> CustomAuthorizeAttribute : AuthorizeAttribute<br />{<br /><br /> </span><span style="color: #0000FF;">protected</span><span style="color: #000000;"> </span><span style="color: #0000FF;">override</span><span style="color: #000000;"> </span><span style="color: #0000FF;">bool</span><span style="color: #000000;"> AuthorizeCore(HttpContextBase httpContext)<br /> {<br /> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (httpContext </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)<br /> {<br /> </span><span style="color: #0000FF;">throw</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> ArgumentNullException(</span><span style="color: #800000;">"</span><span style="color: #800000;">httpContext</span><span style="color: #800000;">"</span><span style="color: #000000;">);<br /> }<br /><br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Authenticate the user using Forms Authentication</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> IPrincipal user </span><span style="color: #000000;">=</span><span style="color: #000000;"> httpContext.User;<br /> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (</span><span style="color: #000000;">!</span><span style="color: #000000;">user.Identity.IsAuthenticated)<br /> {<br /> </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;<br /> }<br /> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Now check that a new session has not been created, if we are missing<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> some critical session variables then we assume that the session<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> expired and do not allow the request to continue</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> </span><span style="color: #0000FF;">if</span><span style="color: #000000;"> (httpContext.Session[</span><span style="color: #800000;">"</span><span style="color: #800000;">UserId</span><span style="color: #800000;">"</span><span style="color: #000000;">] </span><span style="color: #000000;">==</span><span style="color: #000000;"> </span><span style="color: #0000FF;">null</span><span style="color: #000000;">)<br /> {<br /> </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">false</span><span style="color: #000000;">;<br /> }<br /> <br /> </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> </span><span style="color: #0000FF;">true</span><span style="color: #000000;">; <br /> }<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>By applying this custom authorization attribute to your controllers/actions you will now be able to check both forms authentication and session expiration at the same time.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com3tag:blogger.com,1999:blog-6872827378253370843.post-68400753801272930012013-04-29T10:51:00.001+01:002013-04-29T10:51:07.637+01:00Writing Working Code at Hyperspeed<p><strong><img style="float: none; margin-left: auto; display: block; margin-right: auto" src="http://3.bp.blogspot.com/-l9eDpld2UBc/TbHoDCtvMwI/AAAAAAAACq4/b5Z_q33N_rs/s1600/star-wars-008.jpg" width="640" height="362"></strong></p> <p align="center"><font size="1">Image courtesy of <a href="http://cyclingcosmonaut.blogspot.co.uk/2011/04/heavy-drop-exclusive-inside-fotos.html">Cycling Cosmonaut</a></font></p> <p>Today I thought I would share with you something I had to do recently at work. To give some background I work for <a href="http://www.trytalentq.com/">Talent Q</a> who are a provider of online psychometric tests; I am one of the developers who works on all the various systems we have such as the candidate tests, the administration side and all sorts of backend services to keep everything working as it should.</p> <p>In our last sprint we were working on adding a new suite of tests to our product list. In fact we’ve already got them running now as part of some trials before global release and have already witnessed tens of thousands of completions – they clearly work so that’s always a good start! Me and my colleagues did want to go back over the code though before the final release as developers always have that feeling of wanting to perfect their code; we also had a view of making sure long-term maintainability could be achieved.</p> <p>So we looked through what we had already and found some areas that we wanted to improve. The main part was that the code was trying to be too clever for its own good: </p> <ol> <li>Most classes were trying to be very generic but ended up not incorporating the specifics of each individual test, resulting in some <a href="http://c2.com/cgi/wiki?CodeSmell">code smells</a> such as lots of object casting which was unnecessary. <li>We also had several <a href="http://blog.decayingcode.com/post/anti-pattern-god-object.aspx">God objects</a> that tried to contain every conceivable detail you could imagine yet at the end of day even missing some vital details. <li>Due to all the various classes being very generic it was difficult to follow through the logic of the code. There was clearly a design in there to not have too many strong dependencies interlinked with each other – something that I believe is definitely worthwhile – but you could also get easily lost down a codepath; bear in mind that these tests were built up in an organic manner as most things are so the end result does tend to have more than you actually need (which I will discuss later on).</li></ol> <p>So I was the one tasked with implementing the changes we wanted. We decided that we would not make all these generic types which somehow had to be tied together, instead each test would have a dedicated class with a clear focus even if it meant some duplication of logic – as long as we have working code we would be able to compare the differences and refactor later if required.</p> <p>All seems reasonable so far. Oh, did I mention that due to a number of planning issues I had to do all of this in a matter of days?</p> <p>Umm, OK…</p> <p>But I managed it, all within working hours (no overtime) and it all worked first time! Here’s how I did it…</p> <h3>Plan Your Work First</h3> <p>You might think that with a tight deadline in front of you that you should not waste any time and start writing code immediately, right? </p> <p><strong>Wrong!</strong></p> <p>You could do this but without a clear focus on what you are trying to achieve you’ll struggle to keep up with what you are doing; you don’t want to be thinking of what you need to do <em>and</em> how to translate that into code at the same time.</p> <p>So first of all I spent a few hours going over what I needed to do. I looked at each of the new tests we were creating and wrote down notes to help me understand the high-level logic that drove them, such as:</p> <ul> <li>How do I load the questions? <li>How do I keep track of state and where the candidate is in the test? <li>What if the candidate quits a session and restarts from the last question they answered? Will we be able to know where to pick up the test from? <li>How do I get a final result from the test?</li></ul> <p>Fortunately out of the three new test types we were creating two of them were similar to previous assessments we had already released so it wasn’t too hard to work out the details for them. By the end of this I had a one-page document of notes for each test which explained to me everything they needed to do. With this now written down and not cluttering my mind I could finally get down to writing the code.</p> <h3>Test Driven Development is Your Friend</h3> <p>Now I knew what to do I had to figure out how I was going to get my code written down and make sure it all worked quickly. The trial code we currently had was not designed to be testable; it was all written under the assumption that there would always be a database and always have a user interface driving it, meaning that testing that code was manual, laborious and the feedback loop was painfully slow.</p> <p>I’m a big fan of <a href="http://www.agiledata.org/essays/tdd.html">Test Driven Development</a> though; the idea of writing lots of little tests to quickly verify that your code is working is something I’ve jumped onto with gusto. In the end, although I don’t particularly like the idea of <a href="http://inthecodingzone.blogspot.co.uk/2012/11/the-urge-to-rewrite-code.html">rewriting code from scratch</a>, I decided that I was going to have to write the code for these assessments from first principles again and this time focus on making them work in an isolated environment meaning no database or website required.</p> <h3>Start Typing</h3> <p><strong><img style="float: none; margin-left: auto; display: block; margin-right: auto" src="http://media.tumblr.com/tumblr_m6ecstbkvb1r6r7t1.gif"></strong></p> <p align="center"><font size="1">Image originally from <a href="http://media.tumblr.com/tumblr_m6ecstbkvb1r6r7t1.gif">Tumblr</a></font></p> <p>With all this in place it was time for me to start typing, and fast! One of the benefits of Test Driven Development is that because unit tests are so small you can clearly focus on one tiny bit at a time. For example if I wrote the constructor for the assessment then under the scenario of a brand new assessment being run I knew that the outcome of creating the object would mean:</p> <ol> <li>The internal state would be set to “Running Test” instead of “Completed” <li>That the first question number would be one <li>That the total number of questions available would be a specific number <li>That the first question was loaded into the test <li>etc</li></ol> <p>So I simply wrote one test at a time, used the test runner to make sure it passed, and moved to the next one. I managed to keep up this pace and produce quite a number of test cases quickly, all the while improving the code and verifying that it all worked as I expected it to.</p> <h3>Getting “In the Zone”</h3> <p>My blog is called “In the Coding Zone” as it refers to that mythical place where developers love to roam and simply be <a href="http://psygrammer.com/2011/02/10/the-flow-programming-in-ecstasy/">lost in their own thoughts</a> without any kind of interruption. When “in the zone” developers are able to churn out vast amounts of code and be hugely productive.</p> <p><a href="http://www.doolwind.com/blog/how-to-get-in-the-zone-and-stay-there/">Getting there is a challenge in itself</a>, especially when working in an open office environment. Fortunately I got very few distractions during this time so that I really could just ignore everything around me and focus purely on hitting this deadline.</p> <h3>The End Result</h3> <p>After a lot of hard work I hit that deadline but what else did I have to show for it?</p> <ol> <li>With the code rewritten with testing principles in mind we now had our first ever set of assessments which we could run using test automation. This means we can now verify that these assessments work even without a real database and just using dummy data, or build upon the unit tests to create <a href="http://c2.com/cgi/wiki?IntegrationTest">integration tests</a> using a real bank of questions. <li>For the first time our assessments finally make sense; figuring out how our assessments worked used to be a daunting task but I realised this is because it was down to the sheer amount of extraneous code that was written, not due to the complexity of the logic itself. Test Driven Development is really good at focusing you on what you need to achieve to get your tests running; once all tests pass then you don’t need to write any more code so your final implementation tends to be very lean and ultimately simpler to understand. <li>One drawback though is that I was mentally tired after this exercise. Keeping up a relentless pace of writing code/tests almost non-stop for days does take it’s toll on you and you can’t keep it up forever.</li></ol> <p>Developing software seems to have this aurora of always being delayed and not working until you test it over and over again but I wanted to prove that it is possible to have something work first time (and on time!) as long as you plan your work effectively, focus on the job in hand and basically test as you go, not leaving it as an afterthought.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-32499416344238291922013-04-25T14:21:00.001+01:002013-04-25T14:21:08.186+01:00Is JavaScript Really So Bad?<p>I’ve had some pretty strong opinions on JavaScript in the past, most of them negative <a href="http://inthecodingzone.blogspot.co.uk/2012/10/typescript-javascripts-equivalent-to-c.html">as a previous post has explained</a>. Having been forced into using it more fully recently on several mini-projects though my rigid opinions on it have softened slightly.</p> <p>Despite working on web technologies I don’t really consider myself a web developer; I am most comfortable in working on server-side code, usually in C#. So when the time comes when I am faced with HTML, CSS and JavaScript I do tend to get a little overwhelmed; I can be extremely productive in C# but tying server-side code to a front-end interface can take me hours, more likely days, to get an end result that I’m not even that happy with. It is this mindset I think that clouds my judgement with JavaScript; I’m simply not that proficient in using it and don’t continue developing this skillset to allow me to improve.</p> <p>Part of the problem I think is that I am most familiar with <a href="http://www.asp.net/web-forms">ASP.NET WebForms</a>. When I first started web development proper I worked on WebForms and was able to bypass a lot of issues around learning good HTML/CSS/JavaScript practices because WebForms managed most of the functionality for you; just tie up server controls, set some properties and the final rendered result would somehow magically do what you wanted it to. I still work in WebForms but now I’m trying to get more involved with <a href="http://www.asp.net/mvc">ASP.NET MVC</a>, both in a professional and recreational sense, but there’s a problem; MVC is an excellent framework but it does less for you than WebForms. You have full control over the HTML you output but now I need to know the finer details that WebForms so successfully hid from me all these years, including even simple things like what happens when a HTML form sends a POST request back to the server.</p> <p>So given that I’ve been working a bit more on MVC websites recently in various capacities I took the opportunity to try and “reset” my thinking process and try and work with JavaScript as it was intended and not as an afterthought or constant hindrance. Over the past few weeks I’ve now started to form these opinions instead:</p> <h3>Separation of Concerns</h3> <p>Below is a typical example of the kind of webpage I’m most used to seeing:</p> <div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:0ddbee6a-5900-4811-91ee-6bdac2f93d2d" class="wlWriterEditableSmartContent"><pre style=" width: 727px; height: 414px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF;"><!</span><span style="color: #FF00FF;">DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /></span><span style="color: #0000FF;"><</span><span style="color: #800000;">html </span><span style="color: #FF0000;">xmlns</span><span style="color: #0000FF;">="http://www.w3.org/1999/xhtml"</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /></span><span style="color: #0000FF;"><</span><span style="color: #800000;">head</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000FF;"><</span><span style="color: #800000;">title</span><span style="color: #0000FF;">></span><span style="color: #000000;">My webpage</span><span style="color: #0000FF;"></</span><span style="color: #800000;">title</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000FF;"><</span><span style="color: #800000;">style </span><span style="color: #FF0000;">type</span><span style="color: #0000FF;">="text/css"</span><span style="color: #0000FF;">></span><span style="background-color: #F5F5F5; color: #800000;"><br /> .banner<br /> </span><span style="background-color: #F5F5F5; color: #000000;">{</span><span style="background-color: #F5F5F5; color: #FF0000;"><br /> background-color</span><span style="background-color: #F5F5F5; color: #000000;">:</span><span style="background-color: #F5F5F5; color: #0000FF;"> red</span><span style="background-color: #F5F5F5; color: #000000;">;</span><span style="background-color: #F5F5F5; color: #FF0000;"><br /> </span><span style="background-color: #F5F5F5; color: #000000;">}</span><span style="background-color: #F5F5F5; color: #800000;"><br /> </span><span style="color: #0000FF;"></</span><span style="color: #800000;">style</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000FF;"><</span><span style="color: #800000;">script </span><span style="color: #FF0000;">type</span><span style="color: #0000FF;">="text/javascript"</span><span style="color: #0000FF;">></span><span style="background-color: #F5F5F5; color: #000000;"><br /> </span><span style="background-color: #F5F5F5; color: #0000FF;">function</span><span style="background-color: #F5F5F5; color: #000000;"> firstLoad() {<br /> alert(</span><span style="background-color: #F5F5F5; color: #000000;">"</span><span style="background-color: #F5F5F5; color: #000000;">Hello World!</span><span style="background-color: #F5F5F5; color: #000000;">"</span><span style="background-color: #F5F5F5; color: #000000;">);<br /> }<br /> </span><span style="color: #0000FF;"></</span><span style="color: #800000;">script</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /></span><span style="color: #0000FF;"></</span><span style="color: #800000;">head</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /></span><span style="color: #0000FF;"><</span><span style="color: #800000;">body </span><span style="color: #FF0000;">onload</span><span style="color: #0000FF;">="firstLoad()"</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000FF;"><</span><span style="color: #800000;">div </span><span style="color: #FF0000;">class</span><span style="color: #0000FF;">="banner"</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> Welcome!<br /> </span><span style="color: #0000FF;"></</span><span style="color: #800000;">div</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /> </span><span style="color: #0000FF;"><</span><span style="color: #800000;">a </span><span style="color: #FF0000;">href</span><span style="color: #0000FF;">="Next.html"</span><span style="color: #FF0000;"> style</span><span style="color: #0000FF;">="padding: 10px"</span><span style="color: #FF0000;"> onclick</span><span style="color: #0000FF;">="javascript: alert('You clicked me!')"</span><span style="color: #0000FF;">></span><span style="color: #000000;">Next page</span><span style="color: #0000FF;"></</span><span style="color: #800000;">a</span><span style="color: #0000FF;">></span><span style="color: #000000;"><br /></span><span style="color: #0000FF;"></</span><span style="color: #800000;">body</span><span style="color: #0000FF;">></span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>Yuck! See how it mixes HTML, CSS and JavaScript into one file? Unfortunately this is what I see a lot of and, I’m ashamed to say, even do myself because it is easy to do. But then I’ll run into problems like how to test or debug that JavaScript. Take the example of the hardcoded <strong>onclick</strong> handler on that anchor tag; it’s a simple example but what if it was something more complicated? How could I test that when I find it doesn’t work like I expected?</p><br /><p>So instead I’ve tried to <a href="http://codecraftingblueprints.com/separation-of-concerns/">decouple the parts of the webpage</a> into a file each for HTML, CSS and JavaScript as nearly every web developer recommends. From this I’ve found it is now easier to edit and view my work; if I want to change the style of an element I go to my CSS file and not hunt for it in the monolithic file and similarly if I need to make a code change I update the script file and reload.</p><br /><h3>jQuery</h3><br /><p>OK, now I’ve got my code separated from everything else so now I can just focus on the functionality of the page, but how do I do <em><insert cool fancy feature here></em>? On it’s own JavaScript doesn’t provide a lot for you. Sure, I can use <a href="https://developer.mozilla.org/en-US/docs/DOM/document.getElementById">getElementById()</a> to find various parts of the page but after that do I then write a huge amount of code to do a relatively simple thing? No, I would use one of the bazillion JavaScript frameworks out there. To my mind <a href="http://jquery.com/">jQuery</a> is the top framework that everyone thinks of.</p><br /><p>I spent about a week of playing around with jQuery and using selectors and effects to manipulate the page, calling back to the server to process some JSON data and so on. As a newbie I did have to search around on the internet quite a bit to figure out how to do some simple things but the advantage of jQuery is that, because it is so prolific, there are tons of resources and samples out there to use.</p><br /><p>All in all I now can’t imagine trying to do anything in JavaScript now without using jQuery as it just makes things so much simpler.</p><br /><h3>JavaScript IntelliSense</h3><br /><p>I will freely admit that I completely rely on IntelliSense when writing .NET code. Why bother memorising thousands of APIs when a simple list can show you what is available? IntelliSense works brilliantly for statically typed languages but JavaScript is a dynamic language; at any point during execution the floor could potentially be pulled up beneath you and the API you thought was available could be changed. The dynamic nature of JavaScript is definitely a positive in a lot of cases but not when it comes to trying to discover what APIs are available, going back to relying on *shudder* reading documentation.</p><br /><p>As it turns out though Visual Studio now has a way of trying to provide IntelliSense some information when writing JavaScript code by including <a href="http://blogs.msdn.com/b/webdev/archive/2007/11/06/jscript-intellisense-a-reference-for-the-reference-tag.aspx">reference comments</a> in your file. These seem to work a little like import statements or C-style <em>#include</em> instructions but instead of pulling in code dependencies it looks for source code commenting and adds that information to IntelliSense. I tried it on jQuery and suddenly I can see everything that jQuery is capable of. Amazing!</p><br /><p>Having this in JavaScript is such a big time saver for me because:</p><br /><ol><br /><li>It saves round-trips to reading documentation and determining what each function is and what it requires. A simple tooltip which shows what parameters are needed and what they do is a great help to me. <br /><li>It helps a lot in <em>discovering</em> the APIs. jQuery as an example has lots of functions available but how many? And what do they do? Sometimes just having a simple list of functions available is enough to make you wonder what one does and could end up helping you figure out your solution.</li></ol><br /><h3>Function Callbacks</h3><br /><p>And now onto some minor gripes I still have with JavaScript!</p><br /><p>One of the little annoyances I’m coming across, especially with jQuery’s constant need of function parameters, is that the syntax for creating a nameless function (or sometimes referred to as a <a href="http://stackoverflow.com/questions/16501/what-is-a-lambda-function">lambda function</a> in other languages) is particularly verbose. Here is what I mean:</p><br /><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:d944fd12-148e-4f96-8344-cc39a1fd7cfc" class="wlWriterEditableSmartContent"><pre style=" width: 727px; height: 95px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">$(document).ready(</span><span style="color: #0000FF;">function</span><span style="color: #000000;"> () {<br /> $(</span><span style="color: #000000;">"</span><span style="color: #000000;">.tag</span><span style="color: #000000;">"</span><span style="color: #000000;">).each(</span><span style="color: #0000FF;">function</span><span style="color: #000000;"> (index, element) {<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Do something here</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> });<br />});</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>Having to write the word <em>function</em> gets a bit tiring when doing it over and over again – especially as JavaScript can be minified, you would think that you would want something shorter to use. Whereas in C# using LINQ I could write something like this:</p><br /><div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:9f244b87-20a3-4276-a728-5941ee8db43f" class="wlWriterEditableSmartContent"><pre style=" width: 727px; height: 32px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">var results </span><span style="color: #000000;">=</span><span style="color: #000000;"> list.Where(x </span><span style="color: #000000;">=></span><span style="color: #000000;"> x.Age </span><span style="color: #000000;">></span><span style="color: #000000;"> </span><span style="color: #800080;">10</span><span style="color: #000000;">).Select(x </span><span style="color: #000000;">=></span><span style="color: #000000;"> x.Name);</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>Notice how this “fat arrow” syntax makes things more concise. It does appear though that <a href="http://css.dzone.com/articles/javascript-fat-city">this is being included in the ES 6 specification</a> so hopefully I will see this in JavaScript one day, I just wish it was now!</p><br /><h3>But It’s Still Not Working…</h3><br /><p>By biggest bug-bear with JavaScript though is still the fact that I can write lots of lovely code and it may still not work <em>and the browser won’t tell me it doesn’t work</em>! Rather than tell me anything useful it will simply ignore anything that won’t work and just silently carry on, leaving me bewildered as to why what I expect to happen doesn’t.</p><br /><p>Here is a typical conversation I end up having with my computer:</p><br /><p><strong>Me:</strong> OK, let’s run this and check my new feature works.</p><br /><p><strong>Computer:</strong> …</p><br /><p><strong>Me:</strong> Er, hello? Did you do anything? Nothing has happened.</p><br /><p><strong>Computer:</strong> Sorry, I can’t find that new function you wrote.</p><br /><p><strong>Me: </strong>But it’s in my source file right here!</p><br /><p><strong>Computer: </strong>Well it’s not in my cached version which didn’t update on the last page load.</p><br /><p><strong>Me:</strong> Oh right, the browser cache. *sigh* Let me clear it and reload.</p><br /><p><strong>Computer:</strong> Ah, now I see your new function!</p><br /><p><strong>Me: </strong>Great, but still nothing is happening.</p><br /><p><strong>Computer:</strong> Well no, I can’t find an element with an ID called “banner”.</p><br /><p><strong>Me: </strong>Er, that’s meant to be “Banner”. With an uppercase “B”.</p><br /><p><strong>Computer: </strong>Well if you can’t spell that’s your own fault. *snigger*</p><br /><p><strong>Me: </strong>*grumble* Fine… *fixes spelling* There, happy now?</p><br /><p><strong>Computer:</strong> No, now I can’t find your new function. Have you tried clearing your browser cache?</p><br /><p><strong>Me: </strong>*bangs head on table*</p><br /><p><em>…and so on.</em></p><br /><p>Unfortunately this feedback loop happens all the time with me. Perhaps it will improve with experience but at the moment I do end up getting frustrated that no useful developer information is conveyed to me when something goes wrong.</p><br /><h3></h3><br /><h3><strong>Conclusion</strong></h3><br /><p>Overall though I am starting to find JavaScript more useful now. When it is coupled with a powerful framework to assist you and you accept it for what it is and not try and compare it to another language I realise now that you can achieve quite a lot with it. Which is useful as it seems that we’ll all be using JavaScript for a long time to come.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com1tag:blogger.com,1999:blog-6872827378253370843.post-48198636105362499192013-03-12T13:43:00.001+00:002013-03-12T13:51:12.606+00:00Windows 8: Bringing the Desktop Back<p>In my <a href="http://inthecodingzone.blogspot.co.uk/2013/02/windows-8-tablet-os-stuck-in-desktop-era.html">last post</a> I talked about how I felt Windows 8 had pushed ahead too far into the tablet OS space and left the desktop era trailing behind. In essence there are millions of PCs/devices which are currently capable of running Windows 8 yet are not designed for the brave-new-world interface that is the Modern UI. I did say at the end of that post however that I would suggest ways of improving the situation and this is what this post will be all about.</p> <p><em>Disclaimer: I am but a humble software developer expressing my own opinions here. I do not work for Microsoft and definitely have no sway in how Microsoft builds its products. I am also not an expert in operating system design and architecture and cannot vouch for whether anything I say below is technically feasible – consider everything below a “wishlist” of what Windows 8 could be.</em></p> <p><em>This post also contains diagrams and mockups created with my own two hands so they might hurt your eyes – I would strongly suggest some protective eyewear before you continue reading.</em></p> <h3>Splitting Things Up</h3> <p>Microsoft took a gamble with Windows 8; they wanted it to be <em>the</em> operating system that could be installed on any device/system, small and large. Whereas in the past they tried to shoehorn the behemoth that is Windows onto a smaller form factor – see <a href="http://en.wikipedia.org/wiki/Windows_Mobile">Windows Mobile</a> for an example – this time they are working the other way around, refining their Modern UI concepts on small devices first and then scaling up to larger systems.</p> <p>The problem I see with this though is that a full-fledged PC and a tablet are not the same; the “windows” concept works well on a PC and the fullscreen, one-app-at-a-time concept works well on a tablet. But Windows 8 tries to do both at once and then the inconsistencies appear; some apps appear in multiple windows on the desktop while some <em>must</em> take up the entire screen and hide everything else behind it. </p> <p>Ultimately these two ideologies don’t play well together. Apple, on the other hand, have two operating systems - <a href="http://www.apple.com/uk/osx/">OS X</a>, their full computer operating system and <a href="http://www.apple.com/uk/iphone/ios/">iOS</a> which is their phone/tablet operating system. Both cater to their target devices by only doing what is appropriate on each device with some room for crossover. It is this idea that I think should have been done for Windows but in this case possibly have one OS for each target device – phone, tablet and PC – all running a core Windows system.</p> <p>Because Microsoft loves to make beautiful architecture diagrams how about I have a stab at one to demonstrate what I mean:</p> <p><a href="http://lh4.ggpht.com/-0BZ3gyin5oU/UT8w-oqq_GI/AAAAAAAAAQA/LCZA_VaQUho/s1600-h/Architecture3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Architecture" border="0" alt="Architecture" src="http://lh5.ggpht.com/-HUQDSSoPcV8/UT8xAArNOzI/AAAAAAAAAQI/6CmiUB4rwKg/Architecture_thumb1.png?imgmax=800" width="644" height="402"></a></p> <p>Please bear in mind that this is not very complete and probably laughable but basically I see things working as:</p> <ol> <li>Defining the <strong>Windows Core</strong> operating system which would contain everything that every other Windows-branded OS requires at a minimum e.g. the kernel with process multi-tasking, input (including touch), output, networking, graphics and even the new Modern UI stack. <li>Then have the <strong>Windows Phone </strong>OS be based off of the <strong>Core</strong>. This would be the smallest OS provided due to the hardware constraints of a phone device but would build upon the core OS to include phone services e.g. SMS. <li>Then have the <strong>Windows Tablet</strong> OS be based off of the <strong>Core</strong> and build upon it to provide enough for a tablet device. Effectively this would be what the Windows 8 Modern UI would become. <li>Finally have the <strong>Windows Desktop</strong> OS be based off of the <strong>Core</strong> and complete the picture; this would provide the full package of components including legacy Windows support (which phones and tablets do not need).</li></ol> <p>Note there is already the concept of a “core” operating system – Microsoft developed <a href="http://en.wikipedia.org/wiki/MinWin">MinWin</a> to disentangle all the dependencies Windows has on its sub-systems and produce a minimal version of the OS to base everything else on – but this idea would take it further. As a lot of the future of Windows is being tied together it makes sense to me to include all the common components into one core system and then build upon them where it makes sense. This means that the Phone OS can focus on just being a smartphone whilst the full Desktop OS can focus on being the productivity powerhouse it used to be.</p> <p>I also see nothing wrong with including modern concepts into the core OS such as the Modern UI stack or touch inputs – although desktop PCs today may not make much use of them in the future they certainly could.</p> <p>So that is how I would split them up, but what would each one look like?</p> <h3>Windows Phone</h3> <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://cdn-static.cnet.co.uk/i/c/blg/cat/mobiles/windows-phone-8-availability-1.jpg"></p> <p align="center"><font size="1">Image courtesy of <a href="http://crave.cnet.co.uk/mobiles/windows-phone-8-availability-whos-selling-the-first-phones-50009636/">CNET UK</a></font></p> <p>This one is simple to define as it already exists. When I first got a Windows Phone 7 device I was actually quite impressed that Microsoft almost nailed the entire thing on the first try – thereby breaking their usual “3rd release is best” cycle. And as someone who has used it for a couple of years now I think it works pretty well when considered it is used for things like phone calls, staying connected to your friends and doing things on-the-go. So my thinking is just leave this one be and that is the Phone OS sorted. Next?</p> <h3>Windows Tablet</h3> <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://res2.windows.microsoft.com/resbox/en/windows/2012-win8ga/c8d8763d-f1a4-4533-9f06-1b827d059236_22.jpg"></p> <p align="center"><font size="1">Image courtesy of <a href="http://windows.microsoft.com/en-us/windows-8/new-look">Microsoft</a></font></p> <p>This one is also quite simple as well because this would be what Microsoft has been trying to push onto us since Windows 8 was first shown to the world. Basically the Tablet OS would be the new Start Screen and Modern UI apps - no desktop or legacy at all. However, there are a couple of things I would change to make it the tablet OS it should be. </p> <p>First of all I think the <a href="http://www.guidingtech.com/10146/windows-8-charm-bar-introduction/">Charms bar</a> should just be ditched as I don’t see any point to it. I think it is meant to show that every app has the capability of several core concepts – <em>Search</em>, <em>Share</em>, <em>Devices</em> (which I’ve never used so don’t even know what this is for) and <em>Settings</em>. But the problem I see with it is that not every app ever developed has to include these charms as sometimes it just does not make sense. Let’s take the example of a simple calculator app. So how many charms would we need for this to function?</p> <ul> <li><em>Search</em> is useless since there isn’t a lot of content to search for <li>I don’t particularly feel the need to <em>Share</em> my calculations on Facebook <li>I don’t really need to print anything usually so <em>Devices</em> isn’t required <li>Calculators are not that complicated so I can’t see too many <em>Settings</em> being needed either</li></ul> <p>Which means that this app would not require the Charms bar at all – selecting each charm in turn would result in me being told that this function is not available, something I would have to actually click through to find out.</p> <p>Instead, why can’t we just resort back to some tried-and-true user experience conventions that have been built up over the past couple of decades? For instance, everyone now knows that a rectangular box with a magnifying glass next to it is a “search box” where you can search for things, so why can’t Modern apps simply use the convention too – it’s not like there is a lack of screen estate in some cases.</p> <p><strong><a href="http://lh4.ggpht.com/-Y8T_A4nqJFI/UT8xBE_En2I/AAAAAAAAAQQ/vgkjovdc3Fw/s1600-h/Store%25255B3%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="Store" border="0" alt="Store" src="http://lh3.ggpht.com/-ubX8L3RJvOo/UT8xB4uAaUI/AAAAAAAAAQY/zEoGNu3acGI/Store_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></strong></p> <p align="center"><font size="1">The Windows Store app now with a search bar to clearly show that you can search for apps</font></p> <p>Likewise every website under the sun now has all sorts of “share” buttons littered over their pages, so we could also have Modern UI apps just add a “Share” button when it is appropriate to do so.</p> <h3>Windows Desktop</h3> <p>Now we get the the crux of this post, sorting out the Desktop. I highlighted a few issues I had with the Windows 8 desktop as it is now and the main issue was that every Modern app <em>must</em> be made fullscreen. Now my idea around this problem is simple: put Modern apps in windows again and let the user organise/resize them to how they want them to be. But it turns out <a href="http://www.neowin.net/news/stardock-reveals-modernmix-run-and-resize-modern-windows-8-apps-on-the-desktop">someone else has already thought of this</a>; <a href="http://www.stardock.com/?from=header">Stardock</a> are developing software which does just this called <a href="http://www.stardock.com/products/modernmix/index.asp">ModernMix</a>.</p> <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://www.stardock.com/products/modernmix/images/features/screenshots/screenshot_2.jpg" width="640" height="401"></p> <p align="center"><font size="1">An example of how I think desktop should handle Modern apps and what ModernMix is already capable of. Image courtesy of <a href="http://www.stardock.com/products/modernmix/features.asp">Stardock</a></font></p> <p>To me this feels like the best fit for the desktop – Microsoft could still deploy the new Modern UI apps which use the newer <a href="http://en.wikipedia.org/wiki/Windows_Runtime">Windows RT</a> technology but not at the expense of what came before it. Remember, Windows is all about building on what already exists. Users would get better, modern applications without sacrificing their own productivity or choices.</p> <p>And while we’re still removing things let’s get rid of those pesky <a href="http://forums.lenovo.com/t5/Windows-8-Knowledge-Base/What-are-Windows-8-hot-corners/ta-p/1004589">“hot-corners”</a>. At the moment if you want to see the Start Screen, switch applications or view the Charms bar then with a mouse you can move the pointer into one of the screen “hot” corners and the appropriate action will pop-up. Except that these hot-corners are annoying – it feels so slow and cumbersome to move the mouse all the way to the end of a screen, wait for something to appear and then click on it, which is why I avoid them like the plague and use keyboard shortcuts instead. Simply put the Start button back – which can trigger the Start Screen if Microsoft insist – and that’s all that is needed really.</p> <p>So now we’ve removed the dud features of the desktop, how can we progress it forward? For a start if Microsoft are committed to this new Modern UI/UX then they should start updating their apps and control settings to use it. This can allow them to start thinking about how to integrate touch controls to important Windows features ready for the future.</p> <p>One part of Windows 8 I do really like is the <a href="http://www.soluto.com/kb/windows-8/what-are-windows-8-live-tiles/">live tiles</a> that animate and show all sorts of live information for each application. How could that be applied to the desktop? Perhaps live tiles could be arranged on the desktop itself like regular desktop icons at the moment – a bit like widgets but at least tiles can be organised better.</p> <p><strong><a href="http://lh5.ggpht.com/-RdG48TLk0bA/UT8xC9RmWUI/AAAAAAAAAQg/TdZdMIJoEdA/s1600-h/DesktopTiles%25255B3%25255D.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="DesktopTiles" border="0" alt="DesktopTiles" src="http://lh3.ggpht.com/-6BfK-FSm6LU/UT8xEPXL7aI/AAAAAAAAAQo/c1o5y3wHmvY/DesktopTiles_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></strong></p> <p align="center"><font size="1">A mockup of how Live Tiles could be placed onto the desktop</font></p> <h3>We Can but Dream…</h3> <p>These are some of my wild musings as to what Windows 8 <em>could</em> have been, though I imagine these will never come to fruition; once something is baked into Windows it stays there and Microsoft seem quite committed now to forging ahead with what they’ve got. I am hoping though that <a href="http://www.zdnet.com/microsofts-next-windows-blue-test-build-said-to-be-a-public-preview-7000011728/">Windows “Blue”</a> will try and address some of the usability issues with the desktop/Modern experience but we shall see.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-82784152442177965392013-02-27T14:15:00.001+00:002013-02-27T14:15:39.166+00:00Windows 8: A Tablet OS Stuck in the Desktop Era<p><strong><a href="http://lh5.ggpht.com/-imb45GimWno/US4U1_Or3EI/AAAAAAAAANk/nNEY8_taMYI/s1600-h/Start%25255B3%25255D.png"><img title="Start" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Start" src="http://lh6.ggpht.com/-r_lEVjH4QiA/US4U21f4yJI/AAAAAAAAANs/XFx-dL9xxAw/Start_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></strong></p> <p>It’s been a few months since I upgraded my laptop to <a href="http://windows.microsoft.com/en-us/windows-8/meet">Windows 8</a>. At the time Microsoft were letting you purchase the upgrade for around £25 which sounded like a bargain to me – my wife got it even cheaper at £15 due to purchasing a Windows 7 laptop recently. So I dutifully downloaded it, was amazed at how the installer just seemed to work (surely upgrading an OS should be more troublesome than this?) and set about using it for everyday use.</p> <p>So after a few months of use what is my overall opinion? While I find it perfectly usable I think Microsoft may have been a bit too ambitious trying to convert Windows from a big desktop OS to what is now primarily a tablet OS and the jump between the two is currently too large. Now I’m not saying it is a complete disaster – we’re not at <a href="http://readwrite.com/2008/07/11/the_vista_disaster_back_story">Vista levels</a> at all – as there are still quite a few things that I am happy with but given that my laptop has no touch inputs at all and the entire OS seems hell-bent on pushing these new Modern touch-enabled apps in your face then it leaves a user like me feeling a little left behind in this brave new world.</p> <p>But first let’s focus on the good parts of Windows 8 before I venture into the “could be better” points.</p> <h3>Performance</h3> <p>Windows 8 is fast, very fast sometimes. Whatever Microsoft did to the internals of Windows to make it fast enough on less powerful hardware has also paid dividends on more powerful hardware. A cold boot is faster than Windows 7, waking it up from a sleep state even better (it feels like around 10 – 15 seconds to me) – when I compare it to starting up my Windows 7 PC at work it feels like it takes an age to just get to the login screen now.</p> <h3>Live Tiles and the Start Screen</h3> <p>I own a Windows Phone 7 device so I’ve already grown accustomed to the UI intended for all future Microsoft products. I personally think that the <a href="http://www.pcadvisor.co.uk/opinion/windows/3417778/windows-8-live-tiles-explained/">Live Tiles</a> idea is probably one of the simplest, best and, dare I say it, most original ideas that Microsoft has come up with in a long while. Live Tiles act as both a shortcut to start an application but also as a widget which provides live information to you when you just stare at the Start Screen; information changes on it as you watch it to show you your latest emails, latest Facebook/Twitter mentions, photos etc. If you have a good enough set of apps installed your Start Screen can suddenly come alive with all kinds of information and I quite like waking up my laptop in the morning and quickly seeing how many emails I have.</p> <p>And speaking of the Start Screen I have no problem with it; many people got indignant over the loss of the Start Menu but frankly I haven’t missed it at all. It also comes with some nice bonuses such as being able to uninstall anything straight from the Start Screen, and the search functionality is far better than Windows 7.</p> <h3>Desktop Improvements</h3> <p>Despite the focus clearly being on the Modern UI the existing desktop has seen a few new features too.</p> <p><a href="http://lh6.ggpht.com/-oOTUHA2M07I/US4U3Qza6EI/AAAAAAAAAN0/z-QIoDkUwW4/s1600-h/TaskManager%25255B3%25255D.png"><img title="TaskManager" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="TaskManager" src="http://lh6.ggpht.com/-VO-npwCXS4A/US4U31REvuI/AAAAAAAAAN8/0nj0lNuquko/TaskManager_thumb%25255B1%25255D.png?imgmax=800" width="644" height="429"></a></p> <p>The Task Manager is now something I love rather than something I use to kill non-responsive processes. The detailed view can show you the CPU, disk, memory and network usage of every process running which provides you far more information than before. Checking network usage is actually incredibly useful – I had problems recently with the <a href="http://www.bbc.co.uk/iplayer/">BBC iPlayer</a> and used the Task Manager to confirm whether it was actually downloading anything or not.</p> <p><a href="http://lh3.ggpht.com/-Hm_hDxEWRJE/US4U4j4iJaI/AAAAAAAAAOE/L9LYkJ9y9MY/s1600-h/Explorer%25255B3%25255D.png"><img title="Explorer" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Explorer" src="http://lh5.ggpht.com/-J3lnipIIW9U/US4U5NoCj9I/AAAAAAAAAOM/jWoPfVpTRos/Explorer_thumb%25255B1%25255D.png?imgmax=800" width="644" height="389"></a></p> <p>The Windows Explorer has also seen some improvements such as a ribbon bar to replace the menus (though collapsed by default, I’m guessing due to all the complaints from various users during the consumer reviews) and much better handling of copy-paste operations such as detailed progress and resolving name conflicts.</p> <h3>OneNote MX</h3> <p><a href="http://lh4.ggpht.com/-bOEAJbA8dFo/US4U5kD7obI/AAAAAAAAAOU/UTduWMT25YY/s1600-h/OneNoteMX%25255B3%25255D.png"><img title="OneNoteMX" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="OneNoteMX" src="http://lh3.ggpht.com/-zU9VhaOhzS8/US4U6rPa4uI/AAAAAAAAAOc/XwV0PcSnB88/OneNoteMX_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></p> <p>Not a part of Windows 8 per se but I thought I would give this a mention; I love OneNote in Office and the <a href="http://apps.microsoft.com/windows/en-gb/app/onenote/f022389f-f3a6-417e-ad23-704fbdf57117">OneNote MX app</a> you can get from the Windows Store is probably one of the best examples of a Modern app I’ve seen yet. It’s not perfect – sometimes feeling a little like a prototype of what Office might become – but the fact that I can write my notes and have them sync to SkyDrive to later check on my phone/work PC makes it a fine example of how Microsoft is starting to think beyond the “single PC” ideology that has been governing Windows for decades, plus it is a great example of what you can achieve in a Modern app.</p> <h3>But…</h3> <p>So there are a few things I am happy with and I wouldn’t want to go back to Windows 7. But having said that there are still quite a few problems with it and they tend to revolve around the sudden shift in focus on making it into an operating system designed for every device imaginable.</p> <h3>Modern Apps</h3> <p>I’m going to make a sweeping generalisation here: nearly all Modern apps suck! OK, maybe that is a bit too harsh so let’s try to break it down as there are several areas to this.</p> <p>I have no problem with the “Metro”/Modern UI style as I generally quite like the simplicity of it all; on a phone it works quite well, and I imagine a tablet would be the same. But for a widescreen monitor things can tend to look a little sparse with a lot of empty space, particularly since Windows 8 forces all Modern apps to be full-screen. Also it is a style which allows less artistic people (e.g. developers like me) to be able to make something that generally looks quite good and hopefully more consistent with the rest of Windows but this is a double-edged sword; a lot of Modern apps I’ve seen so far are devoted to lists/grids of rectangles with some text in it so they are never that pretty to look at.</p> <p><a href="http://lh5.ggpht.com/-Fa6Xm6pD6H8/US4U7U5dX5I/AAAAAAAAAOk/wyjhtCLYMEc/s1600-h/SkyDrive%25255B3%25255D.png"><img title="SkyDrive" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="SkyDrive" src="http://lh3.ggpht.com/-mDMa_xnwx7M/US4U76ZJj2I/AAAAAAAAAOs/KffndOlNG5w/SkyDrive_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></p> <p align="center"><font size="1">This is what my SkyDrive app looks like – pretty sparse and flat wouldn’t you say?</font></p> <p>These apps are also the latest in a long line of developer technologies that Microsoft tends to flaunt every few years; this time <a href="http://en.wikipedia.org/wiki/Windows_Runtime">Windows RT</a> is the latest hotness. As all these Modern apps are basically version 1.0 then it becomes very clear that this is a platform that needs time to grow and develop. Currently many apps I’ve seen can be very basic or at worst buggy. <a href="http://apps.microsoft.com/windows/en-gb/app/metrotwit/aa115aae-09e1-48de-95a1-35d77d23c9a0">MetroTwit</a> for instance never seems to be able to load my Twitter timeline, something I would have thought quite crucial given what it is designed for; as a result I uninstalled that almost immediately.</p> <p>The fact that all Modern apps have to run fullscreen may make sense on a tablet where screen estate is limited but I really cannot see the point on a full-blown PC. At my workplace I have two monitors so I would be limited to viewing two apps at once whereas previous Windows versions would allow you to have as many windows open as you wanted and organised however you wanted. I mean, do I really need to devote an entire monitor just to see my Twitter feed? At the moment the Modern apps I do use I have to constantly switch between with Alt-Tab to get anything done.</p> <p>Touch input is the main draw for Modern apps – but only if your hardware supports it. Using a mouse and keyboard is possible but not the best, in the same way that touch is not ideal for using the Desktop. Given that most new PCs would be supplied with Windows 8 by default now but not necessarily the hardware to use it for it's ultimate potential this becomes even more frustrating.</p> <p>But probably the biggest problem with Modern apps so far is not related to technology or usability but one simple question: what are they for? Every single Modern app I’ve seen has a very clear focus, which is to act as a frivolous, content-spewing machine; why not check Facebook or Twitter or news or weather or anything that is actually not very important to your life or work. Can you honestly see a line-of-business Modern app existing as things currently stand? I can’t. Given that Microsoft have spent so long trying to keep their enterprise customers happy it seems they have now switched sides rather abruptly and are now too focused on the casual user instead, rather than find a happy medium.</p> <h3>Windows Store</h3> <p>Fine, lets assume that you do find some good Modern apps – that means you need to find and install them somehow, which is where the Windows Store comes in. Except that this is also a terrible Modern app in itself.</p> <p><strong><a href="http://lh6.ggpht.com/-TYeARb0IgZ0/US4U8q_ZSJI/AAAAAAAAAO0/gjODMkt0mlg/s1600-h/Store%25255B3%25255D.png"><img title="Store" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Store" src="http://lh6.ggpht.com/-WGfvTUmH-OY/US4U9XjC1aI/AAAAAAAAAO8/FhHPuSj54ig/Store_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></strong></p> <p>Take a look at the screenshot above; what attracts you to getting, or even buying, any apps? Do any of them jump out at you? Of course not, they are all flat squares with possibly a single image and their name, basically an example of where the “Metro”/Modern style fails. </p> <p>I’m no expert in commercial dynamics but if I went into a store to buy something I would expect to be bombarded with colours, images and banners trying to advertise everything under the sun – what we have here instead is everything hidden away and not showed off to its full potential. There may well be some truly excellent apps hidden away in there but Microsoft are simply not marketing them well enough. Since these are all you can install on a tablet device I would have expected something with a bit more flair to try and entice people to parting with their money.</p> <p><a href="http://lh3.ggpht.com/-ZR6z4tfmdNs/US4U930tN_I/AAAAAAAAAPE/_4SZ-eCn0bA/s1600-h/StoreSearch%25255B3%25255D.png"><img title="StoreSearch" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="StoreSearch" src="http://lh4.ggpht.com/-y4SfSLHSDfI/US4U-rwvNfI/AAAAAAAAAPM/0BX-42QnbVE/StoreSearch_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></p> <p align="center"><font size="1">Searching through the Store is not a very informative experience either</font></p> <p>There are also technological problems too; the Store app is incredibly buggy. I’ve encountered warnings saying that internet connection is lost constantly and apps failing to install for some bizarre reason. If this is the only way into getting any software onto your device the Store should be as rock-solid as possible. It also poses this question: if the Store app manages all your Modern app updates how does the Store itself get updated?</p> <h3>General OS Gripes</h3> <p>Finally there are some general niggles that bother me.</p> <p><a href="http://lh4.ggpht.com/-mX_T1ViC08c/US4U_dmcTXI/AAAAAAAAAPU/pBSWFfgWrj4/s1600-h/Charms%25255B3%25255D.png"><img title="Charms" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Charms" src="http://lh5.ggpht.com/-9JiGQ1WVc0Q/US4VATOliwI/AAAAAAAAAPc/KA4iKZQD0BI/Charms_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></p> <p>The Charms bar I cannot see any point in, even on a tablet. When you swipe in from the right-hand side you are now presented with a bar of “charms”, or extremely common operations that are now built into the OS, such as Search, Share and Settings. Search and Settings I get – nearly everything these days require these functions – but Share simply looks like a symptom of the times we live in; perhaps there will be clever uses of this charm but for now all I can see it being useful for is to share things to Facebook/Twitter. If I’m working in Microsoft Office do I really need to tweet to everyone that I’m working on a PowerPoint presentation? I can see some point to sharing though but why not just limit it to the applications that require it rather than provide a great big button directly in Windows itself?</p> <p>Windows 8 is also clearly a transitionary OS as is evident by having both the “Modern” Windows and the “legacy” Windows but this divide can also be confusing as there are now inconsistencies between how to do things. For example:</p> <ul> <li>Windows 8 has a fullscreen settings screen but this is not enough to control everything so sometimes you will have to dive back into the Control Panel (which has not been “modernised”). And interestingly some settings are duplicated for no particular reason – setting up a Homegroup can be done exactly the same in the Control Panel or the new setting screen, so why have both? <li>The Desktop can also view the charms bar yet these become even more useless since the Desktop was not built to use any of them. If that is the case why show it at all? <li>The Desktop shows the time, date and items like network connectivity and battery power in the taskbar. The Modern UI hides all of those useful indicators until you make the charms bar visible.</li></ul> <p><a href="http://lh6.ggpht.com/-OIGKZvKwx30/US4VBaqGpwI/AAAAAAAAAPk/xADrCI6-ScQ/s1600-h/Inconsistency%25255B3%25255D.png"><img title="Inconsistency" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Inconsistency" src="http://lh5.ggpht.com/-w5SmClVMid4/US4VCcgNkRI/AAAAAAAAAPs/gck23AgqCBk/Inconsistency_thumb%25255B1%25255D.png?imgmax=800" width="644" height="364"></a></p> <p align="center"><font size="1">An example of UI inconsistency – I’m in the old Desktop yet now I’m also in the Modern UI too?</font></p> <p>Ironically in this touch-enabled future keyboard shortcuts have become the only way I can actually get to anything quickly these days; shortcuts like Win+C are far easier to perform that hovering my mouse cursor into a “hot-corner”, dragging down slightly and clicking on the charm I need. Also, as an experiment, get a brand new user who’s never seen a Windows 8 machine before to try and figure out how to close a Modern app or even how to switch off the device – see how long it takes them before they give up. I had to <a href="http://www.geek.com/articles/chips/geek-101-how-to-close-apps-in-windows-8-20121121/">look these up online</a> before I could figure it out and even now closing a Modern app is not intuitive – Alt-F4 to the rescue!</p> <h3>Is it Really That Bad?</h3> <p>No, of course not. Like I’ve already said I do like Windows 8 but mainly from a <em>desktop user</em> perspective. And while I do have a few Modern apps that I like overall I’m just not impressed with them.</p> <p>The problem I see is that Microsoft took a big gamble trying to get Windows to work in such a way that it is suitable for any device, be it a phone all the way up to a PC, but I’m not so sure this gamble is paying off. Each device type is meant to cater to a particular set of requirements; phones and tablets are not meant to be processing powerhouses and are meant to be used on-the-go so making lots of content-consuming apps makes sense for those devices. PCs and laptops are meant to be more powerful and allow more finer control so it makes more sense to develop more productive apps (like Office) for them.</p> <p>It may be that, one day, we are all using tablets for our computing needs so we need this OS which is touch enabled and easy to use but I don’t think that day has come yet and Microsoft have made that leap too fast too soon, leaving all of it’s users having to catch them up. Ultimately I’m starting to think that Apple may have had the right idea; build an OS for mobile devices and PCs but not both.</p> <p>Now I’m not one for criticism without at least trying to present some suggestions for improvement. After all, everyone has their own opinion on how things should work. I intend to write up how I personally think Windows could have been done whilst also moving it forward but I will leave that for another post, so stay tuned for that.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-2394194766157259112013-02-20T16:49:00.001+00:002013-02-20T16:49:42.769+00:00Settling into Fatherhood<p>I’ve been quiet of late on my blog. That is because a couple of weeks ago this happened…</p> <p><strong><a href="http://lh3.ggpht.com/-MUQIrV5ODeM/UST-o71jbeI/AAAAAAAAAMU/sUKkxvyFudc/s1600-h/WP_000938%25255B4%25255D.jpg"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="WP_000938" border="0" alt="WP_000938" src="http://lh3.ggpht.com/-e7KdN1Z3m7Y/UST-pcrlDbI/AAAAAAAAAMc/PaUZZEtVOac/WP_000938_thumb%25255B1%25255D.jpg?imgmax=800" width="364" height="484"></a></strong></p> <p>I now have a daughter, Little L. Along with my 21-month old son, Big M, I’ve now reached my target family size!</p> <p>Having a second child actually makes you think back and compare how things were with your firstborn. For a start, like everyone tells you, the second one is easier in that you don’t worry so much about things; all that training, stress and exhaustion you encountered during your firstborn’s arrival puts you in pretty good stead for handling a second baby. All sorts of things like changing nappies (which I still have to do for Big M), feeding them, burping them, bouncing up and down to sooth them, it all comes back to you. And the sleepless nights somehow seem more manageable at the moment; I now know that eventually I will get my sleep back so that is a good way of looking at things.</p> <p>My paternity leave this time was also much more enjoyable. During my time off work looking after Big M I basically experienced this for two weeks:</p> <p>“WHAT AM I DOING? WHY IS HE STILL CRYING? HOW IS IT POSSIBLE TO SURVIVE ON THIS LITTLE SLEEP? AM I LOSING MY MIND?”</p> <p>Whereas with Little L it was like:</p> <p>“Oh, she’s crying. Let’s cycle through the changing-feeding-soothing cycle to see if that settles her”</p> <p>It left me feeling that I could actually bond with my family rather than worrying about all the little details.</p> <p>The only challenge I would say I’ve found is having to deal with a hyperactive toddler and a newborn at the same time. In general Big M is very interested in his little sister – no jealousy appearing yet – but he also hasn’t got a clue how to be gentle with her. One minute he can gently kiss her on the head, the next he can give her a big smack. Trying to get him to understand the difference at such a young age is difficult but he is slowly getting there. And I’m sure when Little L is older she’ll get her own back.</p> <p>Normal service will resume on this blog soon albeit a bit slower as I now have to write my posts during my lunchbreaks at work, so stay tuned. </p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-13483637106929746362013-01-31T13:49:00.001+00:002013-01-31T13:49:20.907+00:00GitHub for Windows: Git for Beginners<p><a href="http://git-scm.com/">Git</a> is all the rage these days; you can’t move around the internet without bumping into all kinds of comments saying how Git is amazing, distributed SCM systems are the future, and so on. I myself come from the age of Visual SourceSafe (<em>shudder</em>) and TFS where all source-controlled content is locked down until changes need to be made. I have no major complaints about how TFS works – it may be a bit of a beast but it does the job well enough for me – but I can also see the benefits of a distributed SCM system where changes can be made offline and “pushed” to a central repository when ready, which is where Git shines.</p> <p><a href="https://github.com/">GitHub</a> has also helped its popularity by bringing a primarily Linux-based system to the masses, including the Windows crowd. Having said all this Git also has its drawbacks too:</p> <ol> <li>It is entirely command-line based – which is to be expected given its Linux heritage – which initially tends to put some Windows developers off. Now <a href="http://inthecodingzone.blogspot.co.uk/2012/03/beauty-of-console-applications.html">I’m not averse to using command-line tools</a> but sometimes it is just easier to see something visual in front of you. <li>I also hear that there can be some confusing aspects of Git, such as features that can be used in a variety of ways using various command-line switches. Memorising the commands you need on a daily basis can introduce a bit of a learning curve.</li></ol> <p>Even so I wanted to try my hand at using it, especially as I had a small project in mind that I wanted to keep track of. But as a complete newbie how do I start? I could follow <a href="https://help.github.com/articles/set-up-git">these steps outlined by GitHub</a> and fiddle around with all kinds of settings and SSH keys, or I could let GitHub help me by using their brilliant client front-end <a href="http://windows.github.com/">GitHub for Windows</a>.</p> <p>What is GitHub for Windows? As their website says it’s “the easiest way to use Git on Windows. Period.” It is a desktop application which provides some core features that you would typically use Git for but in GUI form (such as committing changes and branching/merging) but additionally installs all the Git tools you would need anyway; if the GUI can’t do something you can always drop back down to the command-line tools (and it will even help set up your shell to assist you). At the moment I’m just using it for local repositories but I also expect the integration with GitHub itself to be top-notch.</p> <p>Let’s go over the main features I’ve currently been using.</p> <h3>Installation and Setup</h3> <p>I can’t think of many development tools which are this easy to setup. In the past I imagine that a lot of effort would have been made to download all the Git tools (possibly even having to build them from source), set up environment variables, use various other tools to create SSH keys and so on.</p> <p>Not so with GitHub for Windows. It all comes bundled as a <a href="http://msdn.microsoft.com/en-us/library/t71a733d(v=vs.80).aspx">ClickOnce</a> application; I simply downloaded it, installed it and it setup up everything I would need in the space of about 5 minutes. After that all I had to do was sign-in with my GitHub account and I was ready to roll.</p> <h3>Create a Local Repository</h3> <p><a href="http://lh3.ggpht.com/-2uh_pe3c620/UQp2RObMncI/AAAAAAAAAK0/MrV4oDei6UU/s1600-h/Main%25255B3%25255D.png"><img title="Main" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Main" src="http://lh3.ggpht.com/-KePEN_Xg0NE/UQp2SKQ8r3I/AAAAAAAAAK4/RrKYAEZmGFQ/Main_thumb%25255B1%25255D.png?imgmax=800" width="644" height="368"></a></p> <p>You can of course connect to various repositories that are on GitHub but for the moment I wanted to focus on doing some local development on my own project; I’m not ready to make it public just yet. Again this is simple and straightforward; all I did was create a new repository under the <strong>local</strong> section and filled in a name and description of it. GFW (as I’m going to now abbreviate it as) then set up those special “.git” folders and initial files and I was ready to commit changes.</p> <h3>Committing Changes</h3> <p><strong><a href="http://lh6.ggpht.com/-IU-h0TqDJOs/UQp2TA7_VGI/AAAAAAAAALE/lZYT-LMw5-g/s1600-h/Commit%25255B3%25255D.png"><img title="Commit" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Commit" src="http://lh6.ggpht.com/-VFZnUIYdtAo/UQp2T0QIenI/AAAAAAAAALM/BANc6Nr17xU/Commit_thumb%25255B1%25255D.png?imgmax=800" width="644" height="368"></a></strong></p> <p>This is actually the bit I’m most impressed with. I can go to Visual Studio and make all the changes I want to, then come back to GFW and it will have seen what has been changed since the last commit, providing you with a mini-diff window for each change made. Even if you delete a file that used to be in the repository GFW will notice it and remove the file on the next commit. Committing changes suddenly becomes incredibly easy and doesn’t require much thinking about.</p> <h3>Branching and Merging</h3> <p><strong><a href="http://lh5.ggpht.com/-r2m1X73sKzI/UQp2UgsodCI/AAAAAAAAALQ/1V4NTE089Bw/s1600-h/Branches%25255B3%25255D.png"><img title="Branches" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Branches" src="http://lh4.ggpht.com/-nFdtqK_2V6k/UQp2VbHUIqI/AAAAAAAAALc/S9C6ZvqE890/Branches_thumb%25255B1%25255D.png?imgmax=800" width="644" height="368"></a></strong></p> <p>Branching and merging is something that Git is apparently very good at; I had a read though <a href="http://git-scm.com/book/en/Git-Branching">this online book</a> which explained really well how branches work in Git. GFW can handle branches very easily, simply create as many new branches as you want and easily switch between them using the menu.</p> <p>To merge branches together is also simple; GFW has a branch manager window which shows all the active branches in the repository. To merge simply drag the branches to merge to the bottom of the window and hit the “Merge” button. It really couldn’t be easier.</p> <h3>Tagging</h3> <p><strong><a href="http://lh6.ggpht.com/-HlOTW_RgQdE/UQp2WrVNnQI/AAAAAAAAALk/3CDwxoMiX1s/s1600-h/Tools%25255B3%25255D.png"><img title="Tools" style="border-left-width: 0px; border-right-width: 0px; background-image: none; border-bottom-width: 0px; float: none; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; border-top-width: 0px; margin-right: auto" border="0" alt="Tools" src="http://lh4.ggpht.com/-yeFIXbItueI/UQp2Xh-bLfI/AAAAAAAAALo/tiigGArJR4M/Tools_thumb%25255B1%25255D.png?imgmax=800" width="644" height="368"></a></strong></p> <p>Ah, and now we hit something that GFW can’t do on it’s own. It is generally good practice to tag releases of projects so you can easily find them in your commit history, but GFW does not support tags out-of-the-box.</p> <p>Not to worry though, because we can simply use the command-line tools to do that. GFW allows you to open a shell setup for your repository – in my case it opens Powershell using some extra Git extensions. Then I can do something like:</p> <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:a002468e-6bc8-4779-83a8-07c0061de746" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 98px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #008000;">#</span><span style="color: #008000;"> Add a tag</span><span style="color: #008000;"><br /></span><span style="color: #000000;">git tag </span><span style="color: #000000;">-</span><span style="color: #000000;">a </span><span style="color: #800000;">"</span><span style="color: #800000;">NewTag</span><span style="color: #800000;">"</span><span style="color: #000000;"> </span><span style="color: #000000;">-</span><span style="color: #000000;">m </span><span style="color: #800000;">"</span><span style="color: #800000;">This is a new tag!</span><span style="color: #800000;">"</span><span style="color: #000000;"><br /><br /></span><span style="color: #008000;">#</span><span style="color: #008000;"> View available tags</span><span style="color: #008000;"><br /></span><span style="color: #000000;">git tag</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>This is a great example of how, when the GUI does not support what you do, you can always go back to Git as it was meant to be used.</p><br /><h3>Start of a Beautiful Friendship</h3><br /><p>I haven’t been this impressed with a piece of software in quite a while. Not only does GFW ease a beginner like me into using Git on a day-to-day basis but it is actually one of the finest examples of a WPF application I’ve seen yet; it is fast, responsive and hasn’t failed me yet.</p><br /><p>I look forward to actually pushing my project to GitHub when the time comes!</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-85659965315196423932013-01-18T19:32:00.001+00:002013-01-18T19:32:14.459+00:00ASP.NET Websites and Sub-Folders in Project Output Paths<p>This will be a quick post but I wanted to get it out there while I remembered.</p> <p>Yesterday and this morning at work I was faced with an unusual problem. One of our ASP.NET MVC websites, which worked perfectly fine until now, decided it did not want to compile. Specifically it was the Razor engine which wasn’t happy; the actual project would compile fine in Visual Studio but as soon as I ran it a runtime compiler error would happen immediately because a collection of Razor helpers could not find our own assembly as a reference. What’s going on?</p> <p>So I searched and searched and found all sorts of questions on StackOverflow explaining how to add an assembly reference to the Web.config file and add it to the specific Razor Web.config settings but that wasn’t helping me at all; it simply refused to run.</p> <p>Out of sheer frustration I started comparing the project folder to a previous version to see what could have possibly changed to break it and the only difference I found was that another developer had checked in a change which would compile the project output from “bin\” to “bin\{Configuration}”. Surely that can’t be the cause, can it?</p> <p>Actually it was, and this blog post by <a href="http://adammcraventech.wordpress.com/">Adam Craven</a> explained why:</p> <p><a title="http://adammcraventech.wordpress.com/2011/05/04/intellisense-in-razor-for-custom-types-and-helpers/" href="http://adammcraventech.wordpress.com/2011/05/04/intellisense-in-razor-for-custom-types-and-helpers/">Intellisense in Razor for Custom Types and Helpers</a></p> <p>Now most Visual Studio project templates will setup the output path of the compiled files to be “bin\{Configuration}”, which sounds sensible to me. Apparently ASP.NET projects don’t do this because the ASP.NET runtime will not find your own assemblies for some reason – as I said, the blog post above explains it better than I could.</p> <p>So all in all a frustrating morning was resolved simply by changing the project output path. It’s funny how the simplest thing can completely break your code.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com1tag:blogger.com,1999:blog-6872827378253370843.post-34987446790681505632013-01-16T21:03:00.001+00:002013-01-16T21:03:18.868+00:00Unit Testing ASP.NET MVC Views<p>I have successfully jumped onto the <a href="http://www.agiledata.org/essays/tdd.html">Test Driven Development (TDD)</a> bandwagon now and loving it. Over the last 6 months I’ve been trying to incorporate it wherever I can; my code at work is now starting to gain a number of unit tests within a codebase that initially I thought would be difficult to do automated testing on.</p> <p>Recently I’ve started a personal project using <a href="http://www.asp.net/mvc">ASP.NET MVC</a> – I haven’t had much experience of MVC, only Web Forms, and wanted to expand my knowledge on .NET web development. I’ve heard many stories how ASP.NET MVC was designed from the ground up to be very easy to test so I jumped at the chance of reading up and experimenting with it. One bonus as well is that this would be all-new code; the one thing I’ve learned about TDD is that it works brilliantly with a clean-slate, with legacy code it requires quite a bit more work and slower iterations in order to not break what you’ve already got.</p> <p>For most of the MVC framework I could clearly see how you could apply unit testing to your code as it focuses a lot on plain objects. One of the things I couldn’t initially get my head around though is testing controllers and verifying that views returned were correct.</p> <p>Take this example of a simple controller:</p> <div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:32e26b14-5cd2-4f6f-a10d-5330f1a1adb3" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 224px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">class</span><span style="color: #000000;"> AccountController : Controller<br />{<br /> </span><span style="color: #0000FF;">public</span><span style="color: #000000;"> ActionResult Index(</span><span style="color: #0000FF;">int</span><span style="color: #000000;"> id)<br /> {<br /> Account account </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> Account()<br /> {<br /> Id </span><span style="color: #000000;">=</span><span style="color: #000000;"> id,<br /> Name </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #800000;">"</span><span style="color: #800000;">My Account</span><span style="color: #800000;">"</span><span style="color: #000000;"><br /> };<br /> </span><span style="color: #0000FF;">return</span><span style="color: #000000;"> View(</span><span style="color: #800000;">"</span><span style="color: #800000;">Index</span><span style="color: #800000;">"</span><span style="color: #000000;">, account);<br /> }<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>It is actually quite easy to write a unit test for this controller and action as, thankfully, controllers are not strongly tied to anything to do with HTTP requests or responses, so testing becomes as simple as:</p><br /><div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:ec972379-df7e-4af9-bc58-4bb3e9ae195a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 126px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">[Fact]<br /></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> IndexActionReturnsView()<br />{<br /> AccountController controller </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> AccountController();<br /> ActionResult result </span><span style="color: #000000;">=</span><span style="color: #000000;"> controller.Index(</span><span style="color: #800080;">42</span><span style="color: #000000;">);<br /> Assert.NotNull(result);<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>But at this point I got a little stuck. How do I know that the controller action returned the view that I wanted? Initially I was thinking only in terms of controller actions returning HTML output; how can we verify HTML text output in automated tests?</p><br /><p>The answer is you don’t, and actually the answer is a lot simpler and cleaner; we don’t verify the overall output, we simply verify that the view has the necessary information (i.e. model data) it needs to generate the HTML output (or whatever output format is required).</p><br /><p>This can be split up into several parts:</p><br /><h3>Check the View Name</h3><br /><p>One test can be defined to determine that the correct view was returned by checking the name of the view, such as below:</p><br /><div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:24d7284f-f73a-4cff-8027-8413099ba57a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 207px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">[Fact]<br /></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> IndexActionReturnsCorrectViewName()<br />{<br /> AccountController controller </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> AccountController();<br /> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Cast the result of the action to a ViewResult, this will then provide<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> view information for the test to confirm</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> ViewResult result </span><span style="color: #000000;">=</span><span style="color: #000000;"> controller.Index(</span><span style="color: #800080;">42</span><span style="color: #000000;">) </span><span style="color: #0000FF;">as</span><span style="color: #000000;"> ViewResult;<br /> <br /> Assert.Equal(</span><span style="color: #800000;">"</span><span style="color: #800000;">Index</span><span style="color: #800000;">"</span><span style="color: #000000;">, result.ViewName);<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><p>One caveat I’ve found with this though is that in the controller you must <em>specifically</em> request which view you want; letting the MVC framework determine it by convention – based on the action name – doesn’t seem to work for some reason.</p><br /><h3>Check the View Model Type</h3><br /><p>The next test you can run is to ensure that the view returned was supplied with the correct model type, like so:</p><br /><div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:b44bc8d4-c8cc-4d9a-9168-eeeafc946c31" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 186px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">[Fact]<br /></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> IndexActionReturnsCorrectViewModelType()<br />{<br /> AccountController controller </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> AccountController(); <br /> ViewResult result </span><span style="color: #000000;">=</span><span style="color: #000000;"> controller.Index(</span><span style="color: #800080;">42</span><span style="color: #000000;">) </span><span style="color: #0000FF;">as</span><span style="color: #000000;"> ViewResult;<br /> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Test that the model object passed to the view was the correct <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> type</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> Assert.IsType</span><span style="color: #000000;"><</span><span style="color: #000000;">Account</span><span style="color: #000000;">></span><span style="color: #000000;">(result.Model);<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><h3>Check the View Model Data</h3><br /><p>Finally you can then test that the view returned was supplied with the correct model data, like so:</p><br /><div id="scid:9D7513F9-C04C-4721-824A-2B34F0212519:e774b39d-3e7b-4e07-b109-e9877b9aa8ce" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px; display: inline; padding-right: 0px"><pre style=" width: 726px; height: 224px;background-color:White;overflow: auto;"><div><!--<br /><br />Code highlighting produced by Actipro CodeHighlighter (freeware)<br />http://www.CodeHighlighter.com/<br /><br />--><span style="color: #000000;">[Fact]<br /></span><span style="color: #0000FF;">public</span><span style="color: #000000;"> </span><span style="color: #0000FF;">void</span><span style="color: #000000;"> IndexActionReturnsCorrectViewModelData()<br />{<br /> AccountController controller </span><span style="color: #000000;">=</span><span style="color: #000000;"> </span><span style="color: #0000FF;">new</span><span style="color: #000000;"> AccountController();<br /> ViewResult result </span><span style="color: #000000;">=</span><span style="color: #000000;"> controller.Index(</span><span style="color: #800080;">42</span><span style="color: #000000;">) </span><span style="color: #0000FF;">as</span><span style="color: #000000;"> ViewResult;<br /> <br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> Cast the model in the view result to the correct type and<br /> </span><span style="color: #008000;">//</span><span style="color: #008000;"> now we can test against it</span><span style="color: #008000;"><br /></span><span style="color: #000000;"> Account model </span><span style="color: #000000;">=</span><span style="color: #000000;"> result.Model </span><span style="color: #0000FF;">as</span><span style="color: #000000;"> Account;<br /> <br /> Assert.Equal(</span><span style="color: #800080;">42</span><span style="color: #000000;">, model.Id);<br />}</span></div></pre><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin. http://dunnhq.com --></div><br /><h3>Conclusion</h3><br /><p>This concept, once understood, feels incredibly clean to me. If you think about it you don’t want to test how a web page looks because that could change over time thanks to re-designs, plus parsing such information would be incredibly painful. All you need to do is verify that the view was given enough details for it to carry out it’s job; can it display a title for the page, does it have the correct list of customer orders to render, etc. It has actually made me re-think some of my code designs to better match this concept.</p><br /><p>I can see why developers love ASP.NET MVC compared to Web Forms now!</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com1tag:blogger.com,1999:blog-6872827378253370843.post-70022473880404501342013-01-07T14:07:00.001+00:002013-01-07T14:07:19.911+00:00My Life in Computer Games: Part 3<p>This is a series of posts which chronicles my life as measured by the computer games I’ve played; you can find parts 1 and 2 <a href="http://inthecodingzone.blogspot.co.uk/2012/11/my-life-in-computer-games-part-1.html">here</a> and <a href="http://inthecodingzone.blogspot.co.uk/2012/12/my-life-in-computer-games-part-2.html">here</a>. Let’s finish the journey…</p> <h3>Super Metroid</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://pwrcords.files.wordpress.com/2012/02/super_metroid_profilelarge.jpg" width="637" height="480"></strong></p> <p align="center"><font size="1">Image courtesy of <a href="http://pwrcords.com/">Power Cords</a></font></p> <p>So far I’ve been listing games in chronological order, so you might find it strange that I describe a game that was released on the SNES in 1994. The reason is that I discovered this game during my “emulator phase” after finishing university; I never owned a SNES so I decided to see what that console had to offer, and this ended up being one of my favourites.</p> <p>Super Metroid was not what I was expecting from Nintendo; the company that produced Mario and Zelda, how did they also make this dark, atmospheric game with a design inspired by the <a href="https://www.google.co.uk/search?q=aliens&oq=aliens&sugexp=chrome,mod=6&sourceid=chrome&ie=UTF-8#hl=en&tbo=d&q=alien+1979&stick=H4sIAAAAAAAAAGOovnz8BQMDAy8HixKnfq6-gZl5ekaV3-biAqWUQPG9vy-s-PGqUr1UV60UAMTs97AqAAAA&sa=X&ei=q9TqUM-mLoi1hAeY4oGYBg&ved=0CIICEOkTMBY&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.&bvm=bv.1355534169,d.ZG4&fp=f42fee5d8e10998d&bpcl=40096503&biw=1920&bih=1019">Alien films</a>? From the beginning the mood kicked in; exploring what looked like a dead planet with no life signs until you were spotted and things kicked into action, this game was an excellent adventure with memorable bosses, the feeling that if you just looked a bit further you’ll find the next upgrade and an exciting climax ending in a mad dash to escape before everything exploded around you.</p> <h3>Wii Sports</h3> <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjsJTlQOuzWbS-b_jV8THPzKjJKYfw6YWYaIqz1MiaXvcVG5z1I2xAddsMJmigla6jg0MEt__tH0DHR3jmR92wd_ajbNE5782-TgPXpZPiP2Xz_kNbN6U1bpZUv0CfJ7hAtPdxsUHL_3AE/s1600/wii_sports_wii+2.jpg" width="640" height="403"></p> <p align="center"><font size="1">Image courtesy of <a href="http://fusiongamerblog.blogspot.co.uk/2010/10/nintendo-natter-wii-sports.html">Fusion Gamer</a> and <a href="http://www.ign.com/">IGN</a></font></p> <p>Things were changing. Consoles kept pushing for better graphics and more power to produce the same kind of games that we’d already played many times over but this time in high definition. Meanwhile I was starting to settle down, just moved in with my then girlfriend (now wife) and was getting bored of the same kind of gameplay experiences. Enter the <a href="http://en.wikipedia.org/wiki/Wii">Nintendo Wii</a> and the one game which, although not the greatest by a long shot, explained precisely what the Wii was about: Wii Sports.</p> <p>There isn’t really much to say about it; it’s simply a collection of mini-games focused on tennis, boxing, bowling and golf but it’s the way you play them using the <a href="http://en.wikipedia.org/wiki/Wii_Remote">Wiimote</a> and motion controls that makes it different. No other console had done motion controls like this, or at least this simply before; even my wife wanted to play games with me – and somehow she can still beat at boxing every time! For it’s time the Wii was a breath of fresh air to me because it made games fun again.</p> <h3>Super Mario Galaxy</h3> <p><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://media.tumblr.com/tumblr_m0ubaqgR1p1ql1kwb.jpg"></p> <p align="center"><font size="1">Image courtesy of <a href="http://superpolypixel.tumblr.com/post/19261523993/nintendo-a-third-super-mario-galaxy-is-difficult-to">Super PolyPixel</a></font></p> <p>I bought a Nintendo Wii because it was the perfect party games machine which would get my friends involved but also for another reason; I’m a hardcore gamer at heart and wanted to play proper Nintendo games again. And Super Mario Galaxy was the next game I got for it.</p> <p>In essence it evolves the formula laid down years ago by Super Mario 64; Mario collects stars to open more levels, fights Bowser, saves Princess Peach (again!) etc. etc. But this time in space! Which actually opens up new ideas because gravity plays a part now; Mario could literally run around a small planetoid and not fall off it, or jump to a nearby object to fall into that gravity well. Once again I was amazed with the ingenuity of Nintendo who never seem to run out of creative ideas.</p> <p>I also distinctly remember this as one of the few games where I <em>didn’t</em> have to battle with the camera controls; the fact that you could manoeuvre Mario in all kinds of planes made me think this would be awkward but I can’t remember a time where things got in the way, the camera just followed him almost perfectly.</p> <h3>World of Goo</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://www.edge-online.com/wp-content/uploads/edgeonline/oldfiles/images/feature_article/2008/07/world_of_goo_b.jpg"></strong></p> <p align="center"><font size="1">Image courtesy of <a href="http://www.edge-online.com/features/preview-world-goo/">Edge</a></font></p> <p>This most recent generation of consoles brought something new to the mix; having internet connectivity meant that games could be downloaded to the console for the first time ever. World of Goo was my first ever downloaded, unboxed game.</p> <p>To describe World of Goo is a bit difficult. Essentially it is a puzzle game where you have to connect goo balls together into structures and help the remaining goo balls to escape the level via a pipe – sounds similar to <a href="http://www.elizium.nu/scripts/lemmings/">Lemmings</a>, doesn’t it? But the game as a whole is far more than that; it has an artistic vision to it, playful and not taking itself too seriously. There is something of a plot even, told via signposts you see in each level, though not strictly a linear story, more based around themes than anything else. And it has an amazing soundtrack.</p> <p>The problem in describing this game is that my basic words don’t do it justice; I think it is simply one of those games you have to <em>experience</em> for yourself.</p> <h3>Metroid Prime Trilogy</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://purenintendo.com/wp-content/uploads/2009/09/i_18487.jpg" width="673" height="350"></strong></p> <p align="center"><font size="1">Image courtesy of <a href="http://purenintendo.com/2009/09/08/pure-nintendo-review-metroid-prime-trilogy/">Pure Nintendo</a></font></p> <p>One regret I had in never owning a Gamecube was that I never got to play Metroid Prime, a game that so many people had misgivings about (“Metroid in 3D? In the first person? Impossible!”) yet was actually critically acclaimed and ended up being one of the best games on that system. Fortunately I did get to play it on the Wii, plus it’s two sequels and with enhanced motion controls, all in one package.</p> <p>In terms of adventure I felt that Metroid Prime was better than Super Metroid. It had the same atmosphere of Super Metroid and the same sense of adventure but felt much more immersive. The addition of the scan visor also meant that plot details could be viewed (or not if you didn’t want to), so you would read journal entries from the enemy describing how “The Hunter” (a.k.a. you) was slowly infiltrating their bases. And I thank Nintendo for adjusting it to use the Wiimote and create a real first-person control scheme.</p> <p>Metroid Prime 2: Echoes was the Gamecube sequel and followed in roughly the same footsteps as Prime but introduced that old gameplay staple of the <a href="http://zeldawiki.org/Dark_World">“dark world”</a>: splitting the world into both light and dark meant double the size of the levels and some ingenuity of puzzles. Personally I found this game difficult; I still enjoyed it but every time you entered the dark world it would sap away at your health, forcing you to find shelter in special “safe zones”. This meant things were more tense when you’re trying to escape enemies whilst also desperately trying to find the next safe zone. Plus there were some sections which almost had me pulling my hair out in frustration; in general, it was harder than Prime.</p> <p>Metroid Prime 3: Corruption was the true Wii sequel to the trilogy and it showed; designed completely with the Wiimote in mind it added certain actions like flicking the nunchuk in a whip-like fashion and using the Wiimote in certain situations by having to twist it this way and that, plus the graphics were much improved. Overall it was a solid sequel and altogether one of the best deals I’ve purchased.</p> <h3>The Legend of Zelda: Skyward Sword</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://files.g4tv.com/ImageDb3/241094_S/the-legend-of-zelda-skyward-sword.jpg"></strong></p> <p align="center"><font size="1">Image courtesy of <a href="http://www.g4tv.com/thefeed/blog/post/718881/skyrim-vs-legend-of-zelda-skyward-sword-videogame-deathmatch-best-games-of-2011-nerdfight/">G4</a></font></p> <p>And so to my most recent game which I’m still trying to complete after a year! (Not because I’m bad but trying to find the time to devote to it is tricky for me now).</p> <p>There is one reason why this game is great: pretending the Wiimote is a sword, like everyone imagined they would do when they first heard about the Wii. Swinging in a particular direction makes Link swing <em>exactly</em> the same way, which actually adds some strategy to the usual hack-and-slash action. For instance, I could swing horizontally but the enemy could block that direction; only a vertical attack would work. Things get interesting when enemies keep dodging and blocking your attacks forcing you to adapt as well.</p> <p>Apart from the sword your other items have motion controls too; swing you Wiimote like a whip to use the whip, pull back your bow string as you would expect, push your shield hand forward to perform a shield bash attack, and so on. Finally Nintendo made good on their promise of motion controls being the future.</p> <h3>The End?</h3> <p>And that’s my life so far. Like I mentioned in <a href="http://inthecodingzone.blogspot.co.uk/2012/11/my-life-in-computer-games-part-1.html">part 1</a> I’m not sure I’ll be able to keep playing lengthy games anymore, partly due to lack of interest and partly due to time constraints. I’ve got a few games on my phone which may be more manageable, but I’m guessing I will now wait until my children are old enough to want to play computer games too before I start again.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-27440741460300763772012-12-14T12:52:00.001+00:002012-12-14T12:52:54.672+00:00My Life in Computer Games: Part 2<p>This is a series of posts which chronicles my life as measured by the computer games I’ve played; you can find the <a href="http://inthecodingzone.blogspot.co.uk/2012/11/my-life-in-computer-games-part-1.html">first part here</a>. Let’s continue the journey…</p> <h3>Perfect Dark</h3> <div style="padding-bottom: 0px; margin: 0px auto; padding-left: 0px; width: 448px; padding-right: 0px; display: block; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:a9885fee-82ff-466b-9e86-e107090d306c" class="wlWriterEditableSmartContent"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/zfUy5nZkFiM?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/zfUy5nZkFiM?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div></div> <p>The N64 was starting to run out of steam but, like every console at the end of its lifecycle, it had a few last gems to dish out. One of them was Perfect Dark, the spiritual successor to Goldeneye.</p> <p>It was basically the same kind of gameplay that Goldeneye introduced but in a different setting and tightened gameplay; it still had the mission difficulty of its predecessor but crammed in so many more features, allowed you to play in a higher resolution (640 x 480!) and even had voice samples – even if the voice acting was terrible at least it added a bit more to the atmosphere having guards complain about being shot.</p> <p>Once again though the multiplayer was where it truly shined, not only by adding more weapons and options but by adding <a href="http://perfectdark.retropixel.net/pd/combat/simulants.php">bots</a>, allowing up to 12 players at once – 4 human, 8 computer controlled. This really changed the pace of the matches; Goldeneye had a more measured, strategic pacing but because Perfect Dark bots never stood still for longer than a second you always had to be on the run making things a bit more frantic; it is how I imagine PC multiplayer games like Doom and Quake to be.</p> <h3>Banjo Tooie</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://www.wallpaperpimper.com/wallpaper/Games/Banjo_Tooie/Banjo-Tooie-6-1024x768.jpg" width="638" height="480"></strong></p> <p align="center"><font size="1">Image courtesy of </font><a href="http://www.wallpaperpimper.com/wallpaper/download-wallpaper-Banjo_Tooie-size-1024x768-id-128507.htm"><font size="1">Wallpaper Pimper</font></a></p> <p>In 1998 Rare released they’re take on the 3D platformer, <a href="http://en.wikipedia.org/wiki/Banjo-Kazooie">Banjo-Kazooie</a>. I loved that game but I have far fonder memories of it’s sequel Banjo-Tooie (despite the ridiculous name).</p> <p>Whereas the first game had big worlds to play in, this one had <em>massive</em> worlds; when playing through the first level I thought it would be a bit bigger, but when I got to the highest point and looked down I could see <em>everything</em> before me! That must have been quite an achievement for the N64. Not only were the levels huge but they were interconnected; unlike other games where each level/world was it’s own distinct area, this game connected each level at strategic points to give the illusion of it being a far bigger world. In fact some of the games puzzles relied on having to move about between levels; <a href="http://banjokazooie.wikia.com/wiki/Chuffy">Chuffy the Train</a> is one example.</p> <p>Banjo-Kazooie also tried to have it’s own <a href="http://segaretro.org/Lock-On_Technology">“Lock-on Technology”</a> moment by introducing <a href="http://banjokazooie.wikia.com/wiki/Stop_'n'_Swop">“Stop ‘N’ Swop”</a>, the idea being that once you finished the first game you could unlock secrets that would carry over to the sequel, though it never really worked out in the end. Banjo-Tooie did make reference to it but it was entirely self-contained in it’s own game. Shame.</p> <h3>Metal Gear Solid 2</h3> <div style="padding-bottom: 0px; margin: 0px auto; padding-left: 0px; width: 448px; padding-right: 0px; display: block; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:5f9d6c9d-cbcc-4db9-a49e-85b98c3bcdef" class="wlWriterEditableSmartContent"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/BEE1aWiwz_I?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/BEE1aWiwz_I?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div></div> <p>Now this is a bit different! I never actually owned this since I never had a PS2 but my friend did and we spent ages playing through it. I had seen trailers of it and it looked amazing! Everyone was hyping this game up. So when we started it instead of playing as the legendary <a href="http://metalgear.wikia.com/wiki/Solid_Snake">Solid Snake</a> we had… a girly, floppy haired man with girlfriend issues. Eh?</p> <p>It turns out it was all part of a ruse. All the <a href="http://www.e3expo.com/">E3</a> trailers showed Solid Snake back on form but actually the focus was not on him for most of the game: only if when starting a new game did you say you never played the original (like we hadn’t) did you skip the well know <a href="http://metalgear.wikia.com/wiki/U.S.S._Discovery_(tanker)">tanker part</a> and instead went straight to the meat of the game playing as new spy <a href="http://metalgear.wikia.com/wiki/Raiden">Raiden</a>. I can kind of understand it now; by changing the perspective you see the most important character in a new light. Still, it left me and my friend a bit perplexed initially, especially when I told him there was a whole other part of the game that he hadn’t experienced.</p> <p>Nonetheless it was a really great game. The graphics were fantastic, the stealth gameplay excellent, the boss battles massively over the top and the cutscenes well presented, even if on the long side – I’m sure half the game was devoted to just <em>watching</em> it. My highlight though was towards the end when the game tried to play tricks on you, suggesting you “turn the console off now” or the <a href="http://metalgear.wikia.com/wiki/Game_Over">“Fission Mailed”</a> screen; for a game which played it straight most of the time it left us a bit shocked as to what to do.</p> <h3>Half Life</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://media.giantbomb.com/uploads/0/24/11135-Test_chamber_AYool_super.jpg"></strong></p> <p align="center"><font size="1">“They’re waiting for you Gordon, in the test chamber…”</font></p> <p align="center"><font size="1">Image courtesy of </font><a href="http://www.giantbomb.com/black-mesa-research-facility/95-64/"><font size="1">Giant Bomb</font></a></p> <p>I was never really into playing PC games as it seemed each game I bought required a brand new set of hardware, which gets expensive quickly. But a few have caught my eye throughout time and this was one them.</p> <p>Half Life tells the story of a scientist who has to escape the confines of a research facility once an accident happens and aliens start arriving. So far, so typical science fiction. What made this PC shooter stand out from the others though was it’s narrative and the fact that you were part of it; no cutscenes, no ever seeing what Gordon Freeman looked like, everything was played from your perspective.</p> <p>There were also no levels, instead the entire facility was a level. The opening sequence demonstrated this brilliantly; as you were heading to work on the tram system you would see everyone else going about their jobs, passing through security sections, watching things move about. Despite the aging graphics it felt <em>real</em>, like this was a fully functioning place.</p> <p>The enemy AI was fantastic too. Initially you met various aliens which felt reminiscent of Doom but eventually you met the Marines who were really smart; it took a lot of clever thinking to outsmart them sometimes.</p> <h3>Start Wars: Jedi Knight II</h3> <div style="padding-bottom: 0px; margin: 0px auto; padding-left: 0px; width: 448px; padding-right: 0px; display: block; float: none; padding-top: 0px" id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:71052caf-48cb-4f4c-a2a7-a3beffbcaeea" class="wlWriterEditableSmartContent"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/knShHXJESa4?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/knShHXJESa4?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div></div> <p>There have been a bazillion games based on Star Wars but how many of them can you remember that were even slightly good? This one, in my opinion, was one of the best because finally I could be a Jedi; not doing goody-goody two-shoes tasks like diplomacy like the prequel films would have you suggest, but doing what all kick-ass Jedis do by hacking and slashing Stormtroopers with a lightsaber.</p> <p>Overall I just liked this game; the force powers were focused and the lightsaber duals were fun. The initial few levels forced you to play with weapons which was a shame but it was the lightsaber that stole the show.</p> <h3>Halo: Combat Evolved</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://cdn.pocket-lint.com/images/1Qt/halo-xbox-bungie-microsoft-game-14.jpg?20111109-150051"></strong></p> <p align="center"><font size="1">Image courtesy of </font><a href="http://www.pocket-lint.com/review-gallery/41/halo-xbox-bungie-microsoft-game/15"><font size="1">Pocket-Lint</font></a></p> <p>A new kid came on the block; Microsoft thought they could do this video games thing just as well as Sony and Nintendo so invented the XBox, a huge black console which would leave a legacy. But every console needs a <a href="http://en.wikipedia.org/wiki/Killer_application">“killer app”</a> to sell units, especially one that no-one had ever heard of, and that is what Halo became.</p> <p>Lots of people played it for its multiplayer but I played it for its engaging story, the clever AI and most importantly its co-operative play. Me and a friend played through the co-operative game religiously and for once it made a difference; it wasn’t just about who could shoot more enemies but it helped with your strategy and we both looked for each others backs. It also has one of the best <a href="http://youtu.be/eD3TyjvfAR0">climatic endings</a> for a game I’ve seen.</p> <h3>Half Life 2</h3> <p><strong><img style="display: block; float: none; margin-left: auto; margin-right: auto" src="http://oyster.ignimgs.com/ve3d/images/01/39/13993_half-life-2-20041121083513469.jpg" width="638" height="480"></strong></p> <p align="center"><font size="1">Image courtesy of </font><a href="http://ve3d.ign.com/images/fullsize/13993/PC/Half-Life-2/Screenshots/Half-Life-2"><font size="1">Voodoo Extreme VE3D</font></a></p> <p>I played this version on the XBox and thought it was a great sequel to the original. The scope expanded from the Black Mesa facility to City 17, an unknown European city where the remaining humans were being rounded up by the invading alien forces. The opening in this game worked in a similar vein to the original, but this time focused on the humans milling around, listless and hopeless.</p> <p>The real star of the show though was the physics and infamous <a href="http://www.youtube.com/watch?v=itXTwYLH-dg">“Gravity Gun”</a>. This was probably the best weapon in the game yet didn’t fire a single bullet: instead it let you pick up nearly any object and fling it with force and anything you wanted. The Ravenholm section was the best example of this: flinging buzzsaws at the zombies and slicing them in half never got boring.</p> <p>I also really liked the technology powering the game; having the characters watch you and lip synch perfectly was quite something I thought.</p> <h3>Next Time</h3> <p>The last part focuses on recent years, particularly the Wii. Stay tuned!</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-27819477716328516562012-11-30T20:06:00.001+00:002012-11-30T20:06:12.754+00:00My Life in Computer Games: Part 1<p>I’m coming to a realisation that has slowly been dawning on me for a while now: I’m going to give up playing computer games. For someone who has been playing them since childhood that’s quite a big thing to say, but it is for several reasons.</p> <p>First and foremost I do not have the time anymore. I’ve got a full-time job and a family to support so free time for me is extremely precious. I’m currently playing <a href="http://zelda.com/skywardsword/">The Legend of Zelda: Skyward Sword</a>, but I’ve been doing that since <em>Christmas 2011</em>! And I still haven’t finished! So far I think I’ve clocked up about 40 hours gameplay time but that is very much spread out across a year, playing maybe a couple of hours a week at best. Finding the time for anything more involving than <a href="http://www.angrybirds.com/">Angry Birds</a> is simply difficult these days.</p> <p>But it’s not just a matter of finding the time anymore, I actually don’t feel that bothered about computer games anymore. In the limited free time I have left I would rather actually be doing something constructive (such as writing this blog) and learning more about programming. I’m still interested in <em>how</em> computer games are made – I found the <a href="http://fabiensanglard.net/">code reviews that Fabien Sanglard did on the Quake and Doom game engines</a> really interesting – and I still appreciate them – I think <a href="http://www.halowaypoint.com/halo4/en-us/">Halo 4</a> looks amazing. But playing them? Meh.</p> <p>So I thought I would make a list of all the memorable games I’ve played during my life so far and reminisce, which is going to span a few posts.</p> <h3>The ZX Spectrum</h3> <p>When I first asked my parents for a computer to play computer games I thought I would be getting a Nintendo or a Sega console. Instead what I got was a <a href="http://en.wikipedia.org/wiki/File:Spectrum_128-2.png">ZX Spectrum +2</a>, so not quite what I was expecting.</p> <p>In the end it did shape my entire career by introducing me to programming, but as a game machine all I remember was having to load tapes which took <em>minutes</em> – and also provided a lovely whining noise and hallucinogenic loading screen – only for me to play it for 30 seconds and give up because I didn’t find it entertaining. Maybe the next one will be better… (wait another 5 minutes to load the next tape).</p> <div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:1423f403-74aa-46c9-883d-2317f54f372f" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; width: 448px; margin-right: auto"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/SdwK1vBnZ7A?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/SdwK1vBnZ7A?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div><div style="width:448px;clear:both;font-size:.8em">A ZX Spectrum loading a program. Wow, my head hurts…</div></div> <p>So I gave up on the Spectrum and got myself a Sega Master System, which then led to a <a href="http://en.wikipedia.org/wiki/Sega_Genesis">Sega Mega Drive</a>, which then led to…</p> <h3>Sonic the Hedgehog</h3> <p>Back in the 16-bit days you were either with Nintendo or Sega, Mario or Sonic. I chose Sonic and have many happy memories of those games, because they were <em>fast</em>!</p> <div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:ef61be2d-fb9a-4719-b08c-54cbefc28cfe" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; width: 448px"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/dskL2NwC9L8?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/dskL2NwC9L8?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div></div> <p><a href="http://en.wikipedia.org/wiki/Sonic_the_Hedgehog_2_(16-bit)">Sonic the Hedgehog 2</a> was my personal favourite, the video above showing one of my favourite levels due to the sheer speed you can crank up to – so fast that the screen sometimes can’t even keep up with you!</p> <p>But the real gem of the series was <a href="http://en.wikipedia.org/wiki/Sonic_the_Hedgehog_3">Sonic 3</a> and <a href="http://en.wikipedia.org/wiki/Sonic_%26_Knuckles">Sonic & Knuckles</a>. Both individual games on their own were great, but the <a href="http://segaretro.org/Lock-On_Technology">“lock on” technology</a> that Sonic & Knuckles brought made them combined into an amazing experience – extending the Sonic 3 game, or by joining Sonic 2 to it you could turn an old game into a brand new experience.</p> <p>Recently I actually wondered how they even did the “lock on” bit; how do you turn one game into three games? And how do you take an old game which wasn’t even designed for this kind of thing and make it into what is effectively a brand new game? Turns out that actually it was a clever ROM trick, by joining ROM chips together to make a new one; <a href="http://www.sega-16.com/forum/archive/index.php/t-1947.html">this long forum post explains it in far more detail</a>.</p> <h3>The 32-bit Years</h3> <p>After the Mega Drive I got a <a href="http://en.wikipedia.org/wiki/Sega_Saturn">Sega Saturn</a> – not sure why in retrospect and not a PlayStation which was the latest hotness at the time. There were some good games such as <a href="http://en.wikipedia.org/wiki/Sega_Rally_Championship">Sega Rally</a> and <a href="http://en.wikipedia.org/wiki/Nights_into_Dreams...">NIGHTs Into Dreams</a> but this was the advent of 3D graphics and things were just starting out. One game caught my attention though which made me rethink everything…</p> <h3>GoldenEye</h3> <div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:3d2ac5fb-43cd-4b11-a1d0-c975e26628d2" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; width: 448px"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/An4iRCd3SAY?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/An4iRCd3SAY?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div><div style="width:448px;clear:both;font-size:.8em">Need I say more? Oh, alright then</div></div> <p>I remember going round to my friend’s house and they were playing GoldenEye. I had a go – the Nintendo 64 controller looked a bit weird to hold – but I started playing it and I realised quickly that I was <em>completely</em> hooked on the multiplayer. Every console before the N64 supported two players but this one could support four, meaning that multiplayer shooters actually made sense outside of a PC.</p> <p>So I got an N64 with GoldenEye as my first game for it. The single player missions were great with lots of challenges added as the difficulty ramped up, but my single defining memory of this game was spending nearly all my free time between A-Level lectures playing deathmatch games against my friends. And beating them. Over and over again.</p> <h3>Super Mario 64</h3> <p>Now that I had a N64 I wondered what other games to play on it, so of course I got the N64 killer app: Super Mario 64.</p> <p>Now before then I hadn’t actually played a Mario game before but this game was great. I remember just wandering around the castle hub-world doing all sorts of acrobatics simply because I could and the analog stick finally let me move around in 3D which made sense. Although I have to admit the camera controls did suck.</p> <div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:0f9eda25-b34f-437f-9d4d-45cf7734073a" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; width: 448px"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/xDhxfUBrMko?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/xDhxfUBrMko?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div><div style="width:448px;clear:both;font-size:.8em">Throw a dinosaur four times my size into a bomb? No problem!</div></div> <p>I also came to realise that games that Nintendo made really were top quality; they were fun, inventive and imaginative.</p> <h3>The Legend of Zelda: Ocarina of Time</h3> <p>This game came out during Christmas 1998 and was snapped up by just about everyone at the time. I was very lucky to get this on Christmas Day and spent the next two weeks solid becoming immersed in it.</p> <div id="scid:5737277B-5D6D-4f48-ABFC-DD9C333F4C5D:e8a9d89b-e5f6-4172-94fe-5ea428877f32" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin: 0px auto; display: block; padding-right: 0px; width: 448px"><div><object width="448" height="252"><param name="movie" value="http://www.youtube.com/v/CtMllWsML5M?hl=en&hd=1"></param><embed src="http://www.youtube.com/v/CtMllWsML5M?hl=en&hd=1" type="application/x-shockwave-flash" width="448" height="252"></embed></object></div></div> <p>Just like Mario I had never played a Zelda game before so I never experienced the sense of adventure previous games conjured up, and this did feel like a real adventure. It introduced concepts like “locking-on” to your target during combat so you could always see them (something every game afterwards copied) and split the world into two times: current and future, meaning you played as Young Link and Adult Link. And you got to ride a horse!</p> <p>Looking back I simply remember the variety of the gameplay, the sense of scope (looking into the distance at the volcano or riding across Hyrule field), and the final climatic battle with Ganondorf.</p> <h3>The Legend of Zelda: Majora’s Mask</h3> <p>The sequel to Ocarina of Time, this was like a Zelda game and also not like one at the same time. With the benefit of hindsight I think this had a lot more emotional depth than Ocarina.</p> <p>The main selling point of this game was that you had to save the world from destruction in just three days (game-time, not real), but of course you couldn’t do <em>everything</em> in that kind of timeframe. This meant that a “Groundhog Day” concept was used: you could relive the same three days over and over again to make progress and also watch the lives of each inhabitant of the world happen over and over again, making notes of key points in time when they would do certain actions. It was a bit harder than Ocarina and there was an added sense of urgency (what with an evil-looking and ever looming moon constantly visible in sky) but still worth playing.</p> <p><strong><img style="float: none; margin-left: auto; display: block; margin-right: auto" src="http://ogeeku.com/wp-content/uploads/2011/08/majoras-mask-moon.jpg" width="640" height="430"></strong></p> <p align="center"><font size="1">That doesn’t look promising. </font><font size="1">Image courtesy of </font><a title="http://www.ogeeku.com" href="http://www.ogeeku.com"><font size="1">http://www.ogeeku.com</font></a></p> <p>The emotional depth I mentioned though was something I wasn’t expecting; every character had a backstory and it was your job to help them. One little girl’s father had turned into a monster yet she tried to shield him from the world to protect him. A baby had lost his father and brought depression to everyone around him. Probably the most poignant one was having to re-unite a wife and husband – the longest of all the side quests; you eventually did but only just in time, by which point the moon was nearly about to crash into the world – you brought them back together long enough for them both to properly say goodbye to each other. This adventure was not about stopping a singular enemy, rather it was about healing the wounds of the people of the world.</p> <h3>Next Time</h3> <p>There’s still a lot more to go, so stay tuned for the next part.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-84882748305597111682012-11-14T22:02:00.001+00:002012-11-14T22:02:55.530+00:00Forcibly Uninstall Apps from Windows 8<p>I took the plunge a couple of weeks ago and upgraded to Windows 8. It takes some getting used to but overall I’m mostly happy with it. Except when it did something very unusual with the Metro apps (I refuse to use another name since everyone by now knows what “Metro” means).</p> <p>For those who don’t know when updates are available for Metro apps they appear in the <a href="http://windows.microsoft.com/en-GB/windows-8/apps">Windows Store</a>, a little number appears on the live tile. One day I found that there were updates available for all the built-in apps such as Mail, Calendar, Bing etc. So I dutifully went to start the update process, found it was taking a while as there were quite a few, and just left it to it.</p> <p>To be fair I might have messed up my system myself but while this was happening I thought “I don’t need Travel, Sports or anything like that. I’ll just keep the ones I’m interested in”. So I uninstalled the apps I didn’t care about <em>whilst they were still updating</em>.</p> <p>In retrospect I should have known better – I’m effectively classed as a <a href="http://en.wikipedia.org/wiki/Power_user">power user</a>! As a result of my blunder I ended up with nearly all the apps that were updated being wiped from the system, including some of the ones that did matter to me. Here’s the interesting part though: when I went back to the Windows Store to try and install them again I couldn’t. This is what I saw:</p> <div id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:b402a585-5fdd-4fad-945b-b0aff22c2b26" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; width: 592px; margin-right: auto"><a href="http://lh4.ggpht.com/-2AMNJEmGsUs/UKQUo4pwlsI/AAAAAAAAAJc/3VlSmidJtdE/StoreSaysAppIsInstalledWhenItIsNot-8x6.png?imgmax=800" title="The install button is not there" rel="thumbnail"><img border="0" src="http://lh3.ggpht.com/-uxXmzChPgaM/UKQUqvmEmYI/AAAAAAAAAJk/jKZOtK-S_7Q/StoreSaysAppIsInstalledWhenItIsNot%25255B14%25255D.png?imgmax=800" width="580" height="390" /></a></div> <p>So the Store thinks it is already installed. So why when I search for it does this happen?</p> <div id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:6cbceb8c-9e4e-4e8e-b203-ff3a80f8672b" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; width: 592px; margin-right: auto"><a href="http://lh3.ggpht.com/-l1OQqQblXws/UKQUt0_LMLI/AAAAAAAAAJs/SH1mxrq31r4/AppNotFoundOnSystem-8x6.png?imgmax=800" title="So where is it then?" rel="thumbnail"><img border="0" src="http://lh4.ggpht.com/-X-z4kEQvRi4/UKQUwDCzi2I/AAAAAAAAAJ0/LA-5qP3NMKk/AppNotFoundOnSystem%25255B3%25255D.png?imgmax=800" width="580" height="390" /></a></div> <p>Something in Windows clearly thinks I have the app installed. Now in the past I would have known to check certain folders like Program Files or delve into the <a href="http://www.techsupportalert.com/content/what-everybody-should-know-about-windows-registry.htm">registry</a> to see if some sort of metadata was lying around, but Windows 8 changes things up a bit: these Metro apps seem completely self-contained and sitting in the <a href="http://www.thewindowsclub.com/windows-8-metro-apps-folder-location">WindowsApps folder</a> which is quite secure and doesn’t even let me read it by default. So how can I remove these hidden settings to get Windows to play nice again?</p> <p>Fortunately after some Googling I found the answer on <a href="http://social.technet.microsoft.com/Forums/en/w8itprogeneral/thread/acf551c2-6968-4eed-8c90-ed5aaa416c6b">this forum</a> which I will explain in detail below. In this example I’m going to re-install the Bing app despite the Store telling me that I already have it.</p> <p>First you need to open up an elevated <a href="http://technet.microsoft.com/en-us/library/bb978526.aspx">PowerShell</a> console. Simply:</p> <ol> <li>Press the Win-key to get you to the Start Screen.</li> <li>Start typing “Powershell”</li> <li>Right-click on “Windows PowerShell” and click on “Run as administrator” in the menu that appears at the bottom of the screen.</li></ol> <p>Now you can run this cmdlet to see what Metro apps Windows considers to be installed:</p> <div id="codeSnippetWrapper"><pre id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">Get-AppxPackage -allusers</pre><br></div><br /><p>This should give you a list like in the image below:</p><br /><div id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:a3ad86ad-989a-43fc-b62c-b7f7bb5a2bf7" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; width: 592px; margin-right: auto"><a href="http://lh3.ggpht.com/-99gPyKEnBnI/UKQU2OKu5aI/AAAAAAAAAJ8/gMJEg5V2smk/GetPackagesSaysThisInitially-8x6.png?imgmax=800" title="The rogue app is highlighted" rel="thumbnail"><img border="0" src="http://lh3.ggpht.com/-UVr9mvBpZNQ/UKQU5vbE9-I/AAAAAAAAAKE/cPrpPzROuZE/GetPackagesSaysThisInitially%25255B7%25255D.png?imgmax=800" width="580" height="478" /></a></div><br /><br /><p>Now that you’ve got the details of the app you can run another cmdlet to remove it. In my case I did this:</p><br /><div id="codeSnippetWrapper"><pre id="codeSnippet" style="border-top-style: none; overflow: visible; font-size: 8pt; border-left-style: none; font-family: 'Courier New', courier, monospace; border-bottom-style: none; color: black; padding-bottom: 0px; direction: ltr; text-align: left; padding-top: 0px; border-right-style: none; padding-left: 0px; margin: 0em; line-height: 12pt; padding-right: 0px; width: 100%; background-color: #f4f4f4">Remove-AppxPackage Microsoft.Bing_1.5.1.251_x64__8wekyb3d8bbwe</pre><br></div><br /><p>You’ll notice that you have to use the <em>PackageFullName</em> value that is provided in order for the cmdlet to work.</p><br /><p>Once that was done I went back to the Windows Store and checked that it worked:</p><br /><div id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:93078e4a-30f5-4cd8-977e-e5765652e9fb" class="wlWriterEditableSmartContent" style="float: none; padding-bottom: 0px; padding-top: 0px; padding-left: 0px; margin-left: auto; display: block; padding-right: 0px; width: 592px; margin-right: auto"><a href="http://lh3.ggpht.com/-3sKKMqj5wLQ/UKQU-9sHgjI/AAAAAAAAAKM/1-SYrsJOJrk/StoreNowLetsMeInstallApp-8x6.png?imgmax=800" title="Success! The Install button is back" rel="thumbnail"><img border="0" src="http://lh5.ggpht.com/-dhb8fBzU0AE/UKQVBvEuuPI/AAAAAAAAAKU/7-ldZXaCuls/StoreNowLetsMeInstallApp%25255B3%25255D.png?imgmax=800" width="580" height="390" /></a></div><br /><br /><p>In my case I simply repeated these steps until I had cleared up my mess and managed to get everything I wanted back.</p><br /><p>I think it’s quite good that there is actually a way to uninstall something in an automated fashion. Regardless, this trick got me out of a hole so I’m sure someone else might benefit from re-learning Windows tricks like I’m doing.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-77472496494367837852012-11-08T21:52:00.001+00:002012-11-08T21:52:57.233+00:00The Urge to Rewrite Code<p>I recently read a <a href="http://arstechnica.com/features/2012/10/windows-8-and-winrt-everything-old-is-new-again/">fantastic article on Ars Technica</a> about the inner workings of the new <a href="http://en.wikipedia.org/wiki/Windows_Runtime">WinRT</a> technology powering <a href="http://windows.microsoft.com/en-US/windows-8/meet">Windows 8</a>. It’s a lengthy article but it explains how we got all the way from Win16 to <a href="http://en.wikipedia.org/wiki/Windows_API">Win32</a> to <a href="http://en.wikipedia.org/wiki/Object_Linking_and_Embedding">OLE</a> to <a href="http://www.microsoft.com/com/default.mspx">COM</a> to <a href="http://www.microsoft.com/net">.NET</a> and eventually to WinRT and is well worth a read if you’re interested in Windows development and its history.</p> <p>What got me thinking though is that it gave me a snapshot into Microsoft’s process of keeping Windows and its technology up-to-date yet also be able to support a vast legacy of applications that have been running sometimes for the past 20 – 30 years. What you realise is that to support that legacy and keep pushing forwards it basically built everything on top of one another. If you were to start from the latest WinRT API’s and strip away all the layers of strata you would eventually hit the ancient Win32 API and kernel, the very same system that has been powering Windows since <a href="http://en.wikipedia.org/wiki/Windows_NT">Windows NT</a>. The same can be said for .NET and COM; it doesn’t matter how new or fancy the latest technology trend is, eventually they all become nicer wrappers over what came previously.</p> <p>This is interesting to me because I’ll bet every single developer out there has had one thought cross their minds at some point in their career: “I need to rewrite this”. Maybe you have a codebase written from another era or you’ve inherited code that looks like a monkey tap danced on a keyboard, sometimes we all fall prey to thinking that we need to invest time in rewriting huge chunks of code (or entire systems) because, obviously, we can do a better job and that the end result will be “better”.</p> <p><strong>This is dangerous!</strong></p> <p>I can speak from experience plus cite <a href="http://www.joelonsoftware.com/articles/fog0000000069.html">any number of references</a> saying that taking on a rewrite of a codebase, especially an enterprise/commercial one, is just a bad idea. What you are effectively suggesting is to take a (mostly) working system, spend 6 – 12 months (maybe more) ditching it and starting all over again, and end up with <em>the exact same system you started with</em> plus countless additional bugs you’ve introduced due to human error and/or lack of domain knowledge. Also, all that time you wasted rewriting code meant that you couldn’t do any current development work, meaning your competitors have now charged ahead of you with brand new features that you will never be able to keep up with.</p> <p>All of this so that your code looks better, a matter that no-one else but you cares about.</p> <p>Now I am being a bit extreme here. Of course there are times when you have to rewrite <em>something</em> in order to progress forward. Maybe your code is so stuck in the dark ages that adding new features becomes increasingly time consuming or complex, maybe impossible. Yet I’ve learned over the years that you simply cannot ditch what you already have; your customers don’t give two hoots how you managed to kludge together their feature, the fact remains that it was done and it works so breaking it now is not an option.</p> <p>So what can be done to refactor code effectively? Below are some ideas that I thought of and some of which I even try and implement myself.</p> <h3>Do Nothing</h3> <p>By far the simplest strategy as this requires no work at all! Simply learn to live with your codebase, quality be damned. If you can overcome your initial feelings of revulsion at the spaghetti code you see daily and just accept it for what it is you might overcome some hurdles.</p> <p>Of course doing nothing also means making no improvements so it’s quite a trade-off, but as the old saying goes “if it ain’t broke, don’t fix it”.</p> <h3>The Big Bang Strategy</h3> <p><img style="float: none; margin-left: auto; display: block; margin-right: auto" src="http://cdn.memegenerator.net/instances/400x/25211754.jpg"></p> <p align="center"><font size="1">Image courtesy of </font><a href="http://memegenerator.net/"><font size="1">http://memegenerator.net/</font></a></p> <p>Or the polar opposite of doing nothing is doing everything in one go, but as I’ve already said this is very extreme and hardly ever needed as there are better ways of improving your codebase without greatly affecting anything else.</p> <h3>The Microsoft/Onion Strategy</h3> <p>What I’ve seen Microsoft tend to do is build layers upon all their existing technologies so that the next layer up has a better API than the one below and each new layer will handle the fiddly, lower level details so you don’t have to.</p> <p>For example, consider when .NET first came into existence which introduced <a href="http://msdn.microsoft.com/en-us/library/dd30h2yb.aspx">Windows Forms</a>. This was meant to replicate the drag-and-drop style of development that Visual Basic programmers have long been used to. But do you think that all the framework classes designed to handle windows and controls were written from scratch for a brand new, untested technology? No, Windows Forms was simply an easier to use wrapper over the interop’ed Win32 code because it already worked; why re-invent the wheel?</p> <p>Of course once you’ve introduced these layers and made sure they are working effectively you could start to clean up the lower layers or possibly even remove and replace them so that you don’t need so much API coverage; that is assuming of course you can remove all the dependencies on low level code.</p> <h3>The Side-by-Side Strategy</h3> <p>This is a refactoring strategy I tend to use myself. Let’s say you have a feature that, for whatever reason, you are going to rewrite. What I do is actually never touch the old code and instead create a separate layer of classes <em>alongside</em> the existing code to replicate the same functionality but written differently; usually I separate these classes with appropriate namespaces.</p> <p>Now I can work on the new code whilst the old code can still be deployed if necessary and also not affect my other team member’s builds. Eventually I will have fleshed out the rewritten code enough for calling sites to start using the new code which will then phase out the old. Once all references to the old code have been removed, you can safely delete the old code from your codebase. This might take quite a while to achieve fully but it is certainly a lot safer than starting from a blank canvas with nothing to show for a long time.</p> <p>I also use this strategy with the <a href="http://msdn.microsoft.com/en-us/library/22kk2b44(v=vs.80).aspx">ObsoleteAttribute</a> to make it clear that code is old and should no longer be used; it also helps find all the references to the old code by giving me compiler warnings that I can work my way through.</p> <h3>The Inheritance Strategy</h3> <p>As an alternative to having old and new code side-by-side, you could also implement it top-to-bottom within an inheritance hierarchy. The new code would be contained in a base class while the old code would derive from the new and still keep it’s existing API. This means that legacy code could in theory be passed into functions which require the new class and it would still work.</p> <h3>Conclusion</h3> <p>There are many alternatives to refactoring code in one large chunk – I’m sure there are also many other strategies thought up by people far cleverer and more experienced by me. Essentially I have learned from my career that the “big bang” approach never works out well and a more long-term, slower strategy usually gives the best results.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-49091870803987515892012-10-13T20:35:00.001+01:002012-10-13T20:35:11.941+01:00TypeScript: JavaScript’s Equivalent to C++<p>I’ve never been partial to JavaScript. I’ve no doubt that in the right hands you can do some truly amazing things with it, like:</p> <ul> <li>This <a href="http://hexgl.bkcore.com/">futuristic racer</a> written in HTML5, JavaScript and <a href="http://get.webgl.org/">WebGL</a> <li><a href="http://29a.ch/2010/6/2/realtime-raytracing-in-javascript">Ray tracing</a> <li>Anything from <a href="http://www.chromeexperiments.com/">Chrome Experiments</a></li></ul> <p>But I don’t use any of that for my day job; I simply use just enough JavaScript to get my website to work, which means I effectively treat it like a “glue” language and therefore don’t have the same respect for it like many other web developers would. I have considered trying to put aside any misconceptions I have and knuckling down to learn how I can use it effectively and make beautiful, maintainable code but at the end of the day for me it always boils down to the following problems:</p> <ol> <li>Thanks to it’s dynamic nature you can do <em>anything you want</em> to your objects. This makes it both a blessing and a curse. A blessing in that it gives you an enormous amount of power if you want it; a curse in that if you make a stupid mistake then it will merrily fail <em>and do nothing about it</em> – no critical errors or exceptions, just carry straight on as if nothing happened. <li>Although not limited to JavaScript, having a dynamic language means I cannot inspect the code with <a href="http://msdn.microsoft.com/en-us/library/hcw1s69b(v=vs.110).aspx">IntelliSense</a>/autocompletion, or at least nowhere near as well as a static language. I will freely admit that Visual Studio’s IntelliSense has spoiled me rotten and I simply cannot live without it now; the ability to see what functions/properties exist in a type as I am writing my code is a godsend. With JavaScript though I am forced to remember APIs or <a href="http://www.w3schools.com/htmldom/default.asp">look up documentation for the DOM</a> to remember how to do even the simplest task. <li>JavaScript was designed to be just a scripting language yet it has been proven that with a bit of trickery you can emulate other language features, such as classes and inheritence. But for someone who does not write JavaScript every day trying to understand these concepts is perplexing. For example, did you know that there are <a href="http://www.phpied.com/3-ways-to-define-a-javascript-class/">three different ways to define a JavaScript class</a>? How am I to know which is the correct method to use? And when looking at other people’s code does this mean I then have to do some mental juggling to identify when someone uses a different method than me? <li>Because it is a scripting language and not really designed for application-level code there are a number of quirks that you have to get your head around, such as lack of modular structure and <a href="http://stackoverflow.com/questions/5076944/what-is-the-difference-between-null-and-undefined-in-javascript">having both a null and undefined concept</a>. For an experienced JavaScript developer this must be second nature but to me this could result in hours of wasted time trying to understand why my code isn’t working when it looks like it should.</li></ol> <p>But maybe my biggest problem with JavaScript is that even if I or anyone else doesn’t like it, <strong>tough!</strong> JavaScript has the monopoly on client-side web programming and there is simply no other alternative. To paraphase the famous <a href="http://en.wikiquote.org/wiki/Henry_Ford">Henry Ford</a> quote, you can use any client-side scripting language you want, as long as it’s JavaScript.</p> <h3>Enter TypeScript</h3> <p>Now my intention for this post is not for it to be a rant against JavaScript; many developers love it, my language of choice is C#, to each their own. Rather it is about the recent news and release of <a href="http://www.typescriptlang.org/">TypeScript</a> from Microsoft. If you haven’t heard, TypeScript is a language designed to add things like type annotations, proper classes and modularisation into JavaScript. I would recommend viewing two videos from Channel 9 to get a proper sense of what it is all about:</p> <ol> <li><a href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Introducing-TypeScript">Anders Hejlsberg: Introducing TypeScript</a> <li><a href="http://channel9.msdn.com/posts/Anders-Hejlsberg-Steve-Lucco-and-Luke-Hoban-Inside-TypeScript">Anders Hejlsberg, Steve Lucco and Luke Hoban: Inside TypeScript</a></li></ol> <p>What makes this interesting to me though is that it is not a language like <a href="http://coffeescript.org/">CoffeeScript</a>, which has it’s own syntax to learn that then compiles into JavaScript code, thereby making you a step removed from the result. Rather TypeScript starts as JavaScript code which works completely as you would expect, and then you can add such things as type annotations where you think applicable to clarify your intentions, and again it compiles to pure JavaScript. As an analogy, if JavaScript is like C, then TypeScript is like C++; backwards compatible with the existing language (plus all the millions of libraries and frameworks written in it, including <a href="http://jquery.com/">probably the most important one</a>) yet it can help you define some core language concepts much easier to make you more productive.</p> <p>And for all those people who would complain that Microsoft are trying to take over JavaScript or subvert it for their own cause as they may have done in the past, be aware that nearly everything they are adding to the language is actually very closely mapped to the <a href="http://wiki.ecmascript.org/doku.php?id=harmony:specification_drafts">ECMAScript 6</a> standard which has already defined future features of JavaScript; TypeScript simply brings these features to you now and compiles it all away into JavaScript code that you can run today in any browser, anywhere.</p> <h3></h3> <h3>So Why Bother?</h3> <p>So why do we need TypeScript, or CoffeeScript or <a href="http://www.dartlang.org/">Dart</a> for that matter? Why can’t we just learn to love JavaScript? I’m not sure why exactly, I cannot put my finger on it, but JavaScript tends to just frustrate me somehow. The other day I had to make a change to a DOM event hander and spent ages trying to understand why the code I wrote – which looked fine to me – just did not work. All I had to go on was running through it over and over again, no tools could help me spell out that something was clearly wrong that I had missed.</p> <p>And that is actually what TypeScript is for. It isn’t necessarily a language designed to make JavaScript better, it is actually to provide better tooling for JavaScript. Once you have a well defined type system in place, you can build tools which tell you all sorts of things about your code: trying to pass the wrong types of values into a function being an obvious example.</p> <p>Not only that, but I see this also as a means to help developers new to JavaScript to ease them into some of the complexities of it. Remember how I said there were three ways to define a class? With TypeScript there is just one, which then compiles into a JavaScript equivalent. Having just one means of accomplishing a task a newcomer can then start to learn faster and, if they then want to, delve deeper into what the compiler would then produce to learn more complex JavaScript.</p> <p>As TypeScript is so new I cannot say yet whether I would actually use it or not; I would need a justified work scenario to consider experimenting with it. But it’s initial premise has definitely intrigued me, because although <em>something</em> has to be written in JavaScript there is nothing to say that a tool can’t help you with the job in hand.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com2tag:blogger.com,1999:blog-6872827378253370843.post-5113462188137487922012-09-24T13:37:00.001+01:002012-09-24T13:37:50.083+01:00Becoming a Father: One Year On – Part 4<p>This is the fourth part of my retrospective on my first year as a new father – though I’m starting to lag behind a bit now as my son is now nearly a year and a half old!</p> <p>To view all the parts, please click on one of the links below:</p> <ol> <li><a href="http://inthecodingzone.blogspot.co.uk/2012/06/becoming-father-one-year-on-part-1.html">The Beginning</a> <li><a href="http://inthecodingzone.blogspot.co.uk/2012/07/becoming-father-one-year-on-part-2.html">The First Two Weeks</a> <li><a href="http://inthecodingzone.blogspot.co.uk/2012/08/becoming-father-one-year-on-part-3.html">Getting the Hang of Things</a></li></ol> <p>This post focuses on…</p> <h3>The Accident</h3> <p>Looking back now, the first six months of my son’s life were actually quite uneventful. I would hear stories of his little friends picking up bugs and colds but he seemed as healthy as you could hope, which is something to be thankful for. He never had so much as a sniffle. When he was around 7 months old though he would be paying a visit to the hospital.</p> <p>One morning my wife was carrying him down the stairs when she lost her footing and slipped, sliding on her back down several of them. It left her a bit bruised and for an adult that would kind of be the end of it – just shrug it off, since it wasn’t that serious – but my son was crying uncontrollably. We couldn’t figure out why as we checked him all over and couldn’t see any marks or bruises anywhere, but he simply wasn’t himself. Our initial thought was that the incident was too much of a shock for him, but after about an hour our instincts told us to get him checked out. As this was a Sunday calling the doctor was out of the question, so a trip to <a href="http://en.wikipedia.org/wiki/Emergency_department">A&E</a> it was.</p> <p>After waiting for hours that afternoon we had several doctors check him out and the overall conclusion was that he was just in shock still. We did consider maybe a broken bone but pressing on any part of him seemed to illicit crying so no-one could tell. In the end we took him home and gave him <a href="http://www.calpol.co.uk/">Calpol</a> to help him sleep through the night.</p> <p>The next morning while I was at work my wife texted me to say she was taking him to our GP to get him seen again as he still wasn’t right, who then referred him back to the hospital to get an X-ray on his right leg. Around 4pm I got a call saying that he had a hairline fracture on his right femur and would need to be put in <a href="http://www.nhs.uk/conditions/Traction/Pages/Introduction.aspx">traction</a>, which meant of course staying in the hospital. And that was the start of the week-long “holiday” on the children’s ward.</p> <p>I left work early to run home and pick up a few overnight things for my wife and son and went straight to the hospital to see them. He was on baby morphine to help him with the pain and still was not himself. My wife was now constantly blaming herself for a) inflicting this on him, even though it was an accident that she could not have prevented, and b) not spotting his broken bone sooner, despite not having X-ray vision herself. </p> <p>I watched him as the nurses put him in traction, basically by lying him in bed and wrapping bandages and splints around both legs then tying them to pulleys hanging above his bed; the aim was to keep the leg straight so that it would heal faster – there is no magic cure for broken bones, you simply have to let your body heal itself. Fortunately it was only a hairline fracture and, given his age and constant body development, he would heal a lot faster than an adult (he was well on the mend in a week, whereas it might take me months to heal the same wound).</p> <p>I stayed with them for a few hours before leaving them for the night; my wife would be staying with him around the clock whilst I would still have to go to work each day. That night was actually the first time ever that I was separated from my son; as I walked past his bedroom at home that night I looked into it and it was empty for the first time, which made me feel more alone that I expected.</p> <h3>The Sleepover</h3> <p>So far it is all sounding doom and gloom, isn’t it? Well let me reassure you by showing you what my son looked like for the rest of the week.</p> <div style="padding-bottom: 0px; padding-left: 0px; width: 432px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:bec26d6b-1aac-4a23-b2ce-84320a7335d0" class="wlWriterSmartContent"><a title="What traction looks like..." href="http://lh5.ggpht.com/-BxkGHO6zs8E/UGBUDa8_EgI/AAAAAAAAAIU/FeQXWKlXMY8/Hospital1-8x6.jpg?imgmax=800" rel="thumbnail"><img border="0" src="http://lh6.ggpht.com/-NIcpH-CRPBA/UGBUETvYuAI/AAAAAAAAAIc/bQDZ38G82TE/Hospital19.png?imgmax=800" width="420" height="361"></a></div> <div style="padding-bottom: 0px; padding-left: 0px; width: 432px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:0241f769-26af-4f67-a2f1-cd1d35f16ea0" class="wlWriterSmartContent"><a title="...but he doesn't seem that bothered does he?" href="http://lh5.ggpht.com/-s0FHeKqGwLo/UGBUGBvEpKI/AAAAAAAAAIk/MI3v20L4GfA/Hospital2-8x6.jpg?imgmax=800" rel="thumbnail"><img border="0" src="http://lh4.ggpht.com/-S7rPxEMWzJg/UGBUG5p84-I/AAAAAAAAAIo/SbwUNSx2uC8/Hospital24.png?imgmax=800" width="420" height="361"></a></div> <p>As you can see after his first night in hospital he was pretty happy with life. And wouldn’t you be when you have toys surrounding you in your bed and <a href="http://www.bbc.co.uk/cbeebies/">CBeebies</a> on tap? If anything it was harder on my wife, which I will get to.</p> <p>As I still had to do my day job I was responsible for ferrying items to and from home for them and visiting them first thing in the morning before work and straight after work before going home. I would then get the luxury of sleeping at home, ready to start the routine all over again.</p> <p>My wife on the other hand stayed with our son 24/7. He got a room on the ward meaning my wife could sleep on a sofa-bed with him. For five days in a row she lived on the ward with him. By the fourth day she was almost at breaking point and when the weekend finally came so I could take over she vomited on the way home through sheer exhaustion. When I did my weekend shift straight after work on the Friday night I could finally understand what it was like; the ward was never truly quiet, always having staff roaming around and coming in to do observations on my son, day and night. There was even another child on the ward who sounded a lot worse than our son; I would periodically hear uncontrollable screaming from down the corridor, so I don’t know how that child’s parents managed to survive.</p> <p>But we did it for him because as parents that is simply our job; to put him before ourselves. And he seemed to be having a whale of a time, getting visits from his grandparents regularly and only getting bored now and again. Let’s face it, he could have been a lot worse.</p> <h3>Coming Home</h3> <p>After just over a week (and my wife having a weekend of sleeping at home while I took over) he finally got discharged. He was also getting sores from the bandages on his legs so had to come out of traction anyway but his leg had almost healed completely, we just needed to be careful how we positioned it and keep him on his back. My wife took him for check-up X-rays and a month later he was given the all clear.</p> <p>In fact now we forget that it ever happened. He is so active and runs around all over the place that it is hard to imagine that his leg was ever broken; people even now ask us how his leg is and we have to think for a second as to what they mean.</p> <p>Plus, as the doctor at the hospital pointed out to me, it is safe to assume that this will be the first of many accidents he may experience in his lifetime as kids will always get into scrapes in their continual quest to have fun.</p> <p><strong>Next time: One Year Old…</strong></p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-38694842561670169892012-09-14T21:15:00.001+01:002012-09-14T21:15:32.114+01:00Testing Framework Review: xUnit.net<p>In a previous post I reviewed <a href="http://www.nunit.org/">NUnit</a>. For my last post in this series I will focus on <a href="http://xunit.codeplex.com/">xUnit.net</a>. xUnit.net is a newer open source framework that is gaining some traction. From the xUnit.net website on <a href="http://www.codeplex.com/">CodePlex</a>:</p> <blockquote> <p>xUnit.net is a unit testing tool for the .NET Framework. Written by the original inventor of NUnit, xUnit.net is the latest technology for unit testing C#, F#, VB.NET and other .NET languages. Works with ReSharper, CodeRush, and TestDriven.NET. <p>xUnit.net is a developer testing framework, built to support Test Driven Development, with a design goal of extreme simplicity and alignment with framework features. It is compatible with .NET Framework 2.0 and later, and offers several runners: console, GUI, MSBuild, and Visual Studio integration via TestDriven.net, CodeRush Test Runner and Resharper. It also offers test project integration for ASP.NET MVC.</p></blockquote> <p>xUnit.net is even used internally by some high profile Microsoft projects such as: <ul> <li><a href="http://aspnetwebstack.codeplex.com/">ASP.NET Web Stack</a> <li><a href="http://entityframework.codeplex.com/">Entity Framework</a></li></ul> <h3>Integration</h3> <p>xUnit.net is a separate project meaning that direct Visual Studio integration support is not provided. However <a href="http://www.microsoft.com/visualstudio/11/en-us">Visual Studio 2012</a> will <a href="http://msdn.microsoft.com/en-us/library/hh598952.aspx">allow different frameworks apart from MSTest to be used</a> as the primary unit testing framework – this includes <a href="http://www.codewrecks.com/blog/index.php/2012/03/05/running-nunit-and-xunit-tests-in-tfs11-build/">TFS builds</a> too.</p> <p>In the meantime, the following steps are required:</p> <h3>Download from NuGet</h3> <p><a href="http://nuget.org/">NuGet</a> provides three packages for xUnit.net:</p> <ul> <li><a href="http://nuget.org/packages/xunit/1.9.1">xUnit.net</a> – the core framework <li><a href="http://nuget.org/packages/xunit.extensions/1.9.1">xUnit.net: Extensions</a> – contains commonly used extensions for the framework (such as <a href="http://xunit.codeplex.com/wikipage?title=Comparisons&referringTitle=Home#note4">Theories</a>) <li><a href="http://nuget.org/packages/xunit.runners/1.9.1">xUnit.net: Runners</a> – contains the various test runners needed to run test assemblies</li></ul> <p>Adding these packages to a Visual Studio project is very simple as NuGet will automatically download the latest versions and insert the correct project references required.</p> <h3>Project Items and Snippets</h3> <p>Unlike <a href="http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework">MSTest</a> which provides project items and snippets with the IDE, xUnit.net does not provide any by default. However <a href="http://msdn.microsoft.com/en-us/library/s365byhx(v=vs.100).aspx">these items are not difficult to create yourself if required</a> and the CodePlex project page even explains <a href="http://xunit.codeplex.com/wikipage?title=VsSnippets&referringTitle=Home">how to create snippets for xUnit.net</a>.</p> <h3>Standalone</h3> <p>Although some initial setup is required one possible benefit is that xUnit.net is a standalone framework – it can be run anywhere without requiring installation, simply by copying the correct files.</p> <h3>Team Build</h3> <p>TFS 2012 will be able to use the same <a href="http://blogs.msdn.com/b/visualstudioalm/archive/2012/07/31/writing-a-visual-studio-2012-unit-test-adapter.aspx">Unit Test plugin model</a> that Visual Studio 2012 uses meaning in the future it will be a lot easier to integrate xUnit.net into the Team Build process.</p> <p>Until then though it is possible to use xUnit.net within Team Build but only via a custom build activity and translating the xUnit.net XML output into MSTest results. <a href="http://edwinfrey.com/blog/2012/06/07/using-xunit-with-team-build-2010/">This webpage</a> explains how it is possible to do it, though the process looks quite longwinded to me.</p> <h3>Writing Tests</h3> <p>Tests are written like this in xUnit.net:</p> <p> <div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">using</span> System;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">using</span> System.Collections.Generic;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">using</span> System.Linq;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">using</span> System.Text;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">using</span> Xunit;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff">using</span> Xunit.Extensions;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> <span style="color: #0000ff">namespace</span> SampleCode.xUnit</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #008000">// Classes do not require attributes, xUnit.net does not care</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CalculatorTests</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #008000">// A "fact" is a test without any parameters </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> [Fact]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Add_AddOneAndTwo_ReturnsThree()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> var result = Calculator.Add(1, 2);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span> <span style="color: #008000">// Many asserts are provided by default, API style is simple and concise</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20"> 20:</span> Assert.Equal(3, result);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21"> 21:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22"> 22:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23"> 23:</span> }</pre><!--CRLF--></div></div><br /><p>There are a much wider variety of assertions provided by xUnit.net by default compared to MSTest. A full list can be found <a href="http://xunit.codeplex.com/wikipage?title=Comparisons&referringTitle=Home#assertions">here</a>.</p><br /><h3>Data Driven Tests</h3><br /><p>Data driven tests in xUnit.net are known as <em>theories</em>. They are test methods that have parameters and can accept input from a number of sources. A theory looks like this:</p><br /><p><br /><div id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> [Theory]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> [InlineData(1, 2, 3)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> [InlineData(3, 4, 7)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> [InlineData(30, 10, 40)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Add_AddDataValues_ReturnsExpectedResult(<span style="color: #0000ff">int</span> first, <span style="color: #0000ff">int</span> second, <span style="color: #0000ff">int</span> expected)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> var actualResult = Calculator.Add(first, second);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> Assert.Equal(expected, actualResult);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> }</pre><!--CRLF--></div></div><br /><p>Out of the box xUnit.net can accept input from the following sources:</p><br /><ul><br /><li>Inline data <br /><li>Property data <br /><li>Excel spreadsheet <br /><li>OleDb connection <br /><li>SQL Server database</li></ul><br /><h3>Running Tests</h3><br /><p>Until Visual Studio 2012 comes out xUnit.net tests cannot be run directly via the IDE but there are a number of other options available.</p><br /><div style="padding-bottom: 0px; padding-left: 0px; width: 592px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:9ff11c63-9bfd-40b7-9167-17bb0d39c58f" class="wlWriterEditableSmartContent"><a href="http://lh3.ggpht.com/-yJtbdQZrHd8/UFOQVOKncwI/AAAAAAAAAHs/JgygCB60P90/xUnitConsole-8x6.png?imgmax=800" title="The console runner" rel="thumbnail"><img border="0" src="http://lh5.ggpht.com/-1A0gtd3_JmE/UFOQWUCI7bI/AAAAAAAAAH0/6RieX9Oa7wQ/xUnitConsole%25255B10%25255D.png?imgmax=800" width="580" height="361" /></a></div><br /><p>The console runner is the most basic test runner available and works from the command line.</p><br /><div style="padding-bottom: 0px; padding-left: 0px; width: 592px; padding-right: 0px; display: block; float: none; margin-left: auto; margin-right: auto; padding-top: 0px" id="scid:8747F07C-CDE8-481f-B0DF-C6CFD074BF67:0711261e-3e3b-4911-9e69-305a6a89cbce" class="wlWriterEditableSmartContent"><a href="http://lh4.ggpht.com/-LRoNQpyL9hI/UFOQXVjXLbI/AAAAAAAAAH8/zkg1-LZYc6c/xUnitGUI-8x6.png?imgmax=800" title="The GUI runner" rel="thumbnail"><img border="0" src="http://lh4.ggpht.com/-zCZG6RiJdqs/UFOQYQGjqZI/AAAAAAAAAIE/c1b_L0cxDNU/xUnitGUI%25255B5%25255D.png?imgmax=800" width="580" height="515" /></a></div><br /><p>The GUI runner is a simple standalone application with it’s own user interface and is not as full featured as the NUnit GUI runner but is capable enough. Instead of a tree view like the NUnit GUI runner this test runner presents a flat list of tests but they can be filtered down by search terms, assembly and/or trait values.</p><br /><p>One aspect that is different from the NUnit GUI runner is that although this runner will detect and reload test assemblies when rebuilt it will <em>not</em> automatically run the selected tests again, unlike NUnit.</p><br /><h3>MSBuild</h3><br /><p>Unlike MSTest and NUnit, xUnit.net provides it’s <a href="http://xunit.codeplex.com/wikipage?title=HowToUseMSBuild&referringTitle=Home">own custom MSBuild task</a> which allows direct integration into the build process. A project file can then use it similar to this:</p><br /><p><br /><div id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">UsingTask</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #ff0000">AssemblyFile</span><span style="color: #0000ff">="..\packages\xunit.1.9.1\lib\net20\xunit.runner.msbuild.dll"</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #ff0000">TaskName</span><span style="color: #0000ff">="Xunit.Runner.MSBuild.xunit"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff"><</span><span style="color: #800000">Target</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="AfterBuild"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff"><</span><span style="color: #800000">xunit</span> <span style="color: #ff0000">Assembly</span><span style="color: #0000ff">="$(TargetPath)"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> <span style="color: #0000ff"></</span><span style="color: #800000">Target</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><br /><p>Build output then looks similar to the following:</p><br /><p><pre><code>------ Build started: Project: SampleCode, Configuration: Debug Any CPU ------<br /> SampleCode -> C:\TalentQ\Experiments\UnitTestAnalysis\SampleCode\bin\Debug\SampleCode.dll<br />------ Build started: Project: SampleCode.xUnit, Configuration: Debug Any CPU ------<br /> SampleCode.xUnit -> C:\TalentQ\Experiments\UnitTestAnalysis\SampleCode.xUnit\bin\Debug\SampleCode.xUnit.dll<br /> xUnit.net MSBuild runner (32-bit .NET 4.0.30319.269)<br /> xunit.dll: Version 1.9.1.1600<br /> Test assembly: C:\TalentQ\Experiments\UnitTestAnalysis\SampleCode.xUnit\bin\Debug\SampleCode.xUnit.dll<br /> Tests: 4, Failures: 0, Skipped: 0, Time: 0.041 seconds<br />========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========</code></pre><br /><p>The MSBuild task can be configured like the console runner meaning that XML/HTML results can also be saved too. See the <a href="http://xunit.codeplex.com/wikipage?title=HowToUseMSBuild&referringTitle=Home">documentation</a> for more details.</p><br /><p>Another useful thing is that, because it integrates into MSBuild, any failed tests will appear as errors in the IDE error list so by definition this would make it a failed build. The only slight oddity though is that, in its current form (version 1.9.1), double-clicking the errors in the error list does not take you to the correct source code as line numbers given are referring to the project file not source files.</p><br /><h3>Additional Runners</h3><br /><p>xUnit.net also provides these test runners as standard:</p><br /><ul><br /><li><a href="http://xunit.codeplex.com/wikipage?title=HowToUseTdNet&referringTitle=Home">TestDriven.NET</a> <br /><li><a href="http://xunit.codeplex.com/wikipage?title=HowToUseResharper&referringTitle=Home">ReSharper</a> <br /><li><a href="http://xunit.codeplex.com/wikipage?title=HowToUseTeamCity&referringTitle=Home">TeamCity</a> <br /><li><a href="http://xunit.codeplex.com/wikipage?title=HowToUseCcNet&referringTitle=Home">CruiseControl.net</a></li></ul><br /><h3>Performance</h3><br /><p>Performance of running tests seems to be faster than MSTest, even with a significant number of tests to execute.</p><br /><h3>Reports</h3><br /><p>Apart from the output represented by various test runners, an XML report can be produced by either the console or MSBuild runner. Once in an XML format, this can then be transformed into another format, e.g. a HTML file to make it human readable or a *.trx (MSTest) output file so that Visual Studio can understand it.</p><br /><p>Fortunately xUnit.net is able to do this transformation for you as long as you provide the XSLT stylesheet to use. Out of the box the following stylesheets are provided:</p><br /><ul><br /><li>HTML – transforms the XML report into a HTML, human-readable report <br /><li>NUnit – transforms the XML report into the same format that NUnit uses</li></ul><br /><h3>Documentation</h3><br /><p>This in my opinion is where xUnit.net falters. Because this is a newer framework documentation is thin on the ground, especially when compared to NUnit. Usually though the features are simple enough to figure out and there is sample code provided in the CodePlex repository, but you may also have to do some searching around on the internet for an explanation of some things.</p><br /><h3>Extensibility</h3><br /><p>One of the big selling points of xUnit.net is its extensibility which is far greater than either MSTest or NUnit. Some examples are:</p><br /><h4>Report Transformations</h4><br /><p>By default the console runner can provide XML, HTML or NUnit report output, but this is actually configurable by defining further command line switches mapped to a suitable XSLT stylesheet to transform in into another format (e.g. *.trx (MSTest) format).</p><br /><h4>xUnit.net Extensions</h4><br /><p>The entire xUnit.net extensions assembly is a perfect example of its extensibility. For instance <code>[Theory]</code> methods are actually specialised <code>[Fact]</code> methods that do some additional work.</p><br /><h4>More Assertions</h4><br /><p>If there are not enough assertion functions for your liking you can implement more by extending the Assertions class rather than having to write your own wrappers for it. For example:</p><br /><p><br /><div id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">class</span> MyAssertions </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #008000">// By using extension methods you can add more assertions</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">static</span> <span style="color: #0000ff">void</span> Test(<span style="color: #0000ff">this</span> Assertions assert)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> { </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> Assert.True(<span style="color: #0000ff">true</span>);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> <span style="color: #008000">// By deriving from TestClass a modifiable Assert class becomes available </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CalculatorTests : TestClass </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> [Fact]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> CustomAssert()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> <span style="color: #008000">// This is our own assertion method</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> Assert.Test();</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span> }</pre><!--CRLF--></div></div><br /><h3>My Opinion</h3><br /><p>This is a tricky one. Whereas I felt that NUnit was miles ahead of MSTest, the difference between NUnit and xUnit.net is a lot smaller. To be fair you could pick either one and be extremely productive so it all comes down to nit-picking.</p><br /><p>Both NUnit and xUnit.net have their benefits and each have a few disadvantages but in the end, after much careful thought, I’ve decided to use xUnit.net as my primary test framework for the following reasons:</p><br /><ol><br /><li>I like the fact that XSLT stylesheets are provided with the framework so I don’t have to define my own HTML report format based on the XML output. And if I wanted to change the layout of the report I would at least have something to modify as a base. <br /><li>Overall the MSBuild task is a great way of integrating xUnit.net into the build process. Whereas MSTest and NUnit could be run as a task the fact was that they were just starting a new process; the only way you would know your tests had failed was by checking the exit code of the test runner, which wouldn’t tell you anything useful. <br /><li>The extensibility of framework is a real plus point. I haven’t needed to extend any features yet – consider that a testament to the basics it got right – but it’s nice to know that it is there if needed. <br /><li>Finally I just feel that it has a lot of potential. It may have some niggles to iron out but I feel confident that they will be.</li></ol><br /><p>All of the above are very minor points; like I said I could have just as easily went with NUnit, but xUnit.net just edged ahead in my opinion. </p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com3tag:blogger.com,1999:blog-6872827378253370843.post-22014337963855664132012-09-02T13:51:00.001+01:002012-09-02T13:51:57.110+01:00Testing Framework Review: NUnit<p>In a <a href="http://inthecodingzone.blogspot.co.uk/2012/08/testing-framework-review-mstest.html">previous post I reviewed MSTest</a>. This time I will focus on <a href="http://www.nunit.org/">NUnit</a>. NUnit is an open-source testing framework that has been around for a long time – in fact I think there was a time when this was the <em>only</em> test framework for .NET - and is very mature and stable. From the NUnit website:</p> <blockquote> <p>NUnit is a unit-testing framework for all .Net languages. Initially ported from <a href="http://www.junit.org/">JUnit</a>, the current production release, version 2.6, is the seventh major release of this xUnit based unit testing tool for Microsoft .NET. It is written entirely in C# and has been completely redesigned to take advantage of many .NET language features, for example custom attributes and other reflection related capabilities. NUnit brings xUnit to all .NET languages.</p></blockquote> <h3>Integration</h3> <p>NUnit is a separate project meaning that direct Visual Studio support is not provided. However <a href="http://www.microsoft.com/visualstudio/11/en-us">Visual Studio 2012</a> will <a href="http://msdn.microsoft.com/en-us/library/hh598952.aspx">allow different frameworks apart from MSTest to be used</a> as the primary unit testing framework - this includes <a href="http://www.codewrecks.com/blog/index.php/2012/03/05/running-nunit-and-xunit-tests-in-tfs11-build/">TFS builds</a> too. <p>In the meantime, the following steps are required: <h2></h2> <h3>Download from NuGet</h3> <p><a href="http://nuget.org/">NuGet</a> provides two packages for NUnit: <ul> <li><a href="http://nuget.org/packages/NUnit">NUnit</a> <li><a href="http://nuget.org/packages/NUnit.Runners">NUnit.Runners</a></li></ul> <p>The <strong>NUnit</strong> package contains the core of the framework while the <strong>NUnit.Runners</strong> contains the various test runners needed to run the test assemblies. <p>Adding these packages to a Visual Studio project is very simple as NuGet will automatically download the latest versions and insert the correct project references required. <p>One initial gotcha though is that all the test runners by default assume the .NET 2.0 CLR is the correct runtime environment to use, so if you are using the .NET 4 CLR you will have to update all the *.config files to use the correct framework version; simply a matter of commenting out one line in each *.config file, though there are several to modify.</p> <h3>Project Items and Snippets</h3> <p>Unlike MSTest which provides project items and snippets with the IDE, NUnit does not provide any by default. However <a href="http://msdn.microsoft.com/en-us/library/s365byhx(v=vs.100).aspx">these items are not difficult to create yourself if required</a>.</p> <h3>Standalone</h3> <p>Although some initial setup is required one possible benefit is that NUnit is a standalone framework - it can be run anywhere without requiring installation, simply by copying the correct files.</p> <h3>Team Build</h3> <p>TFS 2012 will be able to use the same <a href="http://blogs.msdn.com/b/visualstudioalm/archive/2012/07/31/writing-a-visual-studio-2012-unit-test-adapter.aspx">Unit Test plugin model</a> that Visual Studio 2012 uses meaning in future it will be a lot easier to integrate NUnit into the Team Build process. <p>Until then though it is possible to use NUnit within Team Build but only via a custom build activity and translating the NUnit XML output into MSTest results. <a href="http://tfsbuildextensions.codeplex.com/wikipage?title=How%20to%20integrate%20the%20nUnit%20build%20activity&referringTitle=Documentation">This webpage</a> explains how it is possible to do it, though the process looks quite longwinded to me.</p> <h3>Writing Tests</h3> <p>Tests are written like this in NUnit:</p> <p> <div id="codeSnippetWrapper"> <div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff">using</span> System;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff">using</span> System.Collections.Generic;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff">using</span> System.Linq;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> <span style="color: #0000ff">using</span> System.Text;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">using</span> NUnit.Framework;</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> <span style="color: #0000ff">namespace</span> SampleCode.NUnit</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> <span style="color: #008000">// Denotes a Test Class for NUnit to find</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> [TestFixture]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum11"> 11:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">class</span> CalculatorTests</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum12"> 12:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum13"> 13:</span> <span style="color: #008000">// Denotes a Test Method for NUnit to run </span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum14"> 14:</span> [Test]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum15"> 15:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Add_AddOneAndTwo_ReturnsThree()</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum16"> 16:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum17"> 17:</span> var result = Calculator.Add(1, 2);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum18"> 18:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum19"> 19:</span> <span style="color: #008000">// Assertions can be written with a fluent API to make them more descriptive</span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum20"> 20:</span> Assert.That(result, Is.EqualTo(3));</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum21"> 21:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum22"> 22:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum23"> 23:</span> }</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum24"> 24:</span> }</pre><!--CRLF--></div></div><br /><p>There are a much wider variety of assertions provided by NUnit compared to MSTest. There is also a <a href="http://www.nunit.org/index.php?p=constraintModel&r=2.6.1">fluent/constraint API</a> provided which allows a more descriptive style of writing if you find that useful.</p><br /><h3>Data Driven Tests</h3><br /><p>NUnit <a href="http://www.nunit.org/index.php?p=testCase&r=2.6.1">supports data-driven tests</a> by writing parameterised test methods and decorating them with special attributes like so:</p><br /><div id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> [Test]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> [TestCase(1, 2, 3)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> [TestCase(5, 10, 15)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum4"> 4:</span> [TestCase(30, 2, 32)]</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum5"> 5:</span> <span style="color: #0000ff">public</span> <span style="color: #0000ff">void</span> Add_AddDataValues_ReturnsExpectedResult(<span style="color: #0000ff">int</span> first, <span style="color: #0000ff">int</span> second, <span style="color: #0000ff">int</span> expected)</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum6"> 6:</span> {</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum7"> 7:</span> var actualResult = Calculator.Add(first, second);</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum8"> 8:</span> </pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum9"> 9:</span> Assert.That(actualResult, Is.EqualTo(expected));</pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum10"> 10:</span> }</pre><!--CRLF--></div></div><br /><p>Unlike MSTest, NUnit sees this as three separate tests and will display it as such in the test runners.</p><br /><p>It is also possible to write a data-driven test by defining a data source using the <code><a href="http://www.nunit.org/index.php?p=testCaseSource&r=2.6.1">[TestCaseSource]</a></code> attribute which defines a property/method which returns an enumerable collection of object values to pass in as parameters. <br /><p>The only thing that NUnit does not provide out-of-the-box is the ability to store data values and load from a file/external source, only code values can be used. However, using the <code>[TestCaseSource]</code> attribute utility methods can be created by yourself to do that.</p><br /><h3>Running Tests</h3><br /><p>Until Visual Studio 2012 comes out NUnit tests cannot be run directly via the IDE but there are a number of other options available.</p><br /><p>The console runner is the most basic test runner available and works from the command line.</p><br /><p><a href="http://lh6.ggpht.com/-qVqy5aqW11E/UENWYbhRzdI/AAAAAAAAAHE/C6kLBQ8mES8/s1600-h/NUnitConsole12.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="NUnitConsole" border="0" alt="NUnitConsole" src="http://lh6.ggpht.com/-7mL0A7u6X74/UENWZA_icaI/AAAAAAAAAHM/Vtjds2pvJ_Y/NUnitConsole_thumb10.png?imgmax=800" width="592" height="303"></a></p><br /><p>The GUI runner is a standalone application with it's own user interface. Tests are represented in a tree view along with their results and any failures are reported on the right-hand side. Notice also that data-driven tests are split further down into more tests to run.</p><br /><p><a href="http://lh3.ggpht.com/-9kzYVlJHAm0/UENWaAU_U3I/AAAAAAAAAHU/zwaj6YYgAu0/s1600-h/NUnitGUI3.png"><img style="background-image: none; border-right-width: 0px; padding-left: 0px; padding-right: 0px; display: block; float: none; border-top-width: 0px; border-bottom-width: 0px; margin-left: auto; border-left-width: 0px; margin-right: auto; padding-top: 0px" title="NUnitGUI" border="0" alt="NUnitGUI" src="http://lh5.ggpht.com/--218VpZWhtQ/UENWa0vSTcI/AAAAAAAAAHc/sJOSTkmWdfk/NUnitGUI_thumb1.png?imgmax=800" width="644" height="326"></a></p><br /><p>A nice feature of the GUI runner is that it is able to detect changes in the test assembly when it is rebuilt. When a change is detected, the GUI runner can be configured to reload the assembly and automatically run the last set of tests to allow for a continuous testing strategy.</p><br /><p>It is also possible to run NUnit via an MSBuild task, e.g. as an after-build step. This is done by simply executing the console runner using the <code><Exec></code> task, similar to this:</p><br /><div id="codeSnippetWrapper"><br /><div style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px" id="codeSnippet"><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum1"> 1:</span> <span style="color: #0000ff"><</span><span style="color: #800000">Target</span> <span style="color: #ff0000">Name</span><span style="color: #0000ff">="AfterBuild"</span><span style="color: #0000ff">></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: #f4f4f4; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum2"> 2:</span> <span style="color: #0000ff"><</span><span style="color: #800000">Exec</span> <span style="color: #ff0000">Command</span><span style="color: #0000ff">="..\packages\NUnit.Runners.2.6.1\tools\nunit-console.exe $(TargetPath)"</span> <span style="color: #0000ff">/></span></pre><!--CRLF--><pre style="border-bottom-style: none; text-align: left; padding-bottom: 0px; line-height: 12pt; background-color: white; margin: 0em; border-left-style: none; padding-left: 0px; width: 100%; padding-right: 0px; font-family: 'Courier New', courier, monospace; direction: ltr; border-top-style: none; color: black; border-right-style: none; font-size: 8pt; overflow: visible; padding-top: 0px"><span style="color: #606060" id="lnum3"> 3:</span> <span style="color: #0000ff"></</span><span style="color: #800000">Target</span><span style="color: #0000ff">></span></pre><!--CRLF--></div></div><br /><p>Build output then appears as follows:<pre><code>------ Build started: Project: SampleCode, Configuration: Debug Any CPU ------<br /> SampleCode -> C:\Experiments\UnitTestAnalysis\SampleCode\bin\Debug\SampleCode.dll<br />------ Build started: Project: SampleCode.NUnit, Configuration: Debug Any CPU ------<br /> SampleCode.NUnit -> C:\Experiments\UnitTestAnalysis\SampleCode.NUnit\bin\Debug\SampleCode.NUnit.dll<br /> NUnit-Console version 2.6.1.12217<br /> Copyright (C) 2002-2012 Charlie Poole.<br /> Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.<br /> Copyright (C) 2000-2002 Philip Craig.<br /> All Rights Reserved.<br /><br /> Runtime Environment - <br /> OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1<br /> CLR Version: 4.0.30319.269 ( Net 4.0 )<br /><br /> ProcessModel: Default DomainUsage: Single<br /> Execution Runtime: net-4.0<br /> ....<br /> Tests run: 4, Errors: 0, Failures: 0, Inconclusive: 0, Time: 0.103 seconds<br /> Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0<br /><br />========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========</code></pre><br /><h3></h3><br /><h3>Performance</h3><br /><p>Performance of running tests seems to be faster than MSTest, even with a significant number of tests to execute.</p><br /><h3>Reports</h3><br /><p>Apart from the output represented by various test runners, an XML report can be produced by either the console or GUI runner. Once in an XML format, this can then be transformed into another format, e.g. a HTML file to make it human readable or a *.trx (MSTest) output file so that Visual Studio can understand it. <br /><p>Unfortunately no sample XSL stylesheets are provided as standard by the NUnit package so this work has to be carried out by yourself or by searching on the Internet for a suitable one.</p><br /><h3>Extensibility</h3><br /><p>There are some <a href="http://www.nunit.org/index.php?p=extensibility&r=2.6.1">extensibility points within NUnit</a> but a lot of the most common features are provided as standard so there is very little else to require from it.</p><br /><h3>My Opinion</h3><br /><p>In my opinion NUnit is a lot better than MSTest. NUnit is very stable, fast, well supported and documented and supports many of the use case scenarios that you would typically use day to day. Although MSTest beats it in terms of IDE integration even without the new Unit Test Adapter it is still very easy to setup and use; the fact that the GUI runner automatically reloads assembly changes means you can have an almost-continuous test setup.</p><br /><p>And for a while I was perfectly happy with using NUnit, until I found out about <a href="http://xunit.codeplex.com/">xUnit.net</a>…</p><br /><p>More next time!</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-65498641178897051492012-08-29T21:25:00.001+01:002012-08-29T21:25:49.310+01:00Time for a Change<p>When I first started this blog I wasn’t sure how long it would last, so I made some initial decisions such as picking a <a href="http://www.blogger.com">free blogging platform</a> as my host. As a result I may have gone a bit overboard with the design of it; it is hard to know what your blog looks like when there is no content on it to give you an idea. Because of this I felt that the look of this blog was too dark and too “busy”.</p> <p>Taking a leaf out of Microsoft’s newfound focus on it’s <a href="http://en.wikipedia.org/wiki/Metro_(design_language)">Metro/Modern/Whatever-you-call-it UI style</a>, I thought I would make the design simpler and focus on making it more readable and just focus on the content, now that I actually have some.</p> <p>This is also the first time I’m writing a post in something other than Blogger’s online editing tools. They were fairly good but there were just too many annoyances I found, such as filling in hyperlinks would send me right back to the top of the page, and formatting (especially code snippets) was a real pain. This post was written in <a href="http://windows.microsoft.com/en-US/windows-live/essentials-other-programs">Windows Live Writer</a> which I am very impressed with so far.</p> <p>So just a quick update this time, normal service will resume shortly.</p> Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-60721012804291186712012-08-26T20:43:00.000+01:002012-08-26T20:43:05.563+01:00Testing Framework Review: MSTestRecently I wrote about <a href="http://inthecodingzone.blogspot.co.uk/2012/08/what-ive-learned-about-test-driven.html">what I learned from Test Driven Development (TDD)</a> and for the most part glossed over the issue of which testing framework to use. In that post I said that I didn't like <a href="http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework">MSTest</a> and ended up preferring <a href="http://xunit.codeplex.com/">xUnit.net</a>, but was I too quick to judge? Was that a snap decision? Had I really investigated all the features of each framework?<br />
<br />
As I am the sole TDD knowledge base at work currently I was also asked to write up an objective analysis of each the major frameworks that I was considering. I therefore thought this would be a good opportunity to share my findings to the world in case anyone else found them useful.<br />
<br />
So I shall write three new posts giving my full review of the following .NET test frameworks I looked at and tried out: <a href="http://en.wikipedia.org/wiki/Visual_Studio_Unit_Testing_Framework">MSTest</a>, <a href="http://www.nunit.org/">NUnit</a> and <a href="http://xunit.codeplex.com/">xUnit.net</a>. I'm sure there are others out there but these were the ones I kept seeing through internet research on a regular basis. I shall try and present the facts as best I can but you will also see my opinions sprinkled throughout.<br />
<br />
This first post will be focused on...<br />
<br />
<h2>
MSTest</h2>
<div>
MSTest is the testing framework from Microsoft and is built into some previous versions Visual Studio but is included as standard with Visual Studio 2010, which is the version I will be referring to from here on out. You can see the <a href="http://msdn.microsoft.com/en-us/library/ms243147.aspx">reference documentation here</a>.</div>
<div>
<br /></div>
<h2>
Integration</h2>
<div>
Because MSTest is built into Visual Studio itself, integration between Visual
Studio and MSTest is very tight. Straight from the IDE you can:<br />
<ul>
<li>Create a test project</li>
<li>Create a test class</li>
<li>Use code snippets provided to define a test method</li>
<li>Run tests using commands/shortcuts and view the results in an IDE tool
window</li>
<li>View report/result files.</li>
</ul>
Also, TFS 2010 has the option built-in to run MSTest assemblies as part of a
Team Build process and it understands the MSTest result file format so it can be
included in the build output.<br />
<br />
A possible downside of deep integration though is that MSTest cannot run
standalone without Visual Studio installed, unlike other frameworks. For instance, if a Continuous
Integration (CI) build server were set up you would have to install the entire
IDE just to use MSTest. It is possible to just find the necessary assemblies required for MSTest to force it to be standalone, <a href="http://www.shunra.com/shunrablog/index.php/2009/04/23/running-mstest-without-visual-studio/">as this blog post describes</a>, but you would also have to fiddle around with the registry to include certain references which could be more painful than it is worth.<br />
<br />
<h2>
Writing Tests</h2>
</div>
<div>
So what do unit tests look like with MSTest? Here is a simple example:</div>
<div>
<br /></div>
<pre class="brush: csharp">using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace SampleCode.MSTest
{
// Denotes a Test Class for MSTest to look for
[TestClass]
public class CalculatorTests
{
// Denotes a Test Method for MSTest to run
[TestMethod]
public void Add_AddOneAndTwo_ReturnsThree()
{
int first = 1;
int second = 2;
var result = Calculator.Add(first, second);
// MSTest assertion
Assert.AreEqual(3, result);
}
}
}
</pre>
<br />
MSTest provides several assertion methods via the <code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.aspx">Assert</a></code> class,
though it does not seem as feature complete as other frameworks.<br />
<br />
Methods provided are:<br />
<ul>
<li>AreEqual</li>
<li>AreNotEqual</li>
<li>AreSame</li>
<li>IsInstanceOfType</li>
<li>IsNotInstanceOfType</li>
<li>IsNull</li>
<li>IsNotNull</li>
<li>IsTrue</li>
<li>IsFalse</li>
</ul>
There are also specialised <code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.stringassert.aspx">StringAssert</a></code> and
<code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.collectionassert.aspx">CollectionAssert</a></code> APIs.<br />
<br />
Exception assertions must be done using the <code><a href="http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.expectedexceptionattribute.aspx">[ExpectedException]</a></code>
attribute. Other frameworks have moved on from this approach, making MSTest a bit antiquated in this area. Below is an example of how to test that something has thrown an exception:<br />
<br />
<pre class="brush: csharp">[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void ExceptionTest()
{
TestMethod(null);
}
</pre>
<br />
It is possible to make your own assertions but you will have to define your own
<code>Assert</code> class to provide additional assertions. For example, <a href="http://blog.drorhelper.com/2009/08/checking-expected-exception-message.html">this
blog post</a> explains how to define an <code>Assert.Throws()</code> method to
replace the clunky syntax for exception checking shown above for a more
functional, fluid approach.<br />
<br />
<h2>
Data Driven Tests</h2>
<div>
Originally I thought that MSTest was not able to use data driven tests - that is tests which require input from an external source - but I was wrong. MSTest <a href="http://msdn.microsoft.com/en-us/library/ms182527.aspx">does support data driven tests</a> but not in the same way as most other frameworks.</div>
<div>
<br /></div>
<div>
Below is an example of such a test:</div>
<div>
<br /></div>
<pre class="brush: csharp">[TestMethod]
[DataSource("Microsoft.VisualStudio.TestTools.DataSource.CSV", "|DataDirectory|\\Add_DataDrivenTestCases.csv", "Add_DataDrivenTestCases#csv", DataAccessMethod.Sequential)]
[DeploymentItem("SampleCode.MSTest\\Add_DataDrivenTestCases.csv")]
public void Add_DataDriven_ReturnsCorrectResult()
{
var first = Convert.ToInt32(TestContext.DataRow["First"]);
var second = Convert.ToInt32(TestContext.DataRow["Second"]);
var expectedResult = Convert.ToInt32(TestContext.DataRow["Result"]);
var actualResult = Calculator.Add(first, second);
Assert.AreEqual(expectedResult, actualResult);
}
</pre>
<br />
Note the following:<br />
<br />
<ol>
<li>MSTest does not support parameters in test methods like other frameworks do.</li>
<li>A <code>[DataSource]</code> attribute is used to define where the input data comes from. This example uses a CSV file but XML and databases are supported too.</li>
<li>Because parameters are not supported, all data input has to be extracted from a <a href="http://msdn.microsoft.com/en-us/library/ms404699.aspx"><code>TestContext</code> class</a> (which you have to define yourself). Getting each column of the file actually returns an object, meaning you have to do yet more work to convert values into something meaningful.</li>
</ol>
<div>
In comparison to other frameworks (which I will highlight in future posts) this feature feels incredibly clunky to me. I used Visual Studio's IDE tools to auto-generate this test method for me as I doubt I would remember the syntax for it each time. It should also be noted that you cannot have inline data - that is data defined as constants such as what NUnit supports.<br />
<br />
<h2>
Running Tests</h2>
</div>
<div>
Running tests in MSTest is incredibly easy. Simply right-click in a test code
file and click "Run Tests" for the Test Window to appear, such as below:<br />
<br />
<div class="separator" style="clear: both; text-align: center;">
<a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWFL5SMd-EDter2fGwdg4MNP9ophnBhztDn__U-cbWyrelG_5uB3nHrVrWeDz1XsrUdVzV7TuSPt3r-ev1IPzReQjDNwnYZMb5rHtpxVTIlWJtpFjQmkwANeRuGsSfdAw2o0nI-SqOUdQl/s1600/MSTestResults.png" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"><img border="0" height="144" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgWFL5SMd-EDter2fGwdg4MNP9ophnBhztDn__U-cbWyrelG_5uB3nHrVrWeDz1XsrUdVzV7TuSPt3r-ev1IPzReQjDNwnYZMb5rHtpxVTIlWJtpFjQmkwANeRuGsSfdAw2o0nI-SqOUdQl/s640/MSTestResults.png" width="640" /></a></div>
<br />
<br />
From this window you can view detailed results of each test.<br />
<br />
For a data-driven test, only one row appears in this window yet it is run
multiple times for each row in the data source, which can appear confusing.
Viewing the detailed results of a data-driven test will show the individual
results though.<br />
<br />
It is also possible to run MSTest via an <a href="http://msdn.microsoft.com/en-us/library/0k6kkbsd.aspx">MSBuild task</a>, e.g. as an after-build
step. This is done by simply executing the MSTest console application using the
<code><a href="http://msdn.microsoft.com/en-us/library/microsoft.build.tasks.exec.aspx"><Exec></a></code> task like this:<br />
<br />
<pre class="brush: xml"><Target Name="AfterBuild">
<Exec Command='"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\mstest.exe" /testcontainer:"$(TargetPath)"' />
</Target></pre>
<br />
Build output then appears as follows:<br />
<br />
<pre><code>------ Build started: Project: SampleCode.MSTest, Configuration: Debug Any CPU ------
SampleCode.MSTest -> C:\Experiments\UnitTestAnalysis\SampleCode.MSTest\bin\Debug\SampleCode.MSTest.dll
Microsoft (R) Test Execution Command Line Tool Version 10.0.30319.1
Copyright (c) Microsoft Corporation. All rights reserved.
Loading C:\Experiments\UnitTestAnalysis\SampleCode.MSTest\bin\Debug\SampleCode.MSTest.dll...
Starting execution...
Results Top Level Tests
------- ---------------
Passed SampleCode.MSTest.CalculatorTests.Add_AddOneAndTwo_ReturnsThree
Passed SampleCode.MSTest.CalculatorTests.Add_DataDriven_ReturnsCorrectResult
2/2 test(s) Passed
Results Add_DataDriven_ReturnsCorrectResult
------- -----------------------------------
Passed SampleCode.MSTest.CalculatorTests.Add_DataDriven_ReturnsCorrectResult
Passed SampleCode.MSTest.CalculatorTests.Add_DataDriven_ReturnsCorrectResult
Passed SampleCode.MSTest.CalculatorTests.Add_DataDriven_ReturnsCorrectResult
3/3 test(s) Passed
Summary
-------
Test Run Completed.
Passed 5
---------
Total 5
Results file: C:\Experiments\UnitTestAnalysis\SampleCode.MSTest\TestResults\petermonks_ACHILLES 2012-08-14 10_42_21.trx
Test Settings: Default Test Settings
========== Build: 2 succeeded or up-to-date, 0 failed, 0 skipped ==========
</code></pre>
<br />
<h2>
Performance</h2>
</div>
<div>
Performance of running tests seems a little slower than other frameworks as
MSTest saves all results to file meaning IO time is consumed a lot. This didn't cause any problems with my simple test suite but this might
be significant if hundreds of tests are being run at once.</div>
<div>
<br /></div>
<h2>
Extensibility</h2>
<div>
Since .NET 4 and Visual Studio 2010, MSTest has been able to be extended to
some degree although doing so is hard work. For example, <a href="http://blogs.msdn.com/b/vstsqualitytools/archive/2009/09/04/extending-the-visual-studio-unit-test-type-part-2.aspx">this
blog post</a> explains how to extend MSTest to use inline data-driven tests that
have parameters, such as:<br />
<br />
<pre class="brush: csharp">[TestMethod]
[Row(1, 2, 3)]
[Row(4, 5, 6)]
public void ParameterTest(int x, int y, int z)
{
// Test code here...
}
</pre>
<br />
However from this post it looks incredibly long-winded to implement and
setup, whereas other frameworks have this ability as a built-in feature.<br />
<br />
<h2>
My Opinion</h2>
</div>
<div>
So these are the facts I researched, what do I think about MSTest now?</div>
<div>
<br /></div>
<div>
Overall I am still of the opinion that I was right to not use it. Having tried other frameworks, which I will give my review on in future posts, I can see that MSTest is clunky to use and not as fully featured as other frameworks. The only <a href="http://desktoppub.about.com/cs/freelance/a/usp.htm">Unique Selling Point</a> I can see with it is that it is built into Visual Studio so it is easy to get started with it and integrate it with other Microsoft tools, something we do require at work as we want to use TFS Build to get test results. But seeing as <a href="http://www.richard-banks.org/2012/03/get-visual-studio-11-beta-right-now-for.html">Visual Studio 2012 is going to include the new Unit Test Adapters</a> to allow other test frameworks to be used instead, even this is starting to become a moot point. </div>
<div>
<br /></div>
<div>
I've also noticed that <a href="http://aspnetwebstack.codeplex.com/">some</a> <a href="http://entityframework.codeplex.com/">open-source</a> Mircosoft projects don't even use MSTest and use something else. Maybe it is because they are trying to keep everything self-contained in these projects, but I read it as not even some developers in Mircosoft would consider using their own test framework.</div>
<div>
<br /></div>
<div>
So MSTest isn't for me. Next time I shall review NUnit.</div>
<div>
<br /></div>
<div>
<br /></div>
Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-88676455756562814542012-08-16T21:40:00.000+01:002012-08-16T21:40:48.801+01:00Visual Studio 2012: What's Your Problem?Today I read that <a href="http://blogs.msdn.com/b/somasegar/archive/2012/08/15/visual-studio-2012-and-net-4-5-now-available.aspx">Visual Studio 2012 has finally been released</a> (to MSDN subscribers at least). There are a lot of new features I'm looking forward to using in my work, some of which are <a href="http://www.hanselman.com/blog/VisualStudio2012AndNETFramework45IsRELEASEDHeres5MinuteVideosToGetYouUpToSpeedQuick.aspx">highlighted in these videos</a>. And yet instead of people being excited about it, all I see in blog comments are people still complaining about this:<br />
<br />
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Visual-Studio-2012-RC-is-released---The-_AA5F/Visual%20Studio%20Light%20Theme_2.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="275" src="http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Visual-Studio-2012-RC-is-released---The-_AA5F/Visual%20Studio%20Light%20Theme_2.png" width="400" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Too little colour, TOO MUCH SCREAMING!!<br />Image courtesy of Scott Hanselman (<a href="http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Visual-Studio-2012-RC-is-released---The-_AA5F/Visual%20Studio%20Light%20Theme_2.png">http://www.hanselman.com/blog/content/binary/Windows-Live-Writer/Visual-Studio-2012-RC-is-released---The-_AA5F/Visual%20Studio%20Light%20Theme_2.png</a>)</td></tr>
</tbody></table>
<br />
Seriously, are we still complaining about this?<br />
<br />
I have to admit that when I first saw screenshots of the new interface I also thought "what have they done?" This was back when <i>everything</i> was grey and dull. I initially didn't like the UI but rather than just complain endlessly about it I thought I would wait until I could at least try it myself and not judge it on a few screenshots of a beta product. I even gave what I hoped was constructive criticism about it , like many others did. And eventually Microsoft got the hint and made changes and toned down the extreme parts of the new UI and now I feel more comfortable with it.<br />
<br />
But this UI change has ended up masking any number of new features and improvements that actually make you <i>productive</i> to the point that people can only focus on one thing: they hate how it looks.<br />
<br />
Now I'm not saying that it is perfect or anything, or that it ever could be, but I personally am happy enough with the final result and want to focus on what it can <i>do</i> rather than how it <i>looks</i>. Yet when I see comments like this still I wonder what people are really focusing on:<br />
<br />
<blockquote class="tr_bq">
<div style="background-color: white; color: #424242; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-top: 12px;">
Dear Microsoft,</div>
<div style="background-color: white; color: #424242; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-top: 12px;">
I've been a fan and supporter for 20+ years. This time you guys outdid yourselves (yes, I am being sarcastic).</div>
<div style="background-color: white; color: #424242; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-top: 12px;">
WHAT IN THE WORLD WERE YOU GUYS SMOKING WHEN YOU CAME UP WITH THE BRILLIANT IDEA OF GETTING RID OF THE COLORS???</div>
<div style="background-color: white; color: #424242; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-top: 12px;">
I CAN'T WORK LIKE THIS. I VERY QUICKLY UNINSTALLED IT AND WILL NOT ALLOW ANY DEVELOPER ON MY TEAM TO USE THIS. OUR PRODUCTIVITY WOULD FALL BY AT LEAST 30% IF WE STICK TO THIS IDE.</div>
<div style="background-color: white; color: #424242; font-family: 'Segoe UI', 'Lucida Grande', Verdana, Arial, Helvetica, sans-serif; font-size: 13px; line-height: 18px; margin-top: 12px;">
JUST IN CASE YOU ARE WONDERING WHY I'M TYPING EVERYTHING IN UPPER CASE, IS BECAUSE I'M TRYING TO GIVE YOU A TASTE OF YOUR OWN MEDICINE!!!!!</div>
</blockquote>
It's not even constructive, this is just a person ranting to the world because they can. Unfortunately a lot of people follow this tack so it just feels like I'm drowning in negativity.<br />
<br />
I try very hard to not be critical of things and if I have to complain I try very hard to at least give suggestions to improve something, but it seems the age of the Internet and social media simply makes us into people who want to argue for arguments sake and that disappoints me.<br />
<br />
And I want Microsoft to know that I at least am looking forward to using VS2012.Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-56787744966266580842012-08-10T13:07:00.001+01:002012-08-10T13:17:18.963+01:00What I've Learned About Test Driven DevelopmentAt the end of April this year me and my colleagues prepared and deployed a big website/system update. A lot of things would change and get better and despite our rather lax testing procedures - testing being not very formal and done by us developers - we felt we had tested it as much as we possibly could and were very happy with what we did. We deployed it over a weekend with scheduled downtime, did our updates along with some server enhancements, and brought the site back up...<br />
<br />
...Starting on the following Monday and continuing for the <i>next two weeks</i> we did nothing but patch holes with endless hotfixes and grovel to our customers promising that we will fix all the bugs they were reporting non-stop as soon as possible. One of our web services did not start up again for an entire weekend and our biggest client wanted to know why they couldn't access our systems. Users were complaining that the website kept kicking them out at random times which we eventually found out was being caused by a <a href="http://inthecodingzone.blogspot.co.uk/2012/05/how-windbg-helped-me-find-my.html" target="_blank">StackOverflow exception occurring every 30 minutes and crashing the IIS web process</a>. It got to the point where the CEO got involved and at the eventual end of this nightmare my manager had to go and visit some key clients to personally assure them that all was well and this would never happen again.<br />
<br />
We felt gutted. By our standards this was the most tested release we had ever done and yet it ended up being the worst one in our company's history.<br />
<br />
This is all background to the real purpose of this post. When the dust settled we all sat down and discussed what went wrong and why and one of the key points we learned (though not the only one) was that our testing strategy was dire. In the absence of a real software tester (though we have one now) it was down to the people writing the code to do testing, and it tended to be a quick couple of run-throughs in certain areas to make sure things worked as we expected. This was not good enough and I simply felt that I couldn't trust our own system anymore.<br />
<br />
A friend of mine talked to me about the benefits of <a href="http://en.wikipedia.org/wiki/Test-driven_development" target="_blank">Test Driven Development (TDD)</a> a couple of weeks earlier and at this point I put it towards my team. I felt that, as well as having a proper software tester, we as developers needed to think about testing <i>from the very start</i>. In essence, we had to build <i>quality</i> into our code.<br />
<br />
And so began my long journey into a development practice that I had never tried before and yet now I feel makes so much sense to me. Last week marked the very first unit and functional tests ever entered into our codebase and although they only cover a tiny fraction of our entire code I feel much more comfortable that that code works as it should, even before it goes to our tester to evaluate.<br />
<br />
I will not go into the entire TDD process - there are <a href="https://www.google.co.uk/search?q=test+driven+development" target="_blank">enough resources</a> on this already - but I thought as this was a learning process for me I would share with you what I've learned in the past few months.<br />
<br />
<h2>
<a href="http://osherove.com/blog" target="_blank">Roy Osherove</a> to the Rescue!</h2>
I did a lot of research into TDD, trawling the internet and reading through a book a colleague lent me but I still had many questions and things I was not sure about. What is the difference between a unit test and an integration test? What if your code has to read from a database or a file? What is a stub and what is a mock?<br />
<br />
Then I listened to this <a href="http://hanselminutes.com/169/the-art-of-unit-testing-with-roy-osherove" target="_blank">Hanselminutes podcast</a> of <a href="http://www.hanselman.com/blog/" target="_blank">Scott Hanselman</a> talking to Roy Osherove, author of <a href="http://artofunittesting.com/" target="_blank">The Art of Unit Testing</a>, and all my questions were answered in 30 minutes. If anyone else is having trouble understanding unit testing and TDD I would very much recommend listening to this as it helped me a lot.<br />
<br />
<h2>
No-One Likes MSTest</h2>
<div>
Before you can write your tests though you need a unit testing framework to help you write your them, but which one do you choose?</div>
<div>
<br /></div>
<div>
Initially I started using <a href="http://en.wikipedia.org/wiki/MSTest" target="_blank">MSTest</a> as that came integrated with Visual Studio and I could experiment quickly with learning the TDD process, but in the end I saw some flaws with it - as <a href="http://osherove.com/blog/2011/8/24/why-mstest-is-the-ie6-of-unit-test-frameworks.html" target="_blank">do many others</a>: </div>
<div>
<br /></div>
<div>
<ol>
<li>The benefit of having MSTest integral to Visual Studio can also be it's downfall as you simply cannot run it standalone.</li>
<li>MSTest simply provided the bare minimum of features to make it worthy of calling it a unit testing framework. I learned that other unit testing frameworks were more capable and had far better features than MSTest, including assertion of exceptions and data-driven tests.</li>
<li>The last problem I had was more of a personal one in that the test runner window didn't seem to make it that clear to me that all the tests had passed or failed. Compare the screenshots below of the MSTest and the <a href="http://www.nunit.org/" target="_blank">NUnit</a> test runner:</li>
</ol>
</div>
<div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://www.robusthaven.com/Data/PostModule/6/mstest-test-runner.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="153" src="http://www.robusthaven.com/Data/PostModule/6/mstest-test-runner.jpg" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">An example of the MSTest runner. Notice that tiny little tick at the top of the window? That tells me that all the tests passed.<br />
<br />
Courtesy of Robust Haven (
<a href="http://www.robusthaven.com/blog/linux-development/Unit-test-runner-in-bash-for-C-and-CPP-libraries">http://www.robusthaven.com/blog/linux-development/Unit-test-runner-in-bash-for-C-and-CPP-libraries</a>)</td></tr>
</tbody></table>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://litemedia.info/media/Default/Mint/nunit-gui.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="380" src="http://litemedia.info/media/Default/Mint/nunit-gui.png" width="640" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">Now compare that to the NUnit test runner. See that great big green line? Guess what that means?<br />
<br />
Courtesy of litemedia (
<a href="http://litemedia.info/data-driven-test-cases-in-nunit">http://litemedia.info/data-driven-test-cases-in-nunit</a>)</td></tr>
</tbody></table>
<br /></div>
<div>
<b><br /></b></div>
<div>
So I tried out NUnit which I liked very much and seemed very dependable, and most recently <a href="http://xunit.codeplex.com/">xUnit.net</a> which I finally settled on.</div>
<div>
<br /></div>
<div>
What I learned from this though is that, once you take MSTest out of the equation, <i>any</i> test framework is usually good enough and it simply comes down to personal preference. I went with xUnit.net because it provided several things I found useful straight out-of-the-box such as an MSBuild task to add to your project builds - if a test fails then the build fails - and it provides a XML stylesheet by default to create HTML reports rather than having to make one myself, a la NUnit.</div>
<br />
<h2>
Doing it Backwards</h2>
<div>
The very first stumbling block was that I had to mentally switch around my working style to effectively be back to front. Write tests <i>before</i> code? How was that meant to work, surely you need something there to try out? But as long as you follow the <a href="http://jamesshore.com/Blog/Red-Green-Refactor.html" target="_blank">Red, Green, Refactor</a> process it does actually work.</div>
<div>
<br /></div>
<div>
Even so, for a beginner like me it required a very large mental shift. For my very first unit test I must have sat there for a good half-hour thinking "How do I write this test? Where do I start?" Once you get past the first test - usually making sure something works - then the next test seems a bit more obvious: "What if I pass in the wrong input?" This could produce quite a few more unit tests so now the ball starts rolling. And once the first code function is tested you start to see a pattern so the next batch of tests seem a bit easier to write, and so on.</div>
<div>
<br /></div>
<div>
As long as you can start writing some unit tests to begin with, the process becomes a lot more intuitive up to the point where it seems like second nature and the way you were working before seems so arcane now.</div>
<div>
<br /></div>
<h2>
Designing Your API</h2>
<div>
The other thing that struck me is that, despite the word "test" in Test Driven Development, initially it feels more like I'm writing a very detailed specification for all my objects. As I am building up each test it feels like I am defining what the code should be doing which to my mind is almost like a list of requirements - function A will allow a string to be passed in, but not an empty string or one that has more than 100 characters etc.<br />
<br />
TDD has also made me think a lot more about object dependencies and code design. When I sat down and looked at my codebase as it stands now, many objects in the business logic layer call straight into the data-access layer and database to do something and these objects simply assume that that will just work - there has to be a database present to do <i>anything</i> in my system. For the real world that makes perfect sense as a system without a database is pretty much useless, but in a testing scenario it cannot be assumed that a database is there and for unit testing nothing should be touching external state.<br />
<br />
This led me to wonder how I could actually test anything if all of my code is so inter-dependent on each other (or <b>tightly coupled</b>). The answer for TDD is to make your code <b>loosely coupled</b> instead which impacts your code design and makes you think a lot more about patterns and practices like <a href="http://jamesshore.com/Blog/Dependency-Injection-Demystified.html" target="_blank">Dependency Injection</a>. As a result I'm starting to feel a lot happier with the overall design of my code as it has started to resemble smaller, Lego-sized blocks which can be combined together into bigger systems.<br />
<br />
<h2>
Start From Scratch</h2>
</div>
<div>
Following on from the previous section if you already have a large codebase and start to introduce TDD into it, like me you might find it a bit daunting. Where do you start? Do you retroactively add unit tests into existing code? And what about dependency problems you have?</div>
<div>
<br /></div>
<div>
So I learned that the best way to learn about TDD and introduce it into your working practices is to start on something brand new, a clean slate. That way you can build up your tests and knowledge as you go. And if you can't start from the very beginning? Then pick a new feature that you're due to develop and start thinking about how you would implement it in a TDD fashion. If only one part of your codebase has been written with testability in mind then that is better than nothing.</div>
<div>
<br /></div>
<h2>
Test As Much As You Can</h2>
<div>
My final thought is that initially I thought that you would have to aim for 100% test coverage to make you feel that you had done a good job. While it is a target to aim for, you <i>don't </i>have to achieve it, or maybe it is just impossible to reach that goal for many reasons.</div>
<div>
<br /></div>
<div>
The very first feature I implemented into our product that was written with TDD in mind only has about 30 unit tests and that doesn't even cover the entire feature end-to-end, the reason being that existing code has dependencies that I cannot extricate just yet. But the new code I have written, <i>that</i> was unit tested. In all, the total test coverage is a tiny percentage but at least I can build upon it over time.</div>
<div>
<br /></div>
<div>
All in all I now think in a TDD style and find it difficult when I have to revert back to the old-fashioned cod-then-test mentality. It's only been a few months since I started investigating this process as a possibility but I'm glad that I did as I feel one step closer to being a better programmer.</div>Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-15421608682366397312012-08-01T21:51:00.000+01:002012-09-24T13:41:16.684+01:00Becoming a Father: One Year On - Part 3<br />
This is the third part of my retrospective on my first year as a new father. To view all the parts, please click on one of the links below:<br />
<br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/06/becoming-father-one-year-on-part-1.html" target="_blank">Part 1 - The Beginning</a><br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/07/becoming-father-one-year-on-part-2.html" target="_blank">Part 2 - The First Two Weeks</a><br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/09/becoming-father-one-year-on-part-4.html">Part 4 - The Accident</a><br />
<b><br /></b>
This post focuses on...<br />
<br />
<h2>
Getting the Hang of Things</h2>
<div>
Once I became more accustomed to waking up several times in the night followed by waking up early in the morning to go to work each day, I came to realise that things do tend to settle into a routine (almost). My wife and I learned many things about our son in the first 6 months:</div>
<div>
<br /></div>
<div>
<ol>
<li>He liked to be on the go all the time, he simply did not like sitting still much. This resulted in me usually having to administer <a href="http://www.youtube.com/watch?v=IqhlQfXUk7w" target="_blank">some kind of silly walk</a> whilst carrying him so he felt the exaggerated movement and which kept him happy. Although after 30 seconds of this around the living room my leg muscles would be screaming at me to stop.</li>
<li>He also didn't think much of napping during the day. Whilst other parents might boast that their little angel would have a 1 - 2 hour nap in the afternoon, we were forced to endure almost a whole day of feeling exhausted and looking after him since he would sleep for at most 30 minutes at a time (with usually a 4 - 5 hour gap inbetween).</li>
<li>The flip-side of not napping during the day though was that he at least seemed to understand the <a href="http://www.babycenter.com.au/baby/sleep/understanding/#12" target="_blank">day-night cycle</a> and would sleep longer and better during the night. My wife and I started off going to bed at around 8pm for at least 3 months because we simply couldn't stay awake any longer!</li>
<li>He was heavy and I was weak. When he was born he weighed 8lb 11oz - which for those not in the know is fairly large - and he pretty much worked his way up to the 91st percentile of his baby contemporaries and was generally the largest of all his baby friends. I am not a physically strong person and having to carry him around started to get very draining, though I eventually got more used to it - perhaps it could have been considered as weight training for me!</li>
<li>My wife tried feeding him expressed milk as breastfeeding did not go well but eventually he started to drink more and more formula milk to the point where he could, after a few months, drink almost an entire bottle of it every 3 hours. That could explain the weight gain...</li>
<li>He got to a point 3 months in where he slept pretty much through the night - <a href="http://www.babycentre.co.uk/baby/sleep/sleepallnight/" target="_blank">the holy grail of parenting</a>! But then, at 4 months, he switched things around a bit and did the dreaded <a href="http://cleverfather.com/sleep-regression-babies/" target="_blank">sleep regression</a>. Why babies apparently do this I do not know. I was having dinner with some friends and boasting about how he slept through the night now at such a young age when I got a text message from my wife telling me that he started waking up at night; that was the night when he started waking up several times a night for the next few months. I resolved from then on to <i>never</i> discuss his sleeping habits with anyone other than my wife lest I somehow jinx everything.</li>
<li>Most importantly though was that we could start to see that he had a personality. It is hard to describe in writing but there were little things he did that you could just tell were a part of him.</li>
</ol>
<h3>
The Daily Routine</h3>
</div>
<div>
I found it incredibly helpful that a daily routine seemed to materialise over time - I am a programmer after all! My wife and I both agreed that I would do the (very) early morning feed as once I'm awake I tend to stay awake; I'm a very light sleeper. </div>
<div>
<br /></div>
<div>
Once that was done and everyone was still asleep I could get to my morning chores which started about 6am. These involved having a shower and breakfast for me of course but also cleaning up all the milk bottles, getting the <a href="http://www.babycentre.co.uk/baby/formula/sterilising/" target="_blank">bottle steriliser</a> ready and boiling water for his formula milk for the day. If I had time I'd also prepare his reusable nappies after they had been washed and dried. </div>
<div>
<br /></div>
<div>
At about 7:30am I would go wake up my wife so she could have a shower before I went to work and I would look after the boy in the meantime. We decided that my wife would get as much rest as possible and not the other way around since she would be the one spending all day with him on the go - remember, he didn't like napping. She basically needed as much rest as possible whereas, despite me having to do a full day's work too, at least I would be sitting down for most of it and downing cups of tea through the day.</div>
<div>
<br /></div>
<div>
Once I got home from work I would take over from my wife and give him his bath and get him ready for bed. In the first month that tended to be quite late as he was still getting used to a regular bedtime so that meant I had to learn how to hold him in one arm whilst I ate my dinner with the other. Eventually though I was responsible for putting him to bed by giving him his bedtime bottle, burping him and letting him fall asleep on my shoulder before putting him in his moses basket.</div>
<div>
<br /></div>
<div>
Here's a little secret I'll let you in on: whilst letting him fall asleep on me I spent many a night playing through <a href="http://www.angrybirds.com/" target="_blank">Angry Birds</a> on my phone. I actually got quite far through the game in this fashion!</div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="http://blog.echoenduring.com/wp-content/uploads/2010/11/angry-birds-screenshot-e1290565550754.png" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="213" src="http://blog.echoenduring.com/wp-content/uploads/2010/11/angry-birds-screenshot-e1290565550754.png" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">"What dear? No, I'm putting our son to bed, what did you think I was doing?"<br />
Image courtesy of Echo Enduring Blog (
<a href="http://blog.echoenduring.com/2010/11/23/learning-about-design-from-angry-birds/">http://blog.echoenduring.com/2010/11/23/learning-about-design-from-angry-birds/</a>)</td></tr>
</tbody></table>
<br />
<h3>
It Does Get Better</h3>
<div>
<a href="http://inthecodingzone.blogspot.co.uk/2012/07/becoming-father-one-year-on-part-2.html" target="_blank">My last post</a> may have left you thinking that raising a child is a hellish experience, and initially it is incredibly demanding. It still is but as 6 months roll on you realise that you can deal with things better now, that he also grows up more and changes with you and somehow you both meet in the middle to end up having fun together.</div>
<div>
<br /></div>
<table align="center" cellpadding="0" cellspacing="0" class="tr-caption-container" style="margin-left: auto; margin-right: auto; text-align: center;"><tbody>
<tr><td style="text-align: center;"><a href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR9ZNMiWmLXKpELeI8i0sagaVdiYx0lUFXyhebN3lpviyGf_NH0jlxUlGgOSxdsDG1sLxBSQMq_c1unhCTVrJEdPRGjNruQlOoqTBy0p6i5CWeZJB5EnujxyPBZVb-NV1CRBmgTDrCzIQO/s1600/First6Months.jpg" imageanchor="1" style="margin-left: auto; margin-right: auto;"><img border="0" height="240" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjR9ZNMiWmLXKpELeI8i0sagaVdiYx0lUFXyhebN3lpviyGf_NH0jlxUlGgOSxdsDG1sLxBSQMq_c1unhCTVrJEdPRGjNruQlOoqTBy0p6i5CWeZJB5EnujxyPBZVb-NV1CRBmgTDrCzIQO/s320/First6Months.jpg" width="320" /></a></td></tr>
<tr><td class="tr-caption" style="text-align: center;">He seems a lot happier now :)</td></tr>
</tbody></table>
<div>
<br /></div>
<div>
<b>Next time: <a href="http://inthecodingzone.blogspot.co.uk/2012/09/becoming-father-one-year-on-part-4.html">The Accident - Oh dear...</a></b></div>
Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-8719060829953033052012-07-16T21:22:00.000+01:002012-07-16T21:22:16.813+01:00Is It Really That Complicated?I've recently been reading <a href="http://fabiensanglard.net/" target="_blank">Fabien Sanglard's blog</a>, particularly his fascinating code reviews on the <a href="http://fabiensanglard.net/doom3/index.php" target="_blank">Doom</a> and <a href="http://fabiensanglard.net/quake3/index.php" target="_blank">Quake</a> source engines. Apart from making me feel a bit stupid not understanding <a href="http://en.wikipedia.org/wiki/Binary_space_partitioning" target="_blank">how BSP trees work</a>, something else strikes me regarding my own work:<br />
<br />
<b>What I do isn't really that complicated.</b><br />
<br />
At the heart of my job I write code to make a website work, and if I consider the bare essential tasks that it needs to do I think I'd have the following shortlist:<br />
<ol>
<li>Get data from a database</li>
<li>Do something to the data</li>
<li>Put that data into a webpage and send back to the client</li>
<li>Profit</li>
</ol>
<div>
By now it's safe to assume we've figured out how to do all of these steps easily - except perhaps the last one! There are a ton of ways to read and write to a database from code, either using ADO.NET or a variety of ORM frameworks, just as many ways to visualise that data (WebForms, MVC, Silverlight etc), and the only real work you should do in theory is the logic that sits between those parts.</div>
<div>
<br /></div>
<div>
Yet if this is all I need to do, why does it still seem so complicated to get anything done? Why does it still take me ages to implement a new feature when "code-reuse" should be helping me? I mean, it's not like I'm writing a game engine with crazy 3D maths and physics to calculate in nanoseconds, attempting to cure cancer or even <a href="http://hanselminutes.com/317/it-is-rocket-science-holly-griffith-former-space-shuttle-and-current-space-station-worker" target="_blank">writing software for spacecraft</a>. Apart from some technical challenges that do exist, I think it mainly boils down to two things.<br />
<br />
<h2>
Other People</h2>
</div>
<div>
Your customers usually don't tend to think in the same way as you do. They might say "hey, can you add in the ability to search our website like Google? In fact, can we not just use The Google on our database or something? And possibly email all the search results to us? It can't take that long, right?" I like to try and keep things as simple and generic as possible, yet find that when "other people" get involved it tends to spiral out of control.<br />
<br />
Take, for example, the financial sub-system I inherited from my predecessor. At <a href="http://www1.talentqgroup.com/" target="_blank">work</a> we have a system which calculates how many <i>units</i> each of our clients uses based on what <a href="http://www1.talentqgroup.com/products/assessment-systems/" target="_blank">assessments</a> have been completed and how many reports have been generated. These units are then used by account managers to translate into real money to calculate invoices, such as 1 unit = £10 for instance.</div>
<div>
<br />
So this sounds simple, right? Surely it's just adding up numbers and computers love adding up numbers. Did I mention though that if component A was generated <i>before</i> component B then you only add units for B, but if C and B are combined into one then we halve the units of A. Oh, I forgot, if D is generated between B and A then we add C and E together but only cap to a maximum of 6 (which can be changed based on which country you are in) and <i>then</i> if you bring F into the mix... and this kind of logic goes on and on in an endless spiral of doom.<br />
<br />
Why does the system work this way? Because that is how <i>other people</i> decided it should work, because apparently business rules should never be simple. It also didn't help that this evolved, as most products do, into a big mess which means that business rules end up circling around each other without you even being fully aware of it.<br />
<br />
When I first started this job I had to spend <i>3 months</i> understanding all the many intricacies of this system because only my predecessor knew how it truly worked - despite being told by the managers what they wanted. It has now gotten to the point where only I know how every item is charged for and even the management have to double check with me.<br />
<br />
And to be fair, there is one other thing that tends to complicate matters just as much as other people...<br />
<br />
<h2>
Myself</h2>
</div>
<div>
I tend to get very attached to the code I write. In an ideal world I feel as though my source code should be beautiful to gaze upon, to be able to admire it's sheer simplicity whilst also marvelling at how it can handle so many complex tasks at once. Sometimes I look back on code I wrote maybe a month or two ago, which at the time I was perfectly happy with, yet now I feel it is ugly and horrible and <i>what was I thinking</i>? This simply has to go because now I know <i>exactly</i> how it should be written...</div>
<div>
<br /></div>
<div>
But this is the real world and experience has taught me that sometimes I have to just "get it done" no matter how it ends up. And if we're being honest who else apart from me <i>really</i> cares about what my code looks like? The other day I decided to bash-out three quick features for my website as I felt that customers really needed them; I created them as quickly as possible (since I do have other projects to complete) so the code wasn't pretty, sometimes even copied-and-pasted with some changes. I look back on it now and I don't like how it looks. Yet my customers won't care, because what they see are three new features that make their life easier and <i>they work</i>, which at the end of the day is the most important thing in your product.</div>
<div>
<br /></div>
<h2>
Keep It Simple, Stupid</h2>
<div>
Simplicity is what I strive for in life. I genuinely feel that the simplest solution is always the best as there are fewer complications to consider and less chance of anything going wrong, and I really try to impress that upon people. Yet at the end of the day outside factors have a way of creeping in and adding complications to your best laid plans, and I've built up enough work experience to realise that although the simplest solution may be the best, it's not necessarily what people want.</div>
Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0tag:blogger.com,1999:blog-6872827378253370843.post-89964501206811757202012-07-06T22:06:00.000+01:002012-09-24T13:40:38.004+01:00Becoming a Father: One Year On - Part 2This is the second part of my retrospective on my first year as a new father. To view all the parts, please click on one of the links below:<br />
<br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/06/becoming-father-one-year-on-part-1.html" target="_blank">Part 1 - The Beginning</a><br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/08/becoming-father-one-year-on-part-3.html" target="_blank">Part 3 - Getting the hang of things</a><br />
<a href="http://inthecodingzone.blogspot.co.uk/2012/09/becoming-father-one-year-on-part-4.html">Part 4 - The Accident</a><br />
<b><br /></b>
This post focuses on...<br />
<br />
<h2>
The First Two Weeks</h2>
<div>
The day after my son was born I woke up bleary eyed and called my parents and in-laws - now forever know as "the grandparents" - to tell them the good news; they had been calling all night but I was a little tied up at the time. I had breakfast, a quick shave and headed back to the hospital to pick up my wife and son.</div>
<div>
<br /></div>
<div>
My wife was fortunate enough to get a single room for the night - usually you can get at least 6 new mothers and their babies in a ward room. Even so my wife didn't get that much rest due to my son needing regular feeding and nurses popping in and out constantly to check on mother and child. So I think she was glad to be getting out of there and back home, plus it seemed the hospital kind of wanted the room back; it was never said, just implied since this is the <a href="http://en.wikipedia.org/wiki/National_Health_Service" target="_blank">NHS</a> we're talking about, always under strain. On a side note at least she wouldn't have had to eat the lunch I saw them bring in; the NHS is a great institution but they never have got the hang of meals anyone would willingly eat.</div>
<div>
<br /></div>
<div>
So, new baby in his new car seat and me carrying a metric ton of samples of various baby related paraphernalia, I managed to finally get everyone in the car and get them home. And then the realisation dawned on me and my wife: <i>what the hell do we do now? </i>Because you spend a lot of time thinking about how it will be and reading a lot of books to learn how to look after a baby, but nothing says "trial by fire" more than bringing home your first-born and having to figure out <i>everything</i> you need to do to look after them by pure guesswork.<br />
<br /></div>
<h3>
Breastfeeding</h3>
<div>
Breastfeeding in particular stressed my wife out a lot. You would assume, maybe from seeing people doing it or just the general impression that the idea gives, that it would be an act that both mother and child instinctively know how to do, like they are hard-wired to "just do it". Nothing can be further from the truth. Of course a newborn baby does have a natural suckling instinct, just no way of knowing <i>where</i> to apply it. And it's no easier for the mother - it's very easy to get the baby up to the breast but it's not easy to see whether they are latched on correctly due to the positioning of everything, with no idea how much milk they have drunk, if any. Add to that the pressure of midwives always telling you that "breast is best" and my wife refusing to try any other way, it resulted in a very stressful time.</div>
<div>
<br /></div>
<div>
That first day I don't think my son got much milk down him due to both our inexperience, my wife getting very upset by the end of the day. In the end he did sleep almost through the night - which helped my wife who was still exhausted from childbirth - but we were still worried he wasn't actually getting any milk. Fortunately the midwife who came to visit on the second day explained to us that a) you can <a href="http://www.babycentre.co.uk/baby/breastfeeding/pumpingexpressing/expressingbreastmilk/" target="_blank">express breastmilk</a> and give it to him in a bottle and b) give him formula milk at the same time whilst learning the breastfeeding technique. So we resolved to go out to the supermarket and get some formula milk - our first trip out so it probably did us all good.<br />
<br /></div>
<h3>
Chaos</h3>
<div>
Babies change everything. Suddenly all your little routines that govern your life are thrown out of the window and you are forced to re-learn everything. So apart from having to know how to change nappies, how to feed them, how to burp them, how to dress them and a thousand other little things that you never thought about before, you also have to try and find order within the chaos that a newborn brings into your life. As a programmer, who relishes procedures, order and routines, I found this very hard.</div>
<div>
<br /></div>
<div>
Take, for example, the night feeds - because your job as a parent doesn't end when the sun goes down, no siree! Every 3 hours my son needed feeding - and I mean <i>every</i> 3 hours, morning and night. Before he was born I insisted to myself that I would do my share of everything - nappy changing, cleaning him, the works - and since my wife was starting to express milk it also meant I could help with feeding him. This also meant getting used to a new sleep routine (or lack of it). As a result, we both basically went to bed at around 8pm for nearly 3 months because we were too exhausted to stay up any later!</div>
<div>
<br /></div>
<div>
There was also the night of the third day when he just would not sleep and cried and cried all night. We tried everything we could think off and were getting to our wits end when we realised that letting him suck our finger helped, but take it away and he would start crying again. It got to around midnight, when I was sitting up in bed with him sucking my finger and not being able to get to sleep like this, when I declared to my wife "I'm going to buy some dummies. Now".</div>
<div>
<br /></div>
<div>
Another thing you learn as new parents is to let go of all your pre-conceptions. My wife had many ideas that she thought would be good for our son such as breastfeeding, no dummies ("too unsightful") leading all the way up to baby-led weaning. We reluctantly learned the hard way that a baby doesn't care one bit what <i>you</i> think is best for them, it will do exactly what it likes and there is nothing you can do about it but adapt to them. So I had to drive to the midnight supermarket to get some emergency dummies, which let him at least suck on something while he slept in his crib and gave me my fingers back.<br />
<br /></div>
<h3>
I Don't Like You</h3>
Perhaps the thing I personally and emotionally found hardest to accept in my two weeks off work was the fact that my own son seemed to hate me. Well, perhaps "hate" is too strong a word but he definitely did not like me. No matter how I held him or cuddled him he would just cry and cry at me, only stopping once his mother took hold of him; he was inside my wife for nine months, knew her like the back of his hand, whilst he only met me a few days ago and did not like what he saw.<br />
<br />
This is a very hard thing to take, the fact that your own child does not seem to like you. I had an idea that it would be tough but I also imagined that he would at least just lie in my arms looking all cute and all, but there was none of that. I even looked after him for a whole afternoon on my own while my wife went to get a haircut; I insisted to her that some time alone for her would do her some good. It also meant that I had an entire afternoon of him crying at me, pretty much non-stop. Add on top of that the sleepless nights, trying to keep the house in order (though I soon gave up on that notion) and keeping up a repetitive 3-hour cycle of the same tasks - feed, burp, change nappy, prepare the next feed - I have to admit it almost broke me.<br />
<br />
<h3>
But It Gets Better</h3>
<div>
So far I'm making fatherhood sound like hell on earth, but overall it isn't. What people reading this who don't have children of their own must understand is that the shock of changing your life from free-and-easy to instant parent is incredibly severe. Everyone says that raising children is tough but my words alone cannot convey just <i>how</i> tough it is, the only true way of understanding is to experience it for yourself.</div>
<div>
<br /></div>
<div>
And yes the first two weeks of my son's life were incredibly tough, for me and my wife, I cannot lie about that. But every parent would also tell you that things get easier. At the time, when you haven't slept all night and every minute drags on forever, you can't see the end but it is there. And things did (very slowly) start to get better; towards the end of my paternity leave my son was starting to get a bit more used to me, partly by me realising that he wanted to be moving at all times - that meant rocking him in my arms non-stop, which wore me out physically but at least he wasn't crying! And once you start to see a pattern in his routine - such as when he appears to sleep, when he last had his feed so you can gauge when the next one should be - then you can get into the swing of things.</div>
<div>
<br /></div>
<div>
<b>Next time: <a href="http://inthecodingzone.blogspot.co.uk/2012/08/becoming-father-one-year-on-part-3.html" target="_blank">Getting the hang of it...</a></b></div>
Peter Monkshttp://www.blogger.com/profile/16545944125027320405noreply@blogger.com0