Tuesday, 27 April 2010

C# 4 Last Minute Additions

Update: I'm being very anti-Microsoft at the moment because they make it too expensive for me to get an MSDN license to develop at home. In the past, I've been a big fan but I'm going to defect if they continue down the money or nothing path. Until they stop excluding me from their expensive community, I shall sulk and ridicule them. Please read and have a giggle. It's meant in jest.



I love reading Eric Lippert's blog because he is great at explaining complex ideas in an easy way. That is something severely lacking online. He also dishes the news on my latest reading obsession... C# 4.

They have managed to slip in a few extra features last minute in to the next version of the language. He describes them in more details here. The one's I thought were cute and make the language a little more interesting are the goes to --> and is approached by <-- operators used in loop conditions.

The examples given on his blog show them being used like this:

int x = 10;
// this is read "while x goes to zero"
while (x --> 0)
{
Console.WriteLine("x = {0}", x);
}

int x = 10;
// this is read "while zero is approached by x"
while (0 <-- x) { Console.WriteLine("x = {0}", x); }


Interestingly, when I mentioned the last minute additions to a colleague she commented that she hopes they implemented them properly. In C# 3 they snuck in partial methods and auto-properties which I wouldn't want to live without (although I am in Java-land at the moment).

I'm excited about C# 4. Now I just have to get Microsoft to give me a reasonably priced MSDN license for an individual who isn't a student, a company or a start-up. Market gap.

A recent email I sent to a friend who has started automated testing


Here is a quick email I threw together for a friend who has started writing automated tests and asked if there is a reason to have lots of different kinds of tests covering the same area. Yes, it's simplistic and I'm sure a bunch of ThoughtWorkers would kick me and say it is better explained in other ways but I think this is a good summary. In case it helps others, here it is...



OK, this is the way I structure testing of an application. This works when the tests are written retrospectively or if the application is written in a test driven manner.

There are three types of tests:
  1. Functional tests - UI testing that uses the terms of the users/business. You'll see tools like Selenium with junit/nunit/rspec used at this level. Functional areas of the application are tested in a similar workflow to what I user would use. Happy path comes in here for primary workflows. Deliberate error (validation and business logic) and exception testing at the highest level occur now;
  2. Integration tests - these tests are used when you are plugging all the bits of your system together. Bits can mean layers, components within a layer, or dependencies outside of your system (third party web services, etc...). The point of this is a test interfaces and APIs that are public to the component or application parts. You test input and output in a black box way. Again, with all good data and then causing errors and exceptions;
  3. Unit tests - These tests are the very specific low level tests that check that a unit of functionality is working. This can be at a class level, library or component. You'll see mocking frameworks used here to imitate data sources or connecting systems. At this point, you do not want to be distracted by the possibility of functionality external to this unit causing issues so it doesn't talk to anything and gets all input or directs all output to mocked objects.
The reason for the three layers individually is explained above in each point. The reason you do them together is that with continuous integration and thorough test suites, you can easily track down where an error is occurring and focus in on the area of concern. All these tests should be used together.

This is a starting point and written at a high-level. Ask me if you need it clarified further.

Offline Installers


Most installers available for download online these days, will actually download a a small executable that will download the rest of the required installation files form the Internet as it progresses. If you have a slow connection or are using a proxy then it will often fail.

Do not fret.

Usually, there will be an option to use what is called an Offline Installer. It will be accessible from another location of the installer's website. If it isn't obvious and easy to find then search for application installer offline in your favourite search engine.

For example: Here is the online installer for Chrome from Google and the here is the offline one.

This may seem too simple to share but I've encountered several people who have given up trying to install something because it failed through the online version.

Friday, 9 April 2010

Restart Windows from the command line


If you don't have access to restart a Windows machine (maybe you've remoted in) then here is the cheeky way to do it from the command line...

> shutdown -r -f -t 01

Where...

  • -r is Restart (you can use -s for a straight Shutdown and -h for Hibernate);
  • -f is Force; and
  • -t is Timelapse with a 01 second delay.
If you want to abort the shutdown use...

> shutdown -a