Humblecoder

Caution, this blog may be ironically named

Lc.exe Crashing During Build

| Comments

For a while now I’ve had an intermittent problem when building WinForm projects that contain 3rd party library controls, DevExpress in this case, where lc.exe crashes during the build causing it to fail. I’ve never gotten to the bottom of why it does it, but I have got as far as noticing it is a problem with the contents of .licx files. So a simple and quick fix is to empty the contents of the licx files. If you delete them the build will fail, this means they can’t be excluded from version control as build machine builds will fail.

If you go to the root of your solution and run the command below from PowerShell it should clear the contents of all of them, then a quick clean/rebuild from the IDE gets it up and running again.

get-childitem .\ -include *.licx -recurse | foreach ($_) {set-content $_.fullname $null }

Hope that helps someone else :)

Updated DDDNorth Android App

| Comments

This year I was delighted to once again be selected as a speaker for DDDNorth and to celebrate I decided to update the DDDNorth Android App I created last year with some new features!

The App

Along side last years features of the full schedule, the ability to select sessions and see a personalised schedule, I’ve added some new Twitter related related features, these include:

  • #DDDNorth Twitter Search Alongside the schedule and your personalised schedule is a search of twitter for the DDDNorth hashtag so you can keep with what everyone is saying!
  • Halo Tweet When you first launch the app you see one of the last ten tweets from the #DDDNorth hashtag.
  • Auto Schedule Update the app now has the ability to check for schedule updates (handy as DDDNorth still has TBC sessions).

Again nothing fancy and completely unoffical so please redirect all queries/complaints to me and not the excellent DDDNorth team.

You can download it from here.

My Session

My session this year is called “Test All The Things Or Maybe Not” and I want to talk through my experiences of unit testing. From complete beginner who took the advice literally to where I am today. Where is that? With hard won battle scars from poor, difficult to maintain and flaky unit tests.

I’m not trying to be an expert, but I hope people starting out will avoid making the same mistakes I did and others will realise it’s OK to break the rules :)

Moving to Octopress From Wordpress

| Comments

Yes, this is yet another another I’ve moved from Wordpress to Octopress post. I made the move because I want to get MySQL off the box that hosts my blog and Octopress is pretty awesome.

When choosing a new way to host it I looked at Heroku and GitHub pages but neither (at the time of writing) offered redirects without hitting Ruby middleware and I wanted to keep my old links working. So I choose to host it myself and serve it up using Nginx.

I found a number of posts on how to make the move but none covered how to deal with links or comments. So I thought I’d document the steps I took and hope it help others.

1) Goto the Octopress site and follow the directions to get up and running.

2) Setup Disqus for your current Wordpress blog and import all the comments (this can take a while).

3) Export all your posts from the Wordpress admin area and then run exitwp to convert all your posts to markdown. It might choke at this point on the XML so it’s just a case of fixing the errors and trying again

4) Run through all your posts and fix them, the Wordpress editor and Windows Live Writer produce some interesting output that doesn’t convert to well.

5) Run wp2oct-links with the exported XML to generate nginx rewrite rules for all your old urls and add them to the nginx conf.

6) Test, deploy, etc then when you’re happy change the DNS over.

7) Go back to Disqus and get it to spider your site and it should update all the links.

That should do it.

Have fun cursing at Markdown :)

Hosting Nancy on Debian With Nginx

| Comments

Over the Christmas break I found myself with a bit of free time to play with Nancy. For a long time I’ve fancied writing a link shortener, I even bought the domain vfy.be to serve shortened links from. I originally had grand plans, it was going to be a social link shortener where links “trusted”/visited by your friends took you straight to them, otherwise you hit a landing page with the amount of hits, the real url and what Google thinks about it or I was going to iframe the page in with a toolbar. Anyway, twitter got in the link shortening business and I got another idea and decided to move on. But still how they worked intrigued me.

So I wrote one for fun using C#, mono 2.10 and Nancy. When looking at the Nancy docs, it is slightly lacking in how to host on Linux so I thought I’d do my bit by writing a quick overview.

Options

There is a couple of options when hosting on Linux, one is to create your Nancy project as a mono ASP.NET project then serve it using xsp (the mono ASP.NET server) and proxying to it or using FastCGI. This is fairly well documented at the mono site and writing a Nancy app using ASP.NET for hosting is also well documented. However, I wanted to take a different approach to try and host it in the minimum amount of RAM on an LEB (LowEndBox), because I have a 256MB Xen Debian VPS just sat around doing nothing.

So to minimise RAM I went for self hosting, using pretty much the stock sample with a slight mod (see below). When self hosting the Nancy app will listen on the loopback address at a specified port so we are going to use Nginx to serve static content and forward all requests to our mono process and use Supervisord to monitor the process.

Pull it all together

For this you’ll need the following installed on the Linux machine:

  • Mono 2.10
  • Supervisord
  • Nginx

The first we’re going to do is configure Supervisord. Supervisord is a process monitoring application that can run any normal process as a daemon and automatically restart it if it crashes. I first came across this when working with Python sites to keep FastCGI processes running. The configuration should look something like:

The important bits are:

  • command – this specifies the command believe it or not,
  • user – by default supervisord runs all processes as root, this is bad for webapps.
  • directory – this sets the working directory, so if you’re app needs anything off disc this needs to be correct.

As I said above I needed to make a tweak to the sample self hosting project. The sample uses Console.ReadLine() to stop the process from exiting, but under Mono when running as a daemon this returns EOF and causes the application to close. So I updated it to sleep (shamelessly stolen from xsp source ):

Moving on we need to configure Nginx. The strength of Nginx is serving up static content quickly so we’re going to intercept all requests for static files and then forward the rest to our Nancy app. The configuration below defines an ‘upstream’ which is typically used for load balancing we can use it here for just forwarding requests. Also note we are intercepting and serving requests for /Content using Nginx. At debug time the default conventions in Nancy will serve this up correctly so we get best of both worlds

How well does it do on our LEB?

Impressively, idle the combination of Debian Sid, Supervisord, Nginx and the Mono process takes up just 37MB of RAM, but the most important question is can it handle load? Beware completely unscientific results below

Lets take a look at hitting one of the json API methods* using ApacheBench (that is bundled with OSX ):

  • 1000 continuos requests with a max of 10 concurrent connections peaks memory at 53MB
  • 1000 continuos requests with a max of 25 concurrent connections peaks memory at 54MB but 18 out of the 1000 failed with connection reset by peer, which is more the box failing than the app
  • 1000 continuos requests with a max of 50 concurrent connections peaks memory at 55MB but my own boardband gave up after 700 connection, clearly not enough upspeed

It’s important to note that this app is one static html page with ajax queries back to a JSON api served by Nancy

Wrapping Up

I hope someone finds my configuration snippets useful and it is worth noting that my LEB (£2.20 a month for 256MB Xen) failed before the my app did, so I find this very encouraging for it’s performance under Mono and Linux.

Source for the link shortener and conf files can be found at https://github.com/Dotnetwill/vfy.be The shortener running on Mono http://vfy.be

TFS From the Trenches

| Comments

It seems I whenever I see TFS mentioned on twitter/HN/Reddit it is usually closely followed by mocking or derisive comments. But all these comments lack any real explanation or reasoning, outside of generally hating on MS, from the author. So as someone who works with, and has worked with for the past 3 or so years, TFS on a daily basis I’d like to add on my two cents on how TFS works and what my pain points are.

Bear in mind I’m not an VCS geek, I’m not going to start talking about how the extensionalist index metabear does not quite model that of the intrinsically 4D nature of time and application architecture. This is just how I get on with it while trying to get shit done.

I’m only going to cover the two parts we use, source control and build management.

TL;DR; It has lots promise but sadly missing features and poorly thought functionality severely hamper it.

Editing Files

Let’s cut the crap, working on a file and checking it in is the same in virtually every VCS. And TFS is not exception here, you work away, see your changes, check them in and if there is a conflict you get a diff. Not rocket science and works well enough.

However, this does quickly breakdown if you want edit files outside of Visual Studio (VS). The problem is files need to be “checked out” before you can make edits. If it didn’t happen while it was checked out it, it didn’t happen. I’ve lost count of the number of times I’ve tweaked an XML file, build file, none cs file and done it in Programmers Notepad only to check in and break the CI build because the tweaks have been missed.

Editing and merging csproj or sln files is a complete and utter nightmare and I’ve never understood why.  Let’s face it if you’re using TFS you’re fairly invested in the MS ecosystem so you’re using VS and one of TFS’s big features is integration into VS so why oh why, for the love of God why, can’t TFS parse and merge sln and csproj files? They are MS formats, produced by an MS tool and managed in an MS tool W. T. F.

Merging And Branching

Personally I’ve been completely spoilt by local branching in DVCS (Distributed Version Control System) and I sometimes get lost in what branching means in a more centralised context. In TFS and svn branching can only be done on the server allowing multiple people to work on the same branch. Whereas with DVCS and local branching only you can make edits and commits then when you’re ready to integrate your work with your team you pull the upstream, merge it and push it. So it’s in your best interest to keep the two as close as possible to minimise your own pain.

The more centralised models put the onus on nobody to sync the branch with upstream because somebody, IE not you, will have to do the merge. Many teams will try to manage this through policy to varying degrees of success and lets not forget that it is entirely possible to get into the same mess with DVCS.

For me the secret sauce of branching with DVCS is that it moves the emphasis of the responsibility and management of the branch on to the individual developer. No amount of nifty features or tooling can make up for the fact that a branch that hasn’t been synced with its parent for 3 weeks and has lots of code churn is going to be a nightmare to merge.

So I don’t think it’s fair to pick on TFS over branching, yes it doesn’t support local branching but at the same time that has the same issues of good branching requiring proactive syncing, thought about management and discipline.

One area where TFS has massively improved recently is in history across branch. Pre-2010 there was no easy way to follow the history of an item cross branch but thankfully this has now been added.

Checking Out, Moving Files and IDE integration

For those that don’t know when you do a pull in TFS every file is readonly by default if you want to edit a file you have to go source control explorer, find it and check it out.  If you have VS integration turned on (and if you don’t you’re a mentalist) it is all quickly taken care of for you when working inside of VS.  There is, of course, an option to make files readable on pull but that only introduces a whole new, more annoying, problem, working out what has actually changed.  There is no “Hey TFS, I’ve change some things figure out what’s different and list them as pending changes for this checkin”, I’ll run that by you again if you don’t check it out TFS doesn’t know what has changed.  This is complete lunacy and is a significant barrier when trying to get shit done.  To be fair, it does have this functionality when your connect goes offline and when coming back online it will look for changes and generally find them.  But there is no way to do this from the IDE normally.

Checking out files is a completely moronic concept.
I said earlier that if it wasn’t checked out it didn’t happen, let me amend that to if didn’t happen inside source control explorer with the correct verb then it didn’t happen.  This is most frustrating with file moves, recently I restructured one of our main solutions splitting several new projects from one monster. I created the new projects then cut and paste the required files via Solution Explorer with TFS integration enabled, expecting TFS to pick up the moves but it did delete/adds and completely f’ed up the merges for everyone else and the history.

For me all this TFS having to be explicitly told what you’re doing shouldn’t be a problem when working in VS, this should be it’s killer feature.  It should be don’t worry just work as normal, TFS is watching and will know what to do but nothing could be further from the truth.

Oh and on moving, you can’t multi select files to move them in source control explorer you either do the whole folder or the files one by one :-/ (I think it’s because “moves” are actually “renames” so it needs to know the filename but WTF)

Shelvesets

Shelvesets on the surface seem a pretty nice feature, it allows you save a copy of your current changes without checking them in.  They get stored centrally so can move between machines and even users, handy if you want a code review or you want to quickly spike something out then share it without checking it in or branching.

Over time I have found the omission of features deeply frustrating. Shelvesets themselves do not have any history, I find this fustrating because the first time I seen them I thought great, I can make changes and have lots and lots of small checkpoints before checking in the finished bits and it doesn’t matter if they don’t build or cause tests to fail.  But nope, shelvesets overwrite each other if they have the same name.

The other use case is using them as a stash, so you’re working away on a feature or a bug and you discover you’re working on the wrong branch or something else high priority comes in so you shelve your current changes. Later you go to unshelve them on another branch so you can finish up, nope can’t do that shelves can’t move cross branch for reasons known only to MS.

Again another should be a killer feature but so widely misses the mark.

Builds

I work for an MS shop so we use MSBuild for builds and TFS build is all MSBuild based so it integrates nicely.  It can schedule builds, run the CI, the build machine setup is a little clunky but it makes sense.  Overall running and managing builds it does a good job.  The only major frustration is notifications.

Not only is it really difficult to set up a notification, the UI is horrendous and none obvious, but if someone has setup a notification on your behalf then you can’t delete it, see it or see who created it.  So if you want to piss someone off you can setup for them to be notified on every build that is done ever and there is nothing they can do about it.  Yes, you can go to the TFS database and remove them but that’s a bit extreme and not many developers have that kind of access.

Overall

TFS has so much promise but the combination of idiotic concepts, poor integration and lacklustre features really harms productive.  A sign of a good tool should be one that doesn’t get in the way and in this respect TFS fails massively.  I would even go as far to say it actively promotes bad VCS habits from individual developers.

DDD North Sessions Android App

| Comments

I was massively honoured to have my session on Android development voted into DDD North and I’ve spent the last couple of weeks thinking about and planing my content to do the honour justice.  While doing this I’ve created a small application that lists all the available sessions at DDD North and lets you keep track of what you’re planning to attend.  Partly to help recentre my Android zen and partly to give something back.  So here it is:

Features:

  • Full session list stored locally, so it will work when you have no wifi or signal
  • Includes the title, full description, room, time and presenter of every session
  • The welcome screen gives you a heads up of your next session
  • A “My Schedule” view, once you’ve selected the sessions you want to attend you can see them all at a glance.

It’s nothing ground breaking, or pretty :), but I hope you find it useful. You can download it from:

Market Link

And the source is up at https://github.com/Dotnetwill/DDDNorth-Schedule- Android so if you want to add features you’re more than welcome just send me a pull request!

Disclaimer Although I use the official DDDNorth logo and colours this is 100% unoffical so please direct all complaints and issues to me, not the wonder DDDNorth team :)

My Session

My session is an introduction to Android development from my .Net perspective, I’m going to go over the basics you need to get an internet facing application up and running using Java and the Android SDK.  I’ll cover, roughly, Activities, basic XML layout, AsyncTask, Intents, permissions, list adapters and, of course you can’t miss, context.  Along the way I’ll share with you bits of Java that have caught me out or are relevent to help get these things done.

If you’ve written an Android application I doubt there is going to be much there for you.  If you’re an experience Java developer I’ll probably just make you angry as I butcher the language.  But if you’ve got experience with .NET and would like to learn about Android native dev and bare in mind that this isn’t best practice or even particular wonderful code then please come and long and enjoy it.

Hope to see you there!

Update: DirLinker 2.1.1.0

| Comments

This morning I have pushed a new version of DirLinker to Codeplex.  The only change, a response to a bug raised on codeplex, is to allow the entry of network paths in DirLinker’s UI because it possible to create symbolic links to network locations on Vista (or later) but the strict validation used would not allow it.  There is a couple of things to be aware of when creating them:

  • It only works on Vista or later
  • It can be used for file and folder links
  • You can not create a link on a network location back to your local machine
  • If a sym link created on Vista/Server 2008 (or later) is in a shared folder, XP machines will not be able to use it.  As they don’t support sym links, only junction points.

As usual don’t hesitate to raise any bugs or give any feedback Smile

What Makes a Good Code Review?

| Comments

I love code reviews, I really do.  I like having my code looked at and receiving feedback and I like to look at other peoples to see differing styles, techniques and library functions I might not be aware of.  But I always struggle to find the best way to do code reviews.  So I want to take a look what you need to perform a code review and how to review the code.

Prerequisites

Some people are just really bad at writing bug reports and work items (I’m looking at you developers) but this is the most important thing you need when reviewing the code, apart from the code.  You need to able to read the original bug report and understand it then see the developers analysis and proposed solution so you know what you’re looking at when you review it. Without this it becomes extremely difficult and time consuming to redo all the work that has already been done to identify the problem.

Leave your style at the door, at the office we don’t have one complete standard, we have general rules about casing, and what not, but there isn’t one enforced style. I find it really helps to tune out to subtle differences in style, so long as it’s readable it really doesn’t matter.

The Review

I like to start with some simple things:

  • Run it - Check that the bug has been fixed or the work item has been implemented.  Take it through some basic sanity checks with the debugger attached, if possible, with stop on EVERYTHING enabled and see what it does.  No point in reviewing code that doesn’t do what it’s meant to do.  If it has unit tests run them, step through a few with the debugger to get a feel for how it’s meant to work.
  • Check for build warnings - Ok that might sound petty, but I generally think warning should be treated as errors.
  • Is it readable – This is the most important, if you can’t read it how do you expect it to be maintained?  Or you don’t understand the change enough to give it a good review. By this point we have checked that the code is working and that we understand it. Now for the hard part, looking at it.  At the business end of a code review I generally look for the following things (C# specific):

  • Delegate Registration – Whenever I see a delegate being registered I always look for a corresponding deregistration.

  • Resources Being Release – If a resource (file, db, etc) is opened, make sure it is released again at some point.
  • General Exception Handling – I always look for things I know, from experience, are likely to throw and see if there is exception handling around it.  Whenever there is a catch block, I look at how it is dealt with and what is caught.
  • TryParse v Parse – Parsing values is always error prone, and we do a lot of it in our codebase, so I’m a stickler for correct exception handling or using the TryParse methods.
  • Null Checking (or Use of a Null Pattern) – Defensive coding should be our bread and butter so this should always be present
  • General WTF-ery – Anything that makes me utter those three little letters. I think this covers most points, it’s not an exhaustive list but I think code reviews are more about checking maintainability than quality, although it definitely helps with it.

When giving feedback I like to try and speak to the person first and ask them about it, remember one person’s WTF is another person’s complex issue. Alternatively, I jot a few points down in an email.  I don’t see the need for a separate code review tool when other forms of communication are effective and flexible.  Finally, always be constructive, it’s hard to get people to listen if your just being negative so state your reasons clearly, ask them why it’s like that and always resist the urge to say “W.T.F is going on here dude”.

I started off this blog post with a view to clarifying in my own mind how best to do code reviews, but looking back and rereading my approach I feel there is room for improvement.  So I ask you my dear readers:  What do you think makes a good code review?

My Gateway Drug to Professionalism

| Comments

“Have you considered working in another area in software, you don’t seem to have the right personality type to be a developer”…Said the head of development sat across the table from me.  I sat, head down, a mere 18 months out of university having just delivered my first major product release being told that I was no good at what I do.  I love programming, it has been my hobby since I got my first computer and it was the only job I’d ever wanted to do.

As I’m sure you can imagine, I was devastated but not entirely shocked.  You see I used to rush through a task or bug to get to the next one or get distracted by something shiny.  The best way I can describe it, is as a Magpie effect and, as I was being made aware of at that moment in time, developers are expected to be completer finishers and meticulous to a fault.

I was aware of TDD and I had tried to write some tests but I really struggled with how to make code testable and good unit tests that didn’t just test “stuff”.  But this time I was determined to learn more and put it in to practice, it seemed like the perfect answer.

Present Day…

That was nearly two years ago now, I’ve grown massively as a developer since that day and TDD has been my gateway drug to professionalism. When I started off with TDD I thought it was about testing but when I look back at my journey thus far, it’s about anything but.

One of my biggest problems was rushing, I was always desperate to finish and I missed things or didn’t think them through properly.  The first thing that writing unit tests helped me to do was slow down and break problems into much smaller chunks.  Just taking a few minutes to consider how best to write the test normally exposes any concerns that need to be separated, edge cases and how the class or function will be interacted with.  If I’m ever struggling to make a test pass, write a test or if I can’t make all the tests pass, it normally means I need to go back and look at the tests to see if I’m trying to solve too much in one go or if it has contradictory responsibilities.

The tests provide excellent documentation that is hard to argue with and stays in step with the code.  This is key because it gives me an insight in to what I was thinking and how I intended on it being consumed.  It’s, also, the closest to an interactive interrupter for C# I have used, which is great for rapidly checking assumptions and questioning your own code.

Overall it has taught me so much about architecture, design, good practice and maintainability of code.  One conclusion I have to come is that unit testing has a very low regression value.  At this moment in time I rarely, if ever, find bugs using unit tests.  Yes they help to identify failure points but it’s not very often I find regressions using them.  All they have done is shifted the pain point from if the logic works to if it all works together.  My next challenge is step deeper into the world of the integration testing.

Stop TFS From Telling You “Windows Live Messenger Is Not Running”

| Comments

I’ve recently stopped using Live Messenger (moved to Pidgin) and one unexpected side effect of switching was TFS reminding me every time I went to Team Explorer that Messenger isn’t running with this lovely error message:

image

For the past few weeks I’ve been living with it, but it’s becoming increasingly annoying.  So today I finally worked out how to stop it:

  1. Go to the Team Members item in Team Explorer and right click on it
  2. Select _Personal Settings _
  3. On the dialog there is a Collaboration setting, change the provider to None
  4. Be free of annoying dialog.

Hope this helps some else regain their sanity Smile