Microsoft DDC 2013 Reflections

A few weeks ago, I attended and spoke at this years Danish Developer Conference by Microsoft. The conference was run in both Horsens and Copenhagen and both venues were cinemas. I gave a talk with Mads Kristensen with the topic of Visual Studio productivity tips. Mads covered plain Visual Studio and I gave a whirlwind tour of what productivity with ReSharper could look like.

The venue

I loved both venues, MegaScope in Horsens and Cinemaxx in Copenhagen, presenting in a cinema is just amazing. Forget everything about presentation resolutions and just fire away – Cinemaxx’s projectors were 4K (4096 x 2304px). Having 60+ m2 of screen estate makes everything much simpler. Combined with comfortable seats it was really enjoyable. We had an entire cinema as a Speakers Lounge as well.

My talk

As previously mentioned, I gave my ReSharper whirlwind tour. The talk has very few slides and focuses on giving a quick overview of the most basic features in ReSharper. If you are looking specifically for my ReSharper slides, I have some old presentation blog posts containing a richer set.

I think it will be the last time that I am going to give my basic ReSharper talk, unless specifically requested – since I have given it quite a few times now. I might be tempted to create a more advanced ReSharper talk at some point though. Maybe I will actually speak about some C# related stuff next time.

Other talks

I was generally happy with all the talks I saw, but I want to recommend 2 talks specifically, if you happen to get a chance to see them at a user group or at another conference:

Advanced Unit Testing (Danish: Unit testing for viderekommende)

Mark Seemann is a very experienced speaker and a passionate proponent of automated tests. This talk gives an introduction to some of the patterns to avoid brittle tests, especially in regards to test object construction and equality. In many regards it reflects some of the painful experiences I have gone through over the years.

Bigger, Faster, Stronger: Optimizing ASP.NET 4 and 4.5 Applications

Mads Kristensen has given this talk so many times but it is better every time and it touches on so many helpful things to optimize your web pipeline from the server to the client. The talk is based around the Web Developer Checklist – so if you can’t see the talk live, at least take a look at the checklist.

Surviving no media keys on your new keyboard

I’ve recently acquired a new keyboard, after using my trusty old Logitech for many years. I’ve come to rely on my media keys and the volume wheel for controlling Spotify or other apps.

My solution is to use AutoHotKey to bind the following combinations after a short conversation with Mark (although we don’t entirely agree on the layout):

• Win + Numpad 4 – Previous track
• Win + Numpad 5 – Play / pause
• Win + Numpad 6 – Next track
• Win + Numpad 8 – Volume up
• Win + Numpad 2 – Volume down
• Win + Numpad 7 – Mute

Here’s the script to add to AHK:

#Numpad4::Send {Media_Prev}
#Numpad8::Send {Volume_Up}

… and on a final semi-unrelated note, I’ll recommend my new mechanical keyboard – Das Keyboard S Ultimate Silent. It’s far from silent – but it’s an awesome keyboard. The keys have a very nice feel as you’re typing along and the keyboard itself is rather heavy (almost 2kg) and thus stay completely in place when typing.

Setting up Web Deploy 3.0 / MSDeploy

I’m currently on the path of converting one of my sites from SFTP deployments to using Web Deploy 3.0 and thought it might be interesting to document the process and the pitfalls that I run into. My approach is roughly based on this guide, but it wasn’t a complete fit for me, so here we go.

Motivation

So why would you want to use Web Deploy for deploying web sites? Compared to regular file copy or FTP deployments, Web Deploy offers the option of running a dedicated deployment service on your server, that is actually aware of IIS and can help you make your deployments as smooth as possible. In my case, my SFTP service had started to lock random assemblies recently, and since I’d been wanting upgrade to Web Deploy anyway, I thought now might be as good a time as any.

Web Deploy can do a bunch of things for you, such as syncing IIS sites (6, 7 and 8), deploying packages, archiving sites by offering a multitude of different providers. This post is dedicated to deploying a rather simple site that is already bin deployable.

My setup

My setup is a remote server running Windows Server 2008 R2 with IIS 7.5 and a development environment on a Windows 7 Ultimate machine.

The site is an ASP.NET 4.0 mixed WebForms / MVC project. The application itself manages database migrations, so they’re not in scope for the post either.

Setup steps

1 – Created a dedicated deployment user for use with deployment. It’s nice to know that everything is locked down, when you open up remote access.

2 – Installed Management Service role for my IIS in Server Manager.

3 – Changed Web Management Service to Start automatically (delayed) and specified a specific deployment user.

4 – Configured Management Service within IIS.

Like this:

5 – Created a new site in IIS. Gave the deployment user access to the site folder on the web server.

6 – Gave the deployment user access to the site through IIS Manager Permissions.

7 – Installed Web Deploy 3.0 including IIS Deployment Handler (wasn’t visible in the first custom install). Not using Platform installer. The IIS Deployment handler install option was not visible the first time I tried, because I hadn’t installed the Management Service in IIS.

8 – The guide told me to add rules, but rules already existed in Management Service Delegation.

9 – Installed IIS on my local machine. Was rather freshly paved, so I hadn’t yet. I’m guessing most of you can skip this step.

10 – Wasn’t able to ‘Connect to Site’ as mentioned in test guide – so I installed IIS Manager for Remote Administration v1.1 using Web Platform Installer.

11 – Connected to the Site.

12 – Selected the site.

13 – … aaaaand imported my application package that I’d created through Visual Studio.

14 – Profit!

Conclusion

Now this is a rather crude picture guide. But hopefully it’ll still be useful to some people. I know I’ll check it next time I’m setting up Web Deploy.

My next goals are to adapt my rake scripts for the application to create the package on my TeamCity server and add one-click deployments directly from TeamCity.

GOTOing this year!

I’m happy to announce that I will be going to GOTO 2012 Aarhus in October. Trifork invited me as a blogger, and as such I will be writing blog posts before, under and after the conference. Even though the invitation includes a free ticket, you can rest assured that my future posts about GOTO will contain only my opinion expressed in my words.

The agenda for the conference has been posted and while there’s no dedicated .NET track, the speaker list does include Anders Hejlsberg and Scott Hanselman. I’m also looking forward to seeing Dan North speak again, I was really sold on his talks last year at Öredev. Track-wise I’m definitely going to attend talks in Continuous Delivery, JavaScript, Languages, Hard things made easy and It’s about the people, stupid.

I would have loved a bit more functional programming in the conference program, especially with my new found interest in Clojure. But I guess you can’t have it all.

I’m still considering my approach to blogging about the conference. My main style on this blog is usually informational and rather technical, but I wouldn’t mind dipping into some of the more people / project centric problems / discussions of our industry. One of the benefits of being a independent consultant is that you see so many different places – so I have developed quite a bit of “You’re doing it wrong!” opinions over the years.

Hope to see you at the conference!

MOW2012: Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees

I gave my Exploring C# DSLs: LINQ, Fluent Interfaces and Expression Trees talk today at Miracle Open World 2012 about C# Domain Specific Languages.

The slides are now available here.

… and the demo source is available as a git repository on bitbucket here.

Note that some of the source is just mocked implementation, the goal was not really to show production level quality – but rather concepts. The quality of the few tests and commit messages reflect this.

Converting a Mercurial repository to Git (Windows)

After going through the pain of (re-)discovering how to convert a Mercurial repository into a Git repository on Windows, I thought I’d share how easy it really is. I’ve bounced back and forth between Mercurial and Git a few times – my current preference is Git, mainly because I like Git’s branching strategy a bit better – but really, they’re both excellent choices. I still find the best analogy for comparing them is that Git is MacGyver and Mercurial is James Bond.

You can find quite a few posts describing how to convert – but many of the steps mentioned in those guides are not needed if you have TortoiseHg installed, which most Windows Mercurial users do.

Prerequisites

As I already mentioned, this guide expects that you have TortoiseHg installed on your system.

For the actual conversion, we’re going to be using a Mercurial extension called hggit that enables Mercurial to push and pull from Git repositories. You can either clone the hggit repository on GitHub or grab a zipped version here.

What we need is the hggit folder from the clone or zip file – put this some place handy and remember the path.

Preparing the Git repository

In this guide we’re going to be pushing our repository to a local Git repository – so let’s create a bare repository – this way you’ll avoid Git complains about pushing to a non-bare repository.

Open a command prompt, create a directory for the new repository and from within the directory execute: git init –bare

That’s it – our Git repository is ready. Alternatively you could push directly to a Git repository on either GitHub, Bitbucket or other provider.

Enabling hggit in Mercurial

Now we need to let Mercurial know about the hggit extension. This is done by adding it to the .hgrc or mercurial.ini file in your home directory (for me that’d be c:\users\rasmuskl\mercurial.ini).

In the config file, find the [extensions] section – or add it at bottom if it’s not already there. Then add a reference to the hggit extension followed by the path of the hggit folder:

hggit = c:\path\to\hggit

Converting the repository

To convert the repository, simply open your command prompt, navigate to your Mercurial repository and do: hg push c:\path\to\bare\git\repository

And you’re done. You can now either clone the bare repository to a working directory – or push it to your GitHub or Bitbucket account.

Tips for decluttering Visual Studio 2010

Mogens Heller Grabe wrote a nice post about reducing the amount of clutter in your Visual Studio the other day – and I thought I’d chime in with a few tips.

First up we have the navigation bar – which is taking up a line of your precious screen estate.

Tools –> Options –> Text Editor –> All Languages

Uncheck ‘Navigation bar’. For extra bonus points, check ‘Line numbers’.

Bringing back the Configuration Manager

The following tip I got from Rasmus Wulff Jensen when I mentioned that the only thing I really like from the standard Visual Studio toolbars is the ‘Configuration Manager’ drop down that allows me to switch between Debug and Release builds. He showed me a neat trick to put it in the top toolbar.

Right click on the tool bar to bring up the tool bar selection.

Choose ‘Customize’. Change the tab to ‘Commands’ and move focus to the bottom of the list, like so:

The hit the ‘Add Command’ button and go to the ‘Build’ category. Scrolling to the bottom, you will find a command labeled ‘Solution Configurations’. Pick it.

You now have an inline configuration manager on your top toolbar without taking up extra space. Same trick can be applied to any other commands.

Docking the Find dialog box

The ‘Find and Replace’ dialog is probably one of the most used dialogs in Visual Studio – however with the default settings, you get a floating dialog that doesn’t seem to want to go away after you’re done using it.

If you dock it – like so:

… and unpin it, it will behave nicely and disappear when you’re done searching or press ESC.

Switch to a dark theme

This is more a matter of taste. Personally I’ve been using dark themes for Visual Studio forever. My eyes feel way more relaxed after a day of using a dark theme. My theory is that since computer monitors use additive colors (with white being a full blast mix of red, green and blue and black being no light), a dark theme simply emits way less light.

If you want, you can download my personal theme here (ReSharper specific). It’s the same as I’ve previously posted, except I’ve adjusted it to work properly with Razor views too.

Peer Reviews – Why bother?

Working with code is tricky business – the larger and more complex the code base, the more tricky. Ingraining micro-processes into your work day can help fix some of the issues, some of the broken windows that grow into almost any code base over time. Peer reviews is a great starting point.

There are many forms of peer review – but this post is mainly about informal check-in reviews. The process is simple: Any commit to the code repository must be signed off by another member of the team. Many argue that small commits are okay to go unchecked – but the size of a “small commit” grows in my experience. My counterargument is that a small commit will only take 30 seconds or less. Simply bring up the change set, go over the changes, discuss anything needed informally, then add “Review: <initials>” to the commit message and fire away.

Benefits?

One of the first things you’ll notice when you introduce peer reviews is catching common commit mistakes. These include small changes in files made while testing or debugging that were not meant to be committed, files that were not related to the current commit and, if your reviewer is alert, files missing from the commit.

Another small side effect is a subconscious increase in code quality. Knowing that someone else will review your code closely will increase the mental barrier to introducing hacks and other peculiarities that sometimes sneak into code.

While many developers focus more on writing self-documenting, readable code, getting another pair of eyes on the code is great for clarifying the intent of the code – uncovering small scale refactorings such as renames and extractions. The earlier you uncover and discuss minor design issues like these and further aligning team coding styles, the better shape the code base is likely to end up. Aligning coding styles across multiple teams is a hard task, any improvement is worth taking. Once in a while a peer review will uncover larger design issues and ultimately lead to discarding the code under review and going for a different solution. This is not always a pleasant experience, but it’s easier to kill your darlings when nudged in the right direction by a colleague.

In line with the last paragraph, reviews also often spur discussions about larger things like domain concepts and architecture – it just seems to come up more when looking at concrete issues in the code base. Likewise, the reviewer is investing some of this time in the code and putting his name on it, thus increasing shared code ownership of the code.

Lastly, just seeing how other developers work can give insight in other developers IDE and tool tricks. Being a keyboard-junkie myself, I often find myself exchanging IDE / productivity tips during reviews.

Conclusion

Information code reviews are, in my opinion, one of the cheaper ways to directly affect code quality – assuming it’s taken seriously of course. You might notice that many of these benefits are the same as with pair programming – and they are. Pair programming is usually harder to get started on and not suited for all assignments, although most teams ought to do way more pair programming than they are. Peer review is broadly applicable. Try it with your team for a week or a month – if I’m wrong and nothing improves, I’ll buy you a beer next time we meet

Check your backups – unexpected SQL Server VSS backup

Your backup is only as good as your last restore. I recently changed my backup strategy on my SQL Server 2008 from doing a full nightly backup to doing incremental nightly backups and only a full backup each week. SQL Server incremental backups base themselves on the last full backup. This is nice when you go to restore them since you will only need the full backup + the incremental backup, not any intermediary backups.

However, a few days back I wanted to check some queries on a larger dataset and decided to check my backups at the same time. Fetched full + incremental backups from the server and started the local restore:

RESTORE DATABASE [testdb]
FROM DISK = N'C:\temp\full.wbak'
WITH FILE = 1, NORECOVERY, REPLACE

RESTORE DATABASE [testdb]
FROM DISK = N'C:\temp\incremental.bak'
WITH FILE = 1, RECOVERY

The first backup went through fine, but restoring the incremental backup resulted in the following error message:

This differential backup cannot be restored because the database has not been restored to the correct earlier state.

SQL Server refused to restore my incremental database – this is only supposed to happen if there has been another full backup in between. I double checked the backups I had fetched, checked that I had the set up the new backups correctly and that the old backup job was gone. Everything seemed fine.

I then explored the backup history a bit further with a query adjusted from the one found in this post:

SELECT TOP 10
s.database_name,
m.physical_device_name,
s.backup_start_date
FROM msdb.dbo.backupset s
INNER JOIN msdb.dbo.backupmediafamily m ON s.media_set_id = m.media_set_id
WHERE s.database_name = DB_NAME() -- Remove this line for all the database
ORDER BY backup_start_date DESC

The result showed that there had indeed been backups in between my nightly runs:

{% img /post-images/image_thumb_1.png %}

Further research revealed that backup devices with a GUID name are virtual backup devices and the times of backups matched the daily schedule of our bare metal system backup. Turns out that R1Soft’s backup software integrates with SQL Server’s VSS writer service to perform backups when it finds databases on disk.

Disabling the VSS writer service returned the backups to a working state (VSS backup + my own incremental would also have worked). I did consider skipping my own nightly backups (since the VSS backup is super fast) and just using the R1Soft one, but decided against it for now – my own management is already set up and if I do need to restore, grabbing the backup from the external backup is much slower and more tedious than having it on disk already.