Thought for the Dazed

I've had to give up that Distance Learning course as I was having trouble seeing the teacher.

Flickr
www.flickr.com
RobMiles' items Go to RobMiles' photostream
Twitter
C# Yellow Book

Search entire site
Monday
Feb062012

Made in Hull

imageimageimageimage

imageimageimageimage

imageimageimageimage

imageimageimageimage

imageimageimageimage

imageimageimageimage

These are some of the games and applications that students and staff at Hull have made over the last few months. Some of them are implementations of games produced at Three Thing Game and Evil Squash.

To take a more detailed look, just click on the icon to be magically transported into Windows Marketplace.

Sunday
Feb052012

Chris Wooding and the Ketty Jay

image

If you are looking for a bit of escapist Science Fiction/Fantasy stuff then take a look at Chris Wooding. I’ve just read the first of his Ketty Jay series and it is a rollicking good fun. If you enjoy Harry Harrison, Blake's Seven, Firefly kind of stuff then you’ll like this. A well written take on the “ship of misfits freebooting around falling into danger and adventure” kind of thing with plenty of action and a quite a few laughs.

Saturday
Feb042012

Cameras and Lumps

IMG_0104.jpg

Here’s a tip. If you are buying a digital camera which is not completely new, point it at a white piece of paper and take a photo. Then look at the result. The photograph will show you if there is any dirt on the sensor or the lens.

I didn’t do this today, which is why I had to take the camera back to the shop……..

Friday
Feb032012

Tutorials, Objects and References

Snowy Library.jpg

We are doing objects and references in the First Year tutorial today. Great fun. Well, at least I thought so. I asked the class whether big objects in memory have larger references than small ones. They don’t – the size of the tag is always the same – no matter what it is connected to. I went on to explain that a reference tag contains a bunch of information about the thing it is referring to, including the type that it has, for example string, BankAccount, AlienSprite or whatever class you have created.

Then someone asked a great question: “What happens if the type has a very long name? Does the reference tag get bigger?”. Aha! What a great question. The answer is no. This is because the type of a reference is managed in terms of a reference from the tag to the type object that describes that reference. In other words, a reference to a BankAccount will also contain a reference to an object that describes the BankAccount class.

I was very pleased with this question, because it let me start to explain how, by using objects, you can build up structures of data that are genuinely useful. I’ve been explaining structures and objects all week and several times I’ve had the sensible question “What’s the point of objects and references? They just seem to make life harder for us.”  This little allows me to show how easy it is to use references to allow the system running the program to track and mange the type of the objects it is using.

I reckon that a good tutorial is when the students learn something. A great tutorial is when the tutor learns something as well. I’ve now got a lovely new example to use next year…

Thursday
Feb022012

When is a number not a number?

IMG_5863.jpg

Pop quiz. What would the following C# code do?

float x = 1;
float y = 0;
float result = x / y;
Console.WriteLine(result);
  1. Fail to compile.
  2. Throw an overflow exception.
  3. Print “Infinity”
  4. Cause the universe to explode.

Here’s the thing, the code prints the word “Infinity”. Dividing any floating point variable by zero gives a special result which is encoded into the floating point variable range as “Infinity”. Now what about this?

float y = 0;
float result = y / y;
Console.WriteLine(result);

This time we get the message “NaN”, which means “Not a Number”. Dividing zero by zero does not give a number as a result. There just isn’t a value for this quantity. The value is not as big as as infinity or as small as zero its just, well, not a number. You get the same non-result if you divide infinity by infinity.

The C# runtimes are based on .NET which uses an IEEE (Institute of Electrical Electronics Engineers) standard that contains representations for negative infinity, positive infinity and “not a number”. Calculations in a C# program will produce these results when given dodgy values to work on. This is very important. You might think if you do silly things with numbers in your program you are going to get an exception thrown. Like this would.

int i = 1;
int j = 0;
int Result = i / j;
Console.WriteLine(Result);

Run this code and it throws a “Divide by Zero” exception when it tries to, er, divide by zero. But this does not happen with floating point calculations. This is probably because the range of values for the int type does not include one to represent “infinity”.

The bottom line here is that if you do sums involving floating point values you can’t expect exceptions to be thrown if the calculations go wrong. The good news is that you can use methods provided by the float type to test results of calculations:

if (float.IsNaN(fresult))
    Console.WriteLine("Welcome to the Twilight Zone");

This prints the enigmatic message if the value in fresult is not a number.