Updates from QA Training

Introduction to Programming

I recently volunteered to give a short presentation at our brand spanking new state of the art training centre at International House in London. The presentation was part of a series of career seminars that QA are running. The topic was “an Introduction to Programming”.

Daniel Ives | 7 February 2013

I recently volunteered to give a short presentation at our brand spanking new state of the art training centre at International House in London. The presentation was part of a series of career seminars that QA are running. The topic was “an Introduction to Programming”.

If you're just here for the demos and slides from my presentation, you can get them from here by the way.

An Introduction to Programming

Try googling it. Go on! Come back when you're done. About the best hit I got was the one from wikiversity, spouting the same old stuff I was taught 20[-odd] years ago. I thought to myself, "I'm talking to people who are already in the industry and whether they've cut code in the past or not, they probably appreciate that it's us monkeys who keep the wheels of commerce turning". So I toyed with the brief a bit and came up with the idea of showing up just how far programming languages have come since I was a cub, especially with reference to some of the wonderful stuff that has come along with Visual Studio 2012 and .NET 4.5.

I wanted to demonstrate how much more productive and agile we can be in this advanced modern world we live in.


So what are the challenges facing programmers today? The way I see it, in terms of what I can manage to talk about in half an hour, is as follows:

 1. We needed it yesterday! We need to be able to cut code quicker than ever before
 2. Proof that it works. With additional code to prove that the actual code works (tests)
 3. Ease of maintenance. It needs to be elegant and clear so that it's easier to maintain
 4. More Cores. We need to be able to exploit the fact that our computers have multiple processors that can do   things simultaneously. Now, I don't know about you dear reader, but I'm not clever enough to work that kind of stuff out!
 5. Software Configuration Management / Application Lifecycle Management. Managing successful software projects is about managing the application lifecycle. But what about geographically dispersed teams who are on different networks? How are they going to check code in and out?

Now that last bullet point is important but I didn't feel there was going to be enough time to talk about it. Suffice to say I wanted to introduce people to visual studio , which is Microsoft's cloud-based ALM solution. It's currently free for a limited number of team members but in all likelihood won't continue to be.


Seeing as it's here and it's free, I downloaded Visual Studio 2012 Express for Desktop for my demos, which are all admittedly Console applications because I didn't want UI stuff to get in the way of my beautiful code.

I took the decision to run all my demos for the seminar in VB for aesthetic reasons - for non-coders, it's easier to see where stuff begins and ends. However, I also wrote all of the code for the demos in C# for completeness.

Yesterday and Proof (SomeLibrary and SomeTests)

The first thing I wanted to demonstrate was ease and speed of development, in conjunction with tests that pass. People who have been around code for a while will already be familiar withIntellisenseor code-completion features but I wanted to incorporate that anyway but what I really wanted to highlight was the generate from usage feature (or "ctrl + dot fix-it" as I like to call it). Also it never ceases to amaze me how many people aren't familiar with Code Snippets!

My starting point is an empty class library and an empty unit test project. The unit test project already has a reference to the class library but that's it.

I write a test method. Actually, that's not true; by typing "testm" and pressing I use a code snippet which works in both VB and C# to generate a test method which I call "TestHelloDaniel".

I declare and instantiate a variable called hc of type HelloClass. I get squiggly lines everywhere - there's no such thing as a HelloClass. So I use ctrl + dot to pull up the fix-it menu and tell VS to create me a new type over in the class library.

Then I set the Name property of hc to "Daniel". More squigglies. Fix-it again to create the property stub over in HelloClass.

Next I declare a string variable called "expected" that I give a value of "Hello, Daniel!".

Then I declare another string variable called actual that I give the result of calling hc's SayHello method. Squiggly lines and fix-it again.

I note that I haven't even visited the class library yet.

Now for the proof that it works.

The next line of code in my test method Asserts that my expected string and my actual string AreEqual. I right-click and tell VS to Run Tests and needless to say, the test fails. I need to make it pass. Selecting the SayHello method, I hit F12 to go to the definition and we can see that when VS created the method for me, it put in some functionality to raise an error (the code wouldn't have compiled otherwise!). I change the code to return "Hello, Daniel!". Yes I am cheating. Back to the test and re-run it; passes!

Now I create another test method called TestHelloNotDaniel and copy and paste the body of the previous test, however I change it so that it sets the Name to "Bradley" and expects "Hello, Bradley!". Test fails.

Back to SayHello and change it so that it returns "Hello, {0}!", where {0} gets replaced by the value of the Name property. Pass. Beautiful!

Elegance and readability (ReadableCode)

Not going to build any code here, just show it off. I have a class called NotSoReadable that goes through a list of people looking for those with 6 character first names and then sorts them based on their last names. In order to perform the sort, I had to create another class that tells .NET how to sort stuff.

Then I look at a class called PrettyDarnReadable. Elegant and maintainable (and actually took mere moments to write)!

More cores (ParallelCode)

Since .NET 4 came along, we've had the Parallel Extensions to .NET and I really wanted to highlight the ease with which they can help us to write parallel code. If you think about the challenges involved with performing operations in parallel - breaking a set of data up into chunks, passing those data to x number of processors and then aggregating the results back at the end, all in a safe way - it isn't a straightforward proposition.

So I have some code that benchmarks a fairly processor-intensive operation -discovering prime numbers in a range of values.

It uses a LINQ expression to look through a given Range of integers and calls my IsPrime method on each number. I'm passing it several million numbers starting at 2 (this first Prime) and seeing how long it takes.

I have two different versions of the method that counts the primes - one that does it in serial and one that does it in parallel. I benchmark both and print out the timings to the console, and finally the ratio of the serial version's time to the parallel version's. The parallel version will consistently run approximately x times quicker, where x is the number of processors available on the machine.

The difference between the two methods? A simple call to AsParallel when processing the range.


Daniel Ives

Daniel Ives

Principal Technologist - AWS

Daniel joined QA in 2006, having previously worked as a developer trainer on the Microsoft stack. He is an Authorized Amazon Instructor and holds all 9 of the current AWS certifications. As a Principal Technologist, Daniel focuses on creating and delivering courses about cloud services, service-oriented architectures, data engineering and enterprise application integration. Areas of expertise: Amazon Web Services, C#, .NET and agile development. His areas of interest include all of the above, plus Google Cloud Platform, Microsoft Azure, Python, sailing, skiing and cycling, although not necessarily in that order or at the same time.
Talk to our learning experts

Talk to our team of learning experts

Every business has different learning needs. QA has over 30 years of experience in combining the highest quality training with the most comprehensive range of learning services, ensuring the very best fit for your organisation.

Get in touch with our learning experts to talk about how we can help.