Speaker Training full

As I mentioned in the Scottish Developers July Newsletter Microsoft are running speaker training sessions to help community speakers get started or improve their skills with regard to technical presentations. I just got an email earlier today to say that all the places are full already. Microsoft will be running another session at some point, so if you missed this opportunity there will be another sometime in the coming months.

In the meantime if you want to get your feet wet and have a go at speaking for a short 5-10 minutes session we always welcome new speakers at Scottish Developers. Just drop me an email to colin@scottishdevelopers.com. We also have an open mic night from time-to-time so drop me an email if you’d be interested in that.

 

Speaking at SQL Bits III

I’ve just had the email through to let me know that my session has been selected for SQL Bits III on the 13th of September. I’ll be talking on the subject of Spatial Queries in SQL Server 2008, an evolving talk I’ve done a couple of times before. It will be updated once again for SQL Bits III.

Here’s the abstract: It is reckoned that 80-90% of data has a spatial component to it. But what do we do with it now? At best, we constrain it to postcodes. Well, that would be great if we were delivering letters, but the majority of us aren’t. In this session we look at Spatial Queries in SQL Server to see how it works and what can be done with it.

Scottish Developers July Newsletter

Welcome

We are now in the middle of summer, however as I write this over a period of several days I can tell you that it has been chucking it down and it has been roasting.

If you are interested in SQL Server, the SQL Bits III conference (13th September) has now opened registration and session voting. They’ve opted to allow people to register for the event before they’ve even finalised which sessions are going to run. So, you could take pot luck and register now, or you can wait and see and take your chances that there will be places left.

I would have also been advising you of the ALT.NET conference in London (also 13th September) but when I last checked it was full already! Delegate Registration had only been open for a few days. If you’ve not signed up already there is always the Glasgow ALT.NET User Group. Added to that ALT.NET supporter Paul Cowan will be talking at Scottish Developers in Glasgow in September.

We also have exciting news that we have finally (and formally) merged with the North East Scotland .NET User Group. This gives us a permanent presence in Dundee. It also means that we should be able to put on events in Aberdeen from time-to-time. If you are from either city then get in touch and let us know what you’d like us to be putting on for you.

Our new committee is as follows: Colin Mackay (Chairman), Gary Short (Secretary), Frank Kerrigan (Treasurer), Barry Carr (UG Coordinator) and Craig Murphy (UG Coordinator).

As always, we are on the look out for new speakers. If you would like the opportunity to do a presentation on a software development topic from 10 minutes to 90 minutes then get in touch with me at colin@scottishdevelopers.com. If you are interested, but don’t think you have the skills to stand up and talk to a group of developers Microsoft are running some technical speaking training courses for those that want to speak to user groups. The courses will be held in Reading. The first is on 29th August. If you are interested drop me an email.

Regards,
Colin Mackay, Chairman, Scottish Developers

Events

6-August-2008 @ 19:00 in Dundee (Scottish Developers)
An Introduction to Oxygene and its parallel coding features
FREE – Registration optional

Oxygene (formerly known as Chrome) is an advance .NET (and Mono) language by RemObjects influenced by Object Pascal. Oxygene has all the features of C# plus several more powerful features unique to itself. These include: Interface Delegation which provide a similar behaviour to Mixins; A null safe member access operator; Full support for “Design by Contract”; Virtual static members and Virtual constructors that can make writing object factories a breeze.

9-September-2008 @ 18:30 in Glasgow (Scottish Developers)
An Overview of ALT.NET Technologies
FREE – Registration optional

Most of the patterns and practices that come out of Redmond A.K.A Microsoft are purely to get a response from attendees of conferences like MIX. The same old drag and drop demo ware is both untestable and unmaintainable. Examples of such demo ware are the CAB application block, SCSF (smart client software factory), ObjectBuilder (a very poor IOC container) and the Entity Framework which many believe to be the catalyst for the ALT.NET movement. The recent ASP.NET MVC framework appears to be an acknowledgement from Microsoft that they want to embrace some of the ALT.NET concepts. The discussion will outline some of the following techniques and frameworks by way of a code review. Attendees are encouraged to participate with questions throughout the duration of the discussion. Some of he concepts and frameworks include: * Test Driven Development (TDD) * Nhibernate (Object Relational Mapper) * Castle Windsor (Inversion Of Control or Dependency Injection) * AOP (Aspect Oriented Programming) * ASP.NET MVC Framework * JQuery (a write less JavaScript library from a very talented team).

8-October-2008 @ 19:00 in Edinburgh (BCS)
The Three Ghosts of Microsoft Security
FREE – Registration Required

Taking efficiency one step further – F# Microsoft Research describes F# as “a scripted/functional/imperative/object-oriented programming language”. Combining all those aspects in one language is certainly not an easy task, but they’ve done a good job of it. F# is interesting both as a language to actually consider for your projects and as a source of features that might make it into the mainstream .NET languages tomorrow. The session uses many examples to give you a good general overview of F#. To complement the introductory session, Oliver is going to show some more advanced samples from his talk “Data Handling in F#” and there will also be room for Q&A as well as discussion.

Further Afield

September:
  SQL Bits III (Hatfield)

October:
  Frank Kerrigan talks about SSIS (Glasgow)

November:
  VBUG Conference (Reading)
  TechEd Developers (Barcelona)
  Developer! Developer! Developer! (Reading)

December:
  Andrew Westgarth on ASP.NET development on IIS7 (Glasgow)

Sponsor’s message

SQL Know How are offering top quality SQL Server training courses at excellent value. Not only is the price great, but by entering the site from the links in this newsletter or on the Scottish Developer’s website you’ll get an additional 5% off the price. Their upcoming courses include the following

Best Practices in Performance and Availability for SQL Server 2005/2008
Kimberly L. Tripp and Paul S. Randal 1st – 3rd September 2008 Hatfield, Hertfordshire

Indexing for Performance in SQL Server 2000/2005/2008
Kimberly L. Tripp and Paul S. Randal 8th – 9th September 2008 Edinburgh

Smart Database Design
Paul Nielsen 22nd – 23rd September 2008 Hatfield, Hertfordshire

Smart Database Design
Paul Nielsen 29th – 30th September 2008 Edinburgh

SQL Server Data Storage Formats: Internals, Performance and Best Practices
Kalen Delaney 3rd November 2008 Harpenden, Hertfordshire

SQL Server Concurrency Control: Locking, Blocking and Row Versioning
Kalen Delaney 4th November 2008 Harpenden, Hertfordshire

SQL Server Data Internals and Tuning
Kalen Delaney 5th – 7th November 2008 Harpenden, Hertfordshire

SQL Bits III Session Voting and Delegate Registration open

SQL Bits are going for a slightly different take on the registration process this time. You vote for the sessions you want to see at the same time as signing up for the conference. This is quite interesting because it means that you are signing up as a delegate without actually knowing what the final agenda will be. It’s quite exciting really!

If you want to vote on the sessions you want to see and sign up for the conference then you can head on over to the SQL Bits website and sign up. Remember to vote for my session while you are there: “Where’s my data? An introduction to Spatial Queries in SQL Server 2008”

Where's My Data? An introduction to Spatial Queries in SQL Server 2008

The slide deck used for my presentations to the

There is also a set of demo code to go along with the slide deck variants.

Further information

The following blog posts may also be useful:

An introduction to mock objects

Colin Mackay presenting Mock Objects (Grok Talk)Sometimes when you are unit testing you might get to a point where you say “That’s too difficult to unit test so I’m just going to leave it”. This is where mock objects come in. Mock objects are stand-in dummy objects that don’t have any functionality behind them, they just return the values to the application that the real object would have returned.

Unit tests are supposed to test isolated bits of code. A single method on a class, or a single public method that calls some private methods on the class. Nothing more than that. Mock objects ensure that if the code you are testing calls something external to the class being tested you don’t have to worry about what the actaul real class does. This has some useful advantages.

When mocks are used the external class is not used, therefore any bugs in the external class do not affect the code being tested. The tests for that other class should pick up the bugs. If the external class is non-deterministic then mock objects can be used to ensure that the unit test received known values repeatedly. It would be insane to provide random values in to a test because it may fail intermittently. If you have a bug that causes the code to fail then knowing the values that cause the failure is necessary. If these are known a new unit test that exercises the failing code can be written so that it can be seen when it is fixed. If it starts to fail again then it will be seen instantly.

There are many unit frameworks out there, for this demo I’m using Rhino Mocks by Ayende Rahien. Other frameworks include NMock2, Easy Mock and Type Mock. Mock object frameworks are not strictly necessary. It is possible to set up a mock object just by implementing the interface of the object to be mocked, however this can take a bit more work.

As a general rule classes that are outside the class under test (CUT) should be mocked. There are some exceptions like extremely simple classes such as data transfer objects, whose sole purpose is to transfer data without any functionality.

If your class interacts with external systems then the access to those external systems can be abstracted out. Then the interaction with the external system can be mocked. In general this kind of abstraction would normally take place anyway when separating the application into its appropriate modules, assemblies, layers or tiers. For example, if your application relies on some configuration setting, a configuration class would be created that knows what should be in the config file for the application, extracts it and transforms it into values the application can use. If the code being tested needs to access a configuration value, a mock configuration object can be supplied and a strictly defined value will be available for the test. This saves tedious setting up of files in advance of the test run. The same can be achieved with database access, web service access and so on. It is also possible to mock out the user interface if the presenter pattern is used.

At the heart of most mock objects is simply that they provide inputs into the code that is being tested.

The most obvious input into a method is the parameters that are passed in. But the fields of a class are also inputs into the method, and calls to methods and properties are inputs into the method. Mock objects ensure that inputs into a method generated by code outwith the class under test are setup specifically by the unit test.

Let’s take the example of a piece of code that calls into a D.A.L (Data Abstraction/Access Layer). This might be mocked for many reasons.

  • The database may not be available because it is yet to be created or the data hasn’t been migrated yet from an older system.
  • The database may be shared among the developers. In this case the state of the database cannot be guaranteed as other developers may be changing it while tests are running.
  • The database may take too long to set up, or the set up process may have some manual steps. In order for unit tests to be used effectively they need to be easy and quick to run. If they are not then their value quickly diminishes as developers will stop running them so frequently.
  • The unit tests are likely to be run in many different environments and the availability or consistency of the database in those environments cannot be guaranteed. Typically each developer will be running the unit tests on their own machine. In a large team there may be dedicated testers who will be running the unit tests. There may be a system such as CruiseControl that will automatically build and run unit tests whenever it detects a change in the source control database.

Mock object frameworks, such as Rhino Mocks, typically work by setting up a series of commands that it expects to be called, then those commands are replayed into the code that is being tested. Once the code under test is completed then the mock framework verifies that the commands were called. If for example an expectation was that method A is called, but wasn’t the Verify process will throw an exception that the unit test framework will use to report a problem. If, on the other hand, the code calls method B, but that wasn’t expected then the mock object framework will throw a slightly different exception to say that B was not expected to be called.

In the demonstration solution there is a somewhat contrived example of how mocks work. The ProductsFactory class needs to call the Dal in order to work out what products should be instantiated. There are two mock objects at work here. One is the Dal itself and the other is the IDataReader. The unit test code shows the mocks being created and the expectations being set up. It then replays the commands and runs the code that is to be tested. Once the code is run it verifies that the methods have been called. In the second test, where multiple products are returned from the factory, the expectations are set up slightly differently. In this case an additional expecation is being set up that demands that the methods are called in a strict order. In the first unit test the methods could have been called in any order, just so long as they were called.

Further reading/watching