Friday 11 June 2010

Quick and simple Mercurial (Hg) setup

I thought the time had come for me to get to grips with a DVCS having heard so much love for Git and Hg. The first big decision; Hg or Git? And this is a tough one, because everything I've heard about the two indicates that there's only minimal differences. Someone I know at work has been trying Git, so to get a comparative test I thought Mercurial. Besides, I prefer the name Mercurial (heard about it before Git) and I like the references to the periodic table of elements (Hg); it tickes my geek.

Joel Spolsky wrote a great guide that's available at http://hginit.com/. It's great not only because it helps show people the path to DVCS from SVN (or similar VCSs) but because he does it with the right amount of humour. Even if you don't want to adopt Hg or Git, it's a fun read.

But it jumps right in assuming you, or your IT support team, have already installed Mercurial for you. So here's my guide to getting it all installed and configured.

Where to get the goods:

  1. Get the actual Mercurial installation here: http://mercurial.selenic.com/ 5.91MB
  2. Get VisualHG, a Mercurial Source Control Plugin for MS Visual Studio here: http://visualhg.codeplex.com/ 337kb
  3. Get TortoiseHg here: http://tortoisehg.bitbucket.org/ 21.4MB

Total download: 27.6MB

Installation

Since the first download is an MSI there's really not much to is. Run the MSI. I chose not to install the translations. At the time of writing this was Mercurial 1.5.4. Installation was uneventful as expected. It installed to C:\Program&nsbp;Files&nsbp;(x86)\Mercurial. You guessed it, I'm running 64-bit Windows 7 and Mercurial installed 32-bit. Ho hum. The start menu folder contains links to things like help on the configuration file that made me think I was on Unix again and nearly run for the hills. So I ignored that for now. The link to the command reference seemed equally foreboding so I just opened a command line prompt to see what "hg" would do. At last, a simple list of commands. That confirmed I had it installed and from here I could follow Joel's superb tutorial if I wanted.

Much as I love the command line. Really; I do. Maybe because my first experiences with an IBM PC were with DOS, who knows. Nevertheless, I know that I will not check in as frequently as I ought to if I have to drop to the command line rather than perform these tasks from within my IDE of choice. My IDE of choice is of course, Visual Studio. I love it and I HATE it. But there seems no viable alternative at the moment, so I try focus on the love I have for it. Time now for the second install - VisualHG from CodePlex.

Again, this is an MSI, so it's so straight forward it's practically boring. Again 32-bit (installed to C:\Program Files (x86)\VisualHG\ by default). Installation was particularly quick. One of those moments when you wonder whether it installed correctly. Their installation instructions call for installing TortoiseHg, but I don't feel a need for Explorer integration so I'm not installing that - yet. It's as simple as opening Tools-Options and selecting VisualHG from the Source Control Plug-in selection drop down box. I'm again surprised by how simple this is. I am beginning to feel that sense of pending doom: it's easy; too easy...

Now creating a new project under Mercurial control might not be easy - I've not created a repository yet. Let's see...

Created a new ASP MVC 2 web application. An attempt to commit tells me it's not under Mercurial source control. Well duh. Time to refer to Joel's tutorial...

I go to the folder where the files are, just like he tells me to, and I type "hg init" and hit Enter. Nothing. Ah but hang on, Joel said that would happen. Look and see that the ".hg folder is there". Amazed; I pause. Nothing has ever been that fast before, not even Subversion. I savour the moment. If this is a sign of things to come, bring it ON!

First issue occurs after I've done "hg add" and I try "hg commit". It throws this back at me:

abort: no username supplied (see "hg help config")

I'm starting to guess here. It tells me where it'll look for configuration files so I create a new text file in "C:\Users\bhofmann" called "Mercurial.ini" that it should read from. The contents resemble the following:

[ui]
username = Bernhard Hofmann
verbose = True

I try the "hg commit" command again and woot! It opens Notepad with a list of the files (just like in Joel's tutorial). I exit and save, and it whirls through the files. Maybe there's a plugin for AD support or something, because the ability to spoof identities seems too easy. Still, I trust me and I'm the only one using this repository - for now.

Back to Visual Studio to see what's happened there...

It would appear that TortoiseHg is indeed required for VisualHg. I decide to watch Rob Connery's video: http://tekpub.com/codeplex. As good as the video is, my time is limited and it's WAY too slow.

I install the 64-bit TortoiseHg MSI. Once again installation is boringly simple and robust. Kudos to the testers on all these products.

Start Visual Studio and the difference is obvious - suddenly I have icons showing the status of each file. Sadly the pending changes and source control explorer windows are TFS-only tools.

Job done - I can edit, commit, see history and revert files all from within VS2010.

Next steps will be to see how I push up to a central repository, and how I make backups. Or maybe that's just a question of having another repository I push to?

Thursday 13 May 2010

Things to avoid in development

I'm currently very low, probably due to working my but off and not achieving much. I'm a results driven person and seeing few and insignificant results after working like a mule depresses me. So I decided to try note down some of the things that are causing me to be so inefficient so that I can avoid them in future and focus my efforts on reducing or removing them.
  1. Get tests in early. Unit tests, UI tests, Fitnesse, whatever. Do TDD if you are allowed to. Make the tests the requirements. We're currently finding that changes to fix a bug are breaking other related (though far from obviously related) functionality. Tests would tell us early. I've just finished fixing something that was broken a month ago. It took bloody ages to sift the history and find when and where it was introduced.
  2. DO NOT USE UPDATE PANELS - EVER. THEY ARE THE SPAWN OF SATAN. THEY WILL DESTROY YOU AND YOUR WEBSITE. You have been warned.
  3. Avoid making user controls because they MIGHT be reused. Excessive user controls leads to a heap of stinking doo-doo that is a mother of a pain in the arse to debug and manage.
  4. Just because this thing LOOKS almost exactly like that thing does not mean it's the same thing. Sure, copying and pasting the mark-up is ugly duplication, but not nearly as ugly and buggy as a user control that has a state to indicate what to display. Use a template and push your data into it. See http://encosia.com/2010/05/03/a-few-thoughts-on-jquery-templating-with-jquery-tmpl/.
  5. Use jQuery (or another JavaScript framework/toolbox) for AJAX and for as much UI as possible. Use the server only when you have to. For that matter; avoid ASP.NET WebForm controls - they are designed for server side use and are heavier than POSH (Plain Old Html Semantic) controls.
  6. Do not let timescales pressure you into creating features that have no tests. If you have no test, it will eventually be broken and you won't know and you will spend hours finding what broke it and wish the fleas of a thousand camels on the person who did this, only to find it was you. So write the bleeding tests!
  7. If you're using a home-grown, or 3rd party for that matter, data binding or view-controller framework, make sure that you're clear about the sequences and dependencies between different types and user controls. Do not mix binding to the UI with binding from the UI or you will eventually find yourself in a stack overflow situation chasing your own tail. Technically it's when one type being pushed to the UI wants data for another type from the UI, that wants data from another type that wants to first push the original type. You will go insane.
I'm sure there are a host of other things that should be avoided, and I'll add to this list over time, but for now these are the things that contribute most to my inefficiency.

Sunday 9 May 2010

I left Facebook

I left Facebook a few months ago. I thought I was done; my account was deactivated and I assumed they owned whatever I'd put on the site and that was just how it would end. Recently I've learned that it is in fact possible to delete your Facebook account. I thought these recent entries on the web were worth trying to bring to your attention and I sincerely hope you decide to delete your Facebook account as well. We should never allow websites or companies to turn what was once private into public information.

Read the top ten reasons you should quit Facebook: http://www.rocket.ly/home/2010/4/26/top-ten-reasons-you-should-quit-facebook.html

Facebook’s Gone Rogue. It's Time for an Open Alternative. http://www.wired.com/epicenter/2010/05/facebook-rogue/

If you come to your senses and want to delete your Facebook account: http://hnsl.mn/cUY6Ib