New Monitor


Today I got a new 24″ Samsung T240 for my office at home. I’ve been working from home a lot recently and have really been missing my dual monitor setup from work, even though it is only my laptop with an old 17″ LCD. Two monitors definitely make a big difference to my productivity when coding. I already had a 22″ Samsung 226BW, which now looks thoroughly inadequate next to the 24″ as you can see from the photo below.

My New Desk Arrangement

My New Desk Arrangement

Once I got used to the larger monitor I had a pretty productive day though. The T240 is a decent monitor for developing on, judging from one day’s usage. Text is clear, and after a little tweaking the colour looked about right, enough for my purposes anyway. Not to mention it is a nice looking monitor. All in all, it was well worth the money I/the business spent on it.



TechEd 08 – Day 1


Figured I would write a little about each of the interesting sessions at TechEd, just as a note keeping exercise.

Keynote Speech

National’s John Key and Labour’s David Cunliffe talk about digital strategy.

National’s strategy: $1.5B over 6 years to a single utility for fiber to the home.

Labour’s strategy: $1B over 10 years to multiple providers.

Microsoft’s Amit —- talks about Software+Services

  • Local software extended with on demand computing services.
  • Small pieces loosely joined. Interoperability and standards become important.
  • Foster best of breed software and services.
  • Connecting devices together.
    • All devices seamlessly and securely integrate with each other.
    • Simple management of devices, software, and data.
    • Sharing of data between all of your devices.
  • Cloud computing, how do we split work between client and cloud.
  • Connected Business
    • Consistent UX across delivery and deployment options.
    • Common architecture and data models across deployments.
    • Flexibility and Adaptability in deployment.

WEB301: ASP.Net MVC – Should You Care? – Scott Hanselman

Very similar to Code Camp talk on ASP.Net MVC talk by Owen Evans. Scott talked mostly about the standard ASP.Net MVC features, but he is always entertaining to listen to so it was still worth watching.

ARC201: Moving Beyond Industrial Software – Harry Pierson

  • Architects are responsible for predicting and reacting to change.
  • Current Day:
    • Most IT departments are run like a factory. This is a bad model for creative work.
    • Change is happening now – traditional business models are falling apart.
  • Recommendations
    • Push control to the edge.
      • Centralized models of control cause bottlenecks.
      • Centralization as a technology no longer works.
      • Centralization slows you down – prevents marketplace agility.
      • "There is not one Microsoft anymore" – Steve Ballmer
      • Loose coupling between departments. Still need some decision making power at the centre, but not much. Central control over the budget is a good level.
    • Know when to ignore standards.
      • Choice between solving a business problem and adhering to a standard – solve the business problem!
      • The cost to maintain standards is not zero.
      • Adherence to standards costs as well.
      • Efficiency through Standardisation only occurs in a factory style environment – This is not IT!
      • What is the simplest thing that could work?
    • Empower users to solve their own problems.
      • IT people will never understand the business. If your business idea relies on good communication between IT and business people, you will probably fail.
      • Lack of marketplace within an enterprise means that there is no "natural selection" going on.
      • Build infrastructure and tools, not solutions.
      • Common, centralized infrastructure for business users to build their own solutions on. "If you want something done right, you’ve gotta do it yourself"
      • Common infrastructure costs can be amortized across the entire organization.

SEC306: Privacy – The Why, What, and How – Steve Riley

  • Data breaches in 3 1/2 Years: 227,120,380 in the US.
  • It is practically impossible to have a private face-to-face conversation with today’s invasive technologies.
  • Privacy: The right to be left alone.
  • Privacy laws and fines for data breaches have not caught up with technology – it is possible to expose your entire customer bases private data, but it is cheaper too pay the fine than fix the problem.

Steve’s session was more of a discussion. He went through a bunch of different scenarios, what was an acceptable levels of privacy invasion, what evil things it is possible to do with large amounts of user data. I don’t have much written down because I was too busy listening.

WEB302: ADO.Net Data Services – The zen of RESTfulness and the art of "Astoria" – Scott Hanselman

Astoria looks interesting – it is a framework for setting up REST web services from Entity Data Models. It looks pretty cool, you can then set up a service reference to this and use LINQ to query it. It really looks like Microsoft are setting all their stuff up to work with LINQ and enties now – very cool. The demo showed that you can use the same LINQ query on both a local database using LINQ to SQL, and by just changing the data context, you can query an Astoria web service.

As a side note, Astoria web services are just regular XML (in fact they return Atom), so it is possible to write your own implementation of this. You can set the expected data type (again, standard REST), so you can get back JSON if you want. This is important, because it allows them to use AJAX to pull this data back, and use the entities in the javascript using the actual property names. The data context has a few extra things in it, like the ability to batch requests. Again, these work in a standard REST style.



StringBuilder Performance Issues


We are working on a templating system, so as you can imagine we have to deal with the construction of massive strings of text. Conventional wisdom is to use a StringBuilder rather than a lot of String concatenation, but we wanted to test out the speed of StringBuilder to see if there were any issues that we may encounter. These might not be the best tests strictly speaking, but they show some interesting points that are worth thinking about. Here are our results:

Profiler_first_run

The first run was just to get the string builder code in memory.

Profiler_second_run_first_result_set

This is the same code as above, but hopefully the JIT has run over everything we are profiling so it should have less effect on our tests (if it has any at all in a debug build). Insert seems to be a touch faster but this could just be due to inaccuracies in the profiler though, as they are pretty small..

Profiler_second_run_second_result_set

Our last set of results. This time we took the ToString() call out of the loop and did it at the end. Look at the difference this makes to performance! Both Append and Insert perform nearly identically. The ToString() call itself is very quick, yet somehow it messes up the performance of Append and Insert drastically. Our application needs to periodically get the current state of the string builder, so we fall into the first category- where both Insert and Append perform terribly.

Test Scenario Time spent in loop (s)
Append and ToString 12.5000
Insert and ToString 12.2000
Append and ToString with preallocation 12.4000
Insert and ToString with preallocation 12.8000
Append without ToString 0.0092
Insert without ToString 0.0100
Append without ToString with preallocation 0.0083
Insert without ToString with preallocation 0.0103

Interesting results can come from performance profiling things – Why on earth does calling ToString() mess up the performance of StringBuilder, and is there any way around this?



UI Design, Unit Testing, and Related Pains


Background

Currently I am working on merging two of the steps in the Workbench part of ArchAngel. The final two steps of the generation process used to be the actual generation of the files you wanted, and the analysis to see which files needed to be merged. This was two screens, one in which the user picked the groups of files to generate, and the other which showed conflict resolution. Only after all conflicts had been resolved could the newly generated and merged files be copied into the user’s project directory.

UI Changes

This wasn’t as easy as it could be. There is no reason why the user needs to go through an additional screen to choose the files – why not just put that on the screen with the analysis so they could choose which files they wanted to keep? So Gareth merged the two screens, shifting the file choosing part to the tree view with checkboxes, and showing the results of the analysis as an icon next to the file in the tree.

Process Changes

One thing Gareth wanted to do was generate the files in the background. I set up a process whereby the files would be generated on a background thread, and if the user changed any options in the project, the files would be regenerated. Hopefully most of the files would be generated by the time the user actually got to the final generate and merge screen. We also do the analysis on the same thread once the generation is done.

Unit Testing

This process is really the meat of the ArchAngel Workbench – the majority of the processing happens here. Thus I wanted to make sure that I wasn’t breaking anything by implementing this background processing, as I had to make a number of changes to make it thread-safe. So I embarked on a quest to make this part of the system as easy to unit test as possible.

I started by completely removing any trace of GUI code from the generation code. This meant removing the background worker references, and replacing all of the code dealing with threading with a helper class I created. This class encapsulated progress reporting and task cancellation, so that we can mock these aspects during testing.

Mocking is a major focus of this process – I want to be able to mock out as much of the system as possible in order to make the unit tests more focused. The thing with mocking/faking the major components in the system is that we can write these mocks/fakes once, and reuse them in all of our tests. This is better than relying on resetting the state of the major components – this is prone to failure if those components change in future. Also it is difficult to prevent behaviour that relies on the underlying environment, such as writing to files and reading from settings files.

On Monday I will start working on creating some mocks for these components, and will add another post with my experiences of this.



Quick Update on Unit Testing


Just thought I would add one more blog post to the millions of others floating around the net about how great unit testing is. I’ve spent the last week or so designing and implementing a cleaner version of one of the major modules of ArchAngel, and I couldn’t have done it without the regression test suite I wrote. It picked up all of those tiny little bugs that you just look over, but will cause you massive grief later on because they exist in parts of the code that "should just work".

The number one lesson I’ve learned from this is to never assume anything works, even very simple things.

I started reading Pragmatic Unit Testing in C# with NUnit (http://www.pragprog.com/titles/utc2/pragmatic-unit-testing-in-c-with-nunit-2nd-ed) a few days into the design phase, and although I was doing some unit testing it pushed me into implementing more and better tests. It is a really good introduction to both how to unit test, as well as what to test. I highly recommend it for anyone working in C#. They have a Java/JUnit one there too, but I haven’t read that one.

In short: Unit testing saved my sanity this week.



Contracting Experiences So Far…


The first thing I did before collecting any money was set up a separate bank account. I got another Fast Saver, which is currently offering 7.75% interest per annum. This way I can earn a little interest on my tax before I have to pay it out at the end of the month.

At the end of last week I sent out my first invoice, and received my first bill payment. I used the online PAYE calculator at PAYE Calculator 2008 to calculate my income after tax. I then removed that amount from the business account, leaving the PAYE and GST in there for later payment. This means there is no chance of missing a tax payment, as I have kept the money aside.

I’ve also been printing out everything (invoices, tax calculations, bank statements showing income and payments) and putting it aside. This should make it easier for me to organise everything when it comes time to pay my taxes. I have asked an accountant (a very helpful family friend) for a bit of advice as to what I should be doing too, and he is doing a bit of research for me.

On the actual work front, everything has been going great so far. Gareth has been very helpful in getting me up to speed on the code base. I’m currently working on a formatter for TSQL code. I’ve written a bunch of new code, as well as refactored old code to make it easier to modify. I am also creating a unit test suite to make sure I don’t break anything. My next major task is to incorporate a whitespace insensitive text diff into our tests – this way I can run the code through the formatter and make sure it hasn’t removed anything important. Since there is a huge amount of TSQL code to work with, I can just run the formatter over it and throw the before and after code at the diff. If anything gets broken, the diff will pick it up.



Playing with ANTLR


Today I started doing some research on ANTLR (http://www.antlr.org/), a very powerful parser generator. It compiles language grammars into source code for a number of languages (I am working with C# output mostly, but it primarily creates Java). I am currently learning about Abstract Syntax Trees (http://en.wikipedia.org/wiki/Abstract_syntax_tree) and how I could use one of those instead of a Parse Tree (http://en.wikipedia.org/wiki/Parse_tree), which is what I have previously been working with when parsing languages. The major difference is I need to modify whatever language grammar I am using so that it produces an AST. I am hoping this isn’t too difficult, but we will see how things go over the next few days after I get up to speed on ANTLR. So far it looks promising though. I am impressed with how powerful ANTLR is – because it produces source code, you can embed code in the language specification itself. It looks like it is going to be a bit of fun figuring this all out :-)



Registering For GST


Today I registered for GST using the online form at the IRD website (https://www.ird.govt.nz/cgi-bin/form.cgi?form=ir360) after calling the IRD the other day and asking for a bit more information (they sent me some booklets). This was relatively painless, but necessitated by the fact that I am collecting GST from Slyce on my invoices. The good thing is you can apply to file every six months, which means I don’t have to worry about it for a while. They also say they might get in touch with you to give you a bit of advice on how to file a GST return. Which sounds pretty good to me.

Another thing I thought about today is ACC. It seems as a self employed person they calculate my ACC levies from my IR3 tax return at the end of the year. So I get stung with more bills around tax time. One thing I need to ring them and ask about is what happens if I stop being self employed half way through the year. Hopefully this should be just a case of ringing them and telling them when the time comes.



Joining the Wonderful World of Contracting


Today I was offered a contracting position with Slyce (http://www.slyce.com), a start up working on an amazing looking code generation tool. It allows the use of generated code without interfering with the ability to modify these files. Each file can be modified at will, and ArchAngel (http://www.slyce.com/ArchAngel/) will be able to reconcile those changes with any that it makes should the project be regenerated. I encourage you to read more about it – there’s not a lot of information about it on the website currently but that should change soon.

Expect to see a few posts dealing with the issues related to working as a contractor – I have to pay my own taxes and what not so I will try to detail how I went about the process in the hope that it proves useful to someone else.