Sublime is Sublime 9

Yesterday I took a survey of .net developers as I was curious how most are working. In particular I was wondering what % of time people actually work on .NET code vs working on code such as html or javascript and in particular whether they were using VS for html and javascript development.

I would love to put all of the raw data here but apparently surveymonkey wants 25/euros per month to actually export the results of a survey which sucks. Need to find a new survey tool.

What I found was a few groups of .NET developers one that was quite interesting for me answered the questions in this way:

Q1: What % of your time are you actively coding at work?
Q2: What % of your coding time is in .NET code (C#/F#/VB.NET/etc)
Q3: What % of your coding time is in HTML?
Q4: What % of your coding time is in JavaScript?
Q5: Do you use Visual Studio for javascript/html?

There were a huge number of developers who spent 40-70% of their coding time in Visual Studio not working on C# code but instead working on javascript and html code. For these developers in particular I point you to the html and javascript support in sublime without comment just watch a few videos, getting setup is just installing a few packages through your package manager (discussed previously in this series)



WebInspector – seriously watch the video
Emmet – formerly known as zencoding.
Code Intel – go to definition etc support

Tomorrow we will continue the series getting into .net specific stuff and fixing some areas we are weak in now. How do you add a reference?

Anyone used any of these plugins? Please share your experiences in comments.

Sublime is Sublime 8

In this post we will look at how to become a bit more efficient in our sublime setup without adding lots of new tools or complexity. In particular I don’t like running my builds and my tests manually (and we will look at some varying options for this later). In this post however we will look at a dead simple method for doing it.

Let’s take a look at the full script I briefly wrote that does all of this.

notify-send "Auto Started" "" -i $PWD/images/circleWIN.png -t 1000
while true
      if [ ! -z $(inotifywait --recursive -qre modify --format "%w%f" ./ | grep -v -f includes) ]
	  sleep .25
          /opt/mono/bin/xbuild src/EventStore/EventStore.sln /p:Configuration=Release /verbosity:0 /nologo
          if [ $? -eq 0 ]
               ./ -m /opt/mono -x LongRunning 
                if [ $? -eq 0 ]
                      notify-send "Passed" "Tests Passed" -i $PWD/images/circleWIN.png -t 1000
                      notify-send "Failed" "Tests Failed" -i $PWD/images/circleFAIL.png -t 1000
                notify-send "Failed" "Build Failed" -i $PWD/images/circleFAIL.png -t 1000

So what this does is wait for file changes in the directory structure (notify wait). It then checks to see if the file returned matches an include filter eg “*.cs” if it does it will then build the code followed by running the tests. When you get a failure/success you will receive a notification including a red/green circle in xwindows (regardless of if you are still in sublime). If you want to see you can view it here its a shell script in EventStore to ease in the running of tests on linux.

This is a great showing of the “unix philosophy” of small tools being composed together to get something larger. It was not hard to make this but it provides 80% of the value of and is vastly more configurable if you understand shell script (want an exclude vs an include just edit the script).

There is no fancy installer. There is no visual studio integration to do (I will never do that ever again). On EventStore source base which is by all means not a small source base (roughly 2000 tests which are run locally) the entire cycle is 15-20 seconds on my machine. Although MightyMoose could have gotten this to around 5 which would be even better for simplicity this wins out.

One problem that I ran into had to deal with nunit-console when you have ignored tests there is no way to get it to not print out all the ignored tests (which it does of course last! so you can’t see your failures). To work around that I wrote a small xslt to format its results

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"	
<xsl:output method="html" indent="yes" />
<xsl:template match="test-results">
			<xsl:variable name="failedtests.list" select="//test-case[@success='False']"/>
			<xsl:variable name="total" select="@total + @not-run" />
   			<xsl:variable name="success" select="@total - @failures - @errors" />
          	Total  : <xsl:value-of select="$total" /> Success: <xsl:value-of select="$success" /> Failed : <xsl:value-of select="@failures" /> Not Run: <xsl:value-of select="@not-run" />
			<xsl:apply-templates select="$failedtests.list"/>
<xsl:template match="test-case[@success='False']">
	<xsl:value-of select="@name"/>
	<xsl:value-of select="failure/message"/>
	<xsl:value-of select="failure/stack-trace" />

This will give you a printout that looks like this:

          	Total  : 1748 Success: 1699 Failed : 1 Not Run: 48
	EventStore.Core.Tests.Services.UserManagementService.password_change_notification_reader.when_notification_has_been_written.publishes_reset_password_cache  Expected: 1
  But was:  0
at EventStore.Core.Tests.Services.UserManagementService.password_change_notification_reader.when_notification_has_been_written.publishes_reset_password_cache () [0x00000] in &lt;filename unknown&gt;:0

Again we have not done anything complicated here we are just composing our exists tools. I should add that you can easily make those links clickable back into sublime to go to a line based on stack trace but you either need to switch your terminal from gnometerminal or you need to add one line of code and custom build gnome terminal which may be a bit much for some people :)

As a quick exercise could you write a script like above for javascript?

Sublime is Sublime 7

So as we have come along the path our sublime instance is starting to feel quite a bit more customized than it was before. We can now build, have git/github integration, and of course have awesome command line integration but what about running tests?

We will start with the simplest way of running tests. This may not work for all of your scenarios and does somewhat require you to have thought about things in advance.

If you for instance started off from the beginning with resharper as a test runner you are probably have a test suite that will be difficult to use. Likely it is all in one assembly regardless of whether its a unit test or an integration test. Quite likely the tests have large numbers of dependencies. And to be frank your unit tests probably don’t run properly in linux anyways. Yeah this kind of sucks but can be fixed.

To start with there is no integrated right click->debug test in sublime. I find however that this is not something I missed. Maybe its having worked for a few years building embedded systems where there was no debugger (except dumping as hex pieces of memory).

Let’s talk about the simplest way to run tests from sublime and the general workflow. Normally when working with sublime I have multiple test suites either separated by category or by assembly. I have unit tests which are quick to run and then all other tests. I rarely if ever run the other tests locally. Instead I let a CI server run those. My unit tests should be run in and this would give you a new buffer with the output of your tests running. For a huge portion of code you will be working on this is *good enough*. If you have a 10 second cycle on tests running it is completely reasonable. eg

ctrl+shift+c run >

where I have a script called run that runs nunit in the way I want.

There are however some other things you can do if you want to be more fancy. The first is you could assign the running of the script to a key in sublime. This is actually quite easy any command can be assigned to any key by editing your keymap

Another cool option that is quite easy to enable to get a notification from linux on the status of your build/test run. This can be done trivial using notify-send in your small script above based on return values from processes.

notify-send ‘Hello world!’ ‘This is an example notification.’ –icon=dialog-information

You can even change the icons to say red/green circles for the notification.

Now if your tests are more than 10 seconds. The first strategy would be to start putting them into categories that make sense to you. This way you can only run tests within a given category. This step alone will normally be good enough to get your test runs back under 10 seconds (I prefer 1-2 seconds). If this is not then perhaps your code base has become too dependent on the tool (15 categories 10 seconds each…). One thing you will notice is that your tests in general will run far faster than through tools like VS/R# when being run from the command line.

OK so now we have basic unit test integration. There are still a lot of problems with .NET code. In the next post we will look at what some of these are and how to deal with them.

Sublime is Sublime 6

So far we have done quite a bit getting sublime up and going for use with .NET work but we still at this point have to compile our code from the command prompt which well sucks. In this post we will look at how to get compiles working from within sublime by adding a custom build system for xbuild.

Go to Tools->Build System->new build. A file will open. Drop in:

“cmd”: [“xbuild”],
“path”: “/opt/mono/bin/”,
“working_dir”: “${project_path:${folder}}”,
“file_regex”: “^ (.*)\\(([0-9]*),([0-9]*)”

Then save this file named xbuild. You can now choose xbuild as a build platform.

Is is important to note that you have to point at the correct xbuild (I run off trunk so I compile with a /opt prefix if you get from say apt-get it will be some place else) and you must have the correct mcs in your path when doing this. This code also assumes that you have only a single solution in the root folder of your code.

Once this is done you can choose xbuild as your current build provider. Then you can use either f7 or ctrl+b to build your code on demand.

Now we are really starting to get there. In the next post we will look at how to run unit tests from within sublime manually.

Sublime is Sublime 5

So far we have learned how to install packages and have setup some basic packages for color schemes and for git. In this post we will get better support for the command line as there is lots of useful things that can be done on the command line in a linux system and as a developer you tend to be there often.

To do this bring up the command pallette (ctrl+shift+p) and type install which should bring you to install package. Hit enter and you will get the same popup as when installing the git support in the last post.

In the box type shell turtlestein to install this package This is a very simple package but its also very powerful.

Once it is installed type ctrl+shift+c and a textbox will come up at the bottom of your screen. Any text you type here will be executed. As an example you can try ls -al and you will see the results of your command. This is how you can run arbitrary commands from directly in sublime.

There are however some other features of this command prompt such as being able to take text from in sublime and move them to the command prompt or to take text from the shell and move it to a buffer.

To move text from your command back to a buffer you use the > key trailing your command. As example try ctrl+shift+c then type ps -ax >. This will create a new buffer in sublime with the results of your command. We could even build this way xbuild yoursolution.sln > would bring up a new buffer with the build results but it is not the best way of doing this. This is very useful when writing documentation of say a restful service and interacting via curl

You can also take a document and pipe it to the command (it gets passed as stdin). An example of this can be seen with | wc or | wc > to get the result into a new buffer. The | will either take your selected text in the buffer or the whole text if nothing else is selected.

You can even combine things and do a transformation on your buffer through the command line. An example of this might be | sort | or | transform | which transforms the text then replaces the text within your document.

As you can imagine there are a huge number of possibilities that are now available to you from just interacting with the command line and we will use some of these in the next few posts to do other things that you will need to do on a daily basis.

Sublime is Sublime 4

Now we are heading into our fourth post about sublime. So far we have looked at why we might want to use sublime. We have installed sublime and learned some basic key shortcuts and we have installed a package manager with our first package. In this post we will install git integration into sublime and look at how its used.

This post assumes that the code you have opened in sublime is in a git repository!

So let’s start by installing the git package.

Hit ctrl+shift+p (you should be good at this)
Type install wait for 2-3 seconds
Type git and hit enter to install

After a few moments the git plugin will be installed. You may or may not need to restart sublime at this point I have heard mixed results.

Now let’s try using our git plugin. Let’s start by being in a file under source control and hitting

ctrl+shift+p git log

You will see the full log of your code. If you select one you can view the commit in a text window.

Let’s try another common one

ctrl+shift+p git pull

This will do a git pull. This is just the very beginning of the integration though. One of my favorite features. Add a new file foo.cs. Then in that file do a

ctrl+shift+p git add (current file)

if you then do a ctrl+shift+p git status you can see that the file has been added. We can also add such fun functionality as ctrl+shift+p blame :)

When you want to commit:

ctrl+shift+p git commit

this will bring up a buffer of your commit. Just type it your comment and hit ctrl+w to close the window and commit.

This plugin has very deep git integration including diff viewing and annotating code while working in it! You can find more on its feature set here

It takes a bit of exploring but you can do quite a bit with git integration in sublime and its language agnostic which is really nice.

While we are on the topic let’s install the github plugin since many of you are probably using github. The package is sublime-github You can read more about the configuration of the plugin on their website but it allows you to do things like

view on github (opens code in browser)
manage gists (eg file or selection to public gist)
browse gists

Overall its quite well done as well.

So now you have gotten full git and github integration into sublime very soon we will start getting into the C# specific stuff but before that we need some better linux specific handling.

Sublime is Sublime 3

In the last post we installed sublime and learned (hopefully) some of the basic operations in it. In that setup however you still have a long way to go to being effective in sublime actually doing much of the stuff in your development process will be quite painful (try adding a file and having the joy of manually editing .prj files). In this post we are going to install a package manager and become comfortable with its basic operations. We will need it for the next few posts where we will add on some functionality to sublime.

To install the package manager browse here: there are instructions on how to install it. Select Sublime 2 copy the related python code. Go into sublime and hit ctrl+` this will open your command window. Paste the python code and hit enter the package manager will now be installed. You will need to restart sublime for this change to take effect.

Once you have restarted sublime let’s try to install a package.

hit ctrl+shift+p
type inst (it should bring you to install package) hit enter it make take a few seconds to pop up.
you should now have a list of packages
type Dayle Re and you should see this theme.
Hit enter to install the theme. You will see in the status bar the status of installing it.

If you now go to preferences->color scheme you will see the color scheme that you just installed I personally like sublime->darkside try setting it.

In this post we have installed a package manager and learned how to install a package. In the next few posts we will install some other useful packages.

Sublime is Sublime 2

Now we are into the second post about how Sublime is Sublime. In the last post we looked at some reasons why we may want to use Sublime. In this post we will install Sublime and learn some basics of how to get around the editor.

We will install Sublime 2 (not sublime 3 though much in sublime 3 is similar in sublime 2). Installing Sublime is quite easy. In ubuntu you can just use:

Sublime can be installed for your platform from

Once installed run sublime. You should get a boring looking window. Sublime is just a basic code editor that supports syntax highlighting etc. Some useful keystrokes that you should know contains a bunch of useful keystrokes you should become familiar with. Some of the most important are:

ctrl+p goto anything
ctrl+shift+p command prompt
ctrl+g goto line
ctrl+r goto symbol in file
alt+shift+2 make 2 columns
alt+shift+1 back to 1 column
ctrl+1 focus on 1
ctrl+2 focus on 2
ctrl+shift+1 move file to 1
ctrl+shift+2 move file to 2
f11 full screen
shift+f11 distraction free mode
ctrl+kb toggle side bar (explorer)

Generally when working with a set of code you load the root folder into sublime (file->open folder) you can then view the structure in the side bar to navigate around files.

Some things you should try:

Preferences->Color Scheme
View->Syntax (put on C# if its not already!)

Try opening up some code in Sublime. Try navigating around your code. Switching between column views. Definitely check out distraction free mode.

You will notice that you will have some troubles. Adding a file for instance really sucks as you have to manually edit a project file. How do you build? What about running unit tests? We will get to all of these things and more in the next few posts.

Sublime is Sublime Part 1

This is the first blog post in a series about getting sublime working for .NET development. We will look at how to get nice color schems, git integration, command line integration, handling project and solution files, and both manually and automatically building/running unit tests. Before getting into the details about how to get everything setup one of the most important questions that should be looked at is *why*.

Why not just use Visual Studio and Resharper? Are you just some kind of hipster?

And the chap below is not really a hipster. 


I was for a long time a fan of VS+R#. It is quite a nice IDE. Over time however I started seeing some of the downsides of this particular setup.

The first is that its a windows/microsoft only experience. Currently the majority of my machines do not have windows installed on them. They are running linux. I am not saying that windows is a bad platform but to have my dev tools not work in linux is for me a downside to the tool.

VS + R# is also an extremely heavy tool chain. It is common for devs to need i7s+16gb of ram to be effective using the tool chain. This is especially true for those doing things like solution wide analysis with R#. I have never met a developer in VS who has not had the “I just want to open a file what are you doing!” moment while VS somehow takes 20 seconds to open a text file where a normal text editor should be able to do this in under 500ms.

Another advantage to not using VS is that the tooling can be used for other things. How many keystrokes have you memorized in Visual Studio? How applicable is that knowledge to working in erlang. Lately I have been writing a lot of code in erlang and in C. One positive aspect of just using a text editor is that my tooling is portable to multiple environments/languages. How many companies do you know that have programs to try to learn shortcut keys in their editor du jour? Is that knowledge portable?

There is also an issue of cost. We in the western world often forget how much things really cost from a global perspective. My entire investment on my tooling was $70 for a sublime text license though you can use sublime for free if you want on an “evaluation” period. It will annoy you occasionally about licensing but will still work (I was actually using it this way even though I had a license just because I wasn’t thinking to put my license in). $70 will get you roughly 1/3 of the way to a resharper license (with paid upgrades roughly once per year) forget about tooling like Visual Studio Ultimate at $13k. I could have a team of twenty for roughly the same cost as one developer.

But won’t I miss Resharper and all the great things it does?

Yes. You will. Resharper has some great functionality and when I use it I really feel like I am coding significantly faster. Sublime will not optimize using statements for you. Sublime will not see a type and offer to add a reference for you. Sublime does not have intellisense (although this can be reasonably easily built into it). Sublime does not have automatic refactorings. I would however challenge you to still try using it.

A while ago (roughly two years ago) I decided to actually measure my usage of resharper and how much faster it made me. To measure I wrote a program that would track keystrokes going to Visual Studio (obviously resharper won’t be helping me in chrome). I then put a hot key to track when I was starting to code and stopping. In measuring resharper did make me much faster in the process of inputting or changing code the problem was evev during code heavy times this was a rather small percentage of my overall work. A lot of time was being spent thinking about the code I was writing and/or researching about the code I was writing. I found it to be for me a micro-optimization (try measuring, your results may be different).

There are also downsides to tools such as resharper. One I noticed was that I had basically forgotten which namespaces things live in as the tool would automatically add references for me. Resharper also does some things that you would never do yourself. As an example in a rename that affects domain objects, dtos, and your client. In doing such a “refactor” you also just broke your wire protocol without realizing it. On many teams I would see developers commonly checking in 70+ files why? They were renaming things. Renames that bubble out this much are generally a sign of a problem.

Said simply resharper can help hide many design problems in your code especially problems with encapsulation. Being forced to type your code in will often times also lead to better ways of doing things. I gave an example of this in my 8 lines of code talk when dealing with an application service.

public class InventoryItemDeactivationService {
 private IInventoryItemRepository _repository;
 private IDriversLicenseLookupService _driversLicenseLookupService;

public InventoryItemDeactivationService(IInventoryItemRepository repository, IDriversLicenseLookupService driversLicenseLookupService) {
 _repository = repository;
 _driversLicenseLookupService = driversLicenseLookupService;

public void DeactivateInventoryItem(Deactivate d) {
 var item = _repository.GetById(;
 item.Deactivate(d.reason, _driversLicenseLookupService);

compared a more functional approach of

public static void Deactivate(IInventoryItemRepository repository, IDriversLicenseLookupService driversLicenseLookupService, Deactivate d) {
 var item = _repository.GetById(;
 item.Deactivate(d.reason, _driversLicenseLookupService);
 var handler = x => Deactivate(new OracleRepository(), new CALookup(), x)

In the top piece of code a tool like resharper will help me greatly because everything I am doing I have to type three times. In the second example though I get much less help from my tooling as I am not repeating myself. I would suggest that if you are actually typing your code by hand you are less likely to use the first style and more likely to be interested in the second.

I also find people who are doing TDD in static languages with such tooling to not understand what the concept of a refactor is compared to a refuctor where as dynamic language people working in plain text editors do. A refactor is when you either change your code but not your tests or your tests but not your code. One side stays stable and you predict what will happen (one side stays as your pivot point). If you change both your code and your tests concurrently you no longer have a stable point to measure from. With this tooling often forces changes to happen on both sides and it is no longer “refactors” that people are doing.

In summary

I am not in any way saying that VS and R# are bad tools I have found both to be quite effective. I am simply suggesting that they have their downsides like any other tool. Being able to develop in a plain text editor is a wonderful development environment and has some advantages to larger tooling in some cases.

In this series we will look at how to get everything setup to have a reasonable code editing experience. We will look at integration of tools such as git. We will look at how to manage many of your day to day tasks. We will not get into things like how to edit a winform with a WYSIWYG editor as frankly you can’t do this.

Event Sourcing and Post/Pre Dated Transactions

There was a recent question on the dddcqrs list asking about retroactive events as well as post-dated events. This is quite a common question and the answer is YES. Event Sourcing works very well on these types of systems. In this post we will look at how such systems tend to be built.

It is possible to allow the back/future dating of any transaction relatively easily. It could be hard coded in the handling of any event. In general however you would not want to hard code such behaviours for every event that could be pre/post dated. Instead in such systems you will generally come up with mechanism that applies to any event.

One such way of doing this would be to add metadata to the event (either on the event itself or to an envelope/metadata describing the event). An example of this could be:

     applies : "2011-10-10T14:48:00"

This also applies to a similar pattern

     reverses : 1764532

Where the event is said to be a reversal of a previous event.

This would say that the event should be treated as if it were put there on Oct 10 2010. While being a very simple framework this is also a very common mechanism. If you look in the accounting domain this is regularly done. I can put something onto my books today but apply it to some point in the past (or in the future). The record is still known to have been put today but can apply to another time period. This is commonly done around year end where things need to be applied retroactively to the previous period.

This leads to some interesting differences in how queries operate. It introduces two forms of every query in the system “As of” vs “As At”. From BizWritinTip

BizWritingTip response: This is quite an interesting point. Most people are accustomed to using “as of.” However, when providing a snapshot of a particular position on a certain date, “as at” is the correct term. You will find it often in accounting.

“As at” means as it is at that particular time only. It implies there may be changes.


As at 9 a.m. today, 30 people were registered for the event.

“As of” means as it was or will be on and after that date.

In other words an “As at” query will give us results at a particular time point within the stream (what did we know as at this point in time). This query operates in the same way as a query in any normal event based system, you replay events up until that point in time. Using the accounting system example for a query as at 2010/10/10 you would query all transactions up to that point in time.

The second query type “As of” also takes into consideration events that may need to be retroactively applied. In this query you would replay the event stream up to the point in time that was specified. You would look through the rest of the stream for any events that would need to be applied retroactively before the time specified in the query and apply those as well. This can obviously be an expensive query if you have a large stream. Using the accounting example you can imagine doing the equivalent of the “as at” query and then applying any events in the rest of the stream that have an applies that is before the date of your query.

It is common when dealing with large streams that contain very few retroactive events to build up an index in a separate stream of retroactive events to avoid having to look at a large number of events. Imagine in the accounting example having 25k transactions of which 5 were retroactively applied. You don’t want to have to scan all 25k just to get the five.

As you can see both of these types of queries are relatively simple conceptually. This however leaves one other time based query to deal with and that is the concept of post dating. In this case as at might ignore the postdated event if the applies is after the time point that the query is being executed for.

Overall Event Sourcing works as a relatively simple model for these types of queries and has been used for centuries to provide for the exact behaviours desired in the question.


Get every new post delivered to your Inbox.

Join 10,247 other followers