SatNav and NavSat

We went from Hull to Harrogate on Sunday. And then, because we wanted to get home, we went from Harrogate to Hull. On the way back the sat. nav. tried to send us a different way from the one it used for the outbound journey.

I hate this. It happens most of the times that I go somewhere and then, surprise, surprise, come home again. It reminds me of one of my favourite railway station jokes:

Customer: "I'd like to buy a return ticket please."
Ticket seller: "Where to?"
Customer: "Back here of course...."

Anyhoo, for any navigation software writers out there, here are a couple of tips for your next version. 

  1. If I try to plot a route that seems to be the direct reverse of the one I've just driven, just reverse the route and give it straight back to me. 
  2. If you're planning a route from A to B, plan it from B to A as well and compare them. Then pick the best one. 

Found the bug..

At risk of receiving further flack for my taste in music (like I care) I present to you a screenshot of my M3U playlist maker in action. I'm not saying it's perfect, but it works, and it does what I want it to (so - OK, it is perfect).

Anyhoo, if you want to see how it works, make it better, colour in all of the letter "o"s in the text, or perhaps even use it, you can find it on GitHub here.

Oh, and the bug from yesterday. Very simple. I'd forgotten to get the text out of the TextBox when forming the for the playlist.

string fullFilename = currentDrive + playlistName.Text + ".M3U";

Turns out the ".Text" part of the statement above is really rather important. Otherwise it just gets the string that describes the TextBox, which doesn't make for a very good name for the file.

Finally, if you've not heard of the "Bonzo Dog Doo-Dah Band" then you really should take a listen.

Bluetooth Manager for Windows 10 Universal Apps now on Nuget

BluetoothManager.PNG

I've been playing with nuget

It's awesome. 

It is fantastically easy to package up an assembly and make it available for just anyone to use in their applications. It is beautifully integrated into Visual Studio and I reckon it is actually easier to download a package from the other side of the world and make it part of your solution than it is to add one that you have written yourself on your own machine. 

To practice I've packaged up my Bluetooth Manager library. This is a little wrapper class that makes it really easy to use Bluetooth on Windows 10 applications. I've not tried it on Windows 10 on Raspberry Pi (but I've tried it on lots of other systems and it works fine). You can find out a bit more about it here.  I use it so that I can print message on my little home made Bluetooth printer, but you can use it anywhere you want to talk over a Bluetooth serial connection. 

Oh, and in case you are wondering why it is version 1.0.1 and not version 1.0.0 I found an interesting quirk in nuget. If your library class doesn't have a public constructor the package will fail to work because Visual Studio will complain that the class is "Inaccessible due to its protection level.". That's what happens when you try to use version 1.0.0

Get get-iplayer

To be brutally honest, I don't think it's been a vintage year for Christmas telly. But there have been one or two things worth seeing. If you want to add a bit more flexibility to your TV viewing experience I can recommend get-iplayer.  I first found out about this nifty command-line powered program in a Raspberry Pi magazine. You can use the  program to download and transcode BBC TV programs from iPlayer on your Pi, but there are also versions for Windows 10 and and Mac. 

It works really well, once you've got your head around the command line interface.

Update: You can get a free copy of that Raspberry Pi magazine here.

Making Plans with Trello

We're in the middle of planning an ambitious holiday, along with a whole bunch of domestic renovations. The idea is to get all the heavy lifting done while we are away, so we can just stroll back into a shiny new bedroom and other bits and bobs.

At least, that's the plan.

I've been using Trello to help manage all the ins and outs. It's free and wonderful. You create a Board (which equates to a task - for example Holiday or Bedroom) and then add Cards to the board. Cards can have content (lists, notes, attachments and links) and you can move cards around the board into different categories, for example "To Do" or "Done". Boards can be shared amongst fellow Trello users (love that phrase - wish I could work mellow or yellow into it too) and the system keeps track of who said or did what. 

There are Trello applications for most devices, but I reckon the Web client is pretty much the best way to use it. Everything syncs up in real time - although this can be embarrassing when you are stood in the pet shop with zero signal trying to get the card that tells you what kind of guinea pig food to buy. 

I really think that Trello is now my go-to place for this kind of thing. Outlook tasks are OK, but not very granular and tricky to share. Trello just seems to work. 

Update: Having spent some time making plans at home before heading to work I find that I've forgotten to put my watch on......

Robs Magic Marker

In December last year we spent a happy four days marking first year coursework. I'd printed out a marking sheet for each student and we sat down with each one and went through their programs filling in the marks. At the end I had around 200 forms that had been filled in during the marking, the next step is to enter these into the assessment system.

This seems like the hard way to do it, and it is. But it is the only way that I can check to make sure that all the grades from the different makers line up and that every student gets appropriate feedback.

Imagine my joy when I discovered that when I created the assignment on the university assessment system I'd accidentally selected the "anonymous marking" option. This means that the submissions on the system are, ahem, anonymous, not in an alphabetic list like the one that I'd carefully created. And there's no way that I can "de-anonymise" them. So now I have to sort all my paper sheets into numeric order and then run the risk that I'd get things mixed up.

Fortunately I'm a programmer and so I reckoned I could fix this. Turns out that "anonymous" means "indexed by student number", which is something I can easily obtain for each student. And the submission system has a "bulk download" option so I can bring down all the submissions and then fiddle with them on my computer.

I've ended up with a little program that does all the heavy lifting for me. It gets all the entries, matches names with numbers, lets me enter comments and generates the marking spreadsheet ready for upload into the system.

It took me a morning to create (which is around the time that it would have taken me to sort the paper copies) and I can use it with the assignments from now on.  Sometimes you do get progress from your mistakes.....

Update: A sharp eyed reader has spotted that my cunning technique makes a bit of a mockery of "anonymous marking" as it turns out I was able to map the submissions onto the students with just a bit of C#. That's true, and any member of staff who wanted to could find out the author of a so-called "anonymous" work. However, we don't use this technique to prevent this kind of bad thing. Instead we use it to prevent "unconscious bias".

I was not a fan of anonymity when it was introduced, I saw it as a criticism that implied I might be inclined to victimize particular students if I knew who they were. However, it is not like that at all. If I know Fred, and I'm marking Fred's work, then I'm going to bring to the process all my knowledge of what Fred is like. If the mark I come up with is a bit low, but I happen to think that Fred is quite good, I might inflate it to compensate for this. This is unfair. Fred should get the mark the work is worth.

If all I see is the student number when I'm marking it is much less likely that I'll know  that it is Fred who did the work, and the mark I come up with will be impartial. 

In this case we mark the work in front of the student and so the question of anonymity does not arise. The student is in a position to discuss the mark that they have been awarded to make sure that justice is done, and so I don't see a fairness problem in this situation. But I'd never use it to break "proper" anonymity as this actually makes my job more difficult. When I'm marking exam scripts I much prefer not to know who wrote them, this makes it easier to just focus on what is in front of me. 

Windows Phone, Wedding Lights and Bluetooth

Windows Phone connected Wedding Lights. Eight synchronized lights which can be controlled over Bluetooth. Each light contains an Arduino processor and a 16 NeoPixel ring.

I've finally finished it. I was going to write an article about my Windows Phone Controlled Wedding Lights. But instead I thought I'd do something different. So I fired up Adobe Premier and I made a video about them instead. It only lasts a couple of minutes, but boy was it complicated to make. Anyhoo, feel free to take a look and let me know what you think.

I've done something else I've not done before (and I feel a bit guilty about this one). I've put the Bluetooth code for Windows Phone 8.1 and Windows 8.1 up on Codeplex. I'm ashamed to admit that this is the first code that I've ever posted there. I really should have been posting stuff up there earlier. I'm determined to post more stuff as I come up with it.  

You can find a sample project (my Bluetooth Printer) and the BluetoothManager class that I used to communicate with the embedded Bluetooth controller. There are also details of how to configure the Bluetooth device and send and receive data. 

Improving your University Timetable

image

This year the university is making available an electronic version of the timetable for all staff and students. It is best described as “a work in progress” because that is what it is. Lots of wonderful things are promised for the future, including Outlook integration and proper, personalised timetables. But for now it is a bit unwieldy to use.

Which is not good enough for Tom, one of our students, who has built a Python program that reads the data and then lets you display your timetable and do all the things that you’d really want to do with it. You can find out about it here.

Incidentally, I found his blog post via http://hullcompsciblogs.com/

This has a bunch of good student blogs, and if you are from Hull and starting blogging you can ask them to add yours to the syndication.

Adobe Creative Cloud for Academics

image

If you are thinking of spending some money on a new camera, then welcome to the club. I’m always thinking of spending some money on a new camera. But before you buy a camera you might want to think about investing in some software to make the best of the camera you already have.

I’m a big fan of Photoshop Lightroom as a way of getting pictures out of the camera, tweaking them a bit and then managing where they are stored. It also has very good integration with Photoshop itself, along with lots of other plugins that can do lovely things with your pictures (for example Photomatix Pro for High Dynamic Range work).

Some time ago (in fact around a month and a day before a new version came out) I bought a copy of Photoshop. I’m proud to be able to say that I know what nearly a quarter of the buttons do now. But I really want the newest version, because that works best with the RAW files (images direct from the sensor) that my cameras produce.

Now you can’t really buy Photoshop any more. Instead you rent it by the month. Up until now I’ve not been that keen on that model, I much prefer owning things. However, in a world where (no – this is not  a movie trailer) new versions of cameras and software come out at least once a year, renting makes quite good sense. Particularly as they have a deal at the moment where students and academics can get pretty much all of Adobe software for around fifteen pounds a month by signing up for a Creative Cloud subscription.

People spend more than that on cigarettes, and for your money you get access to the latest versions of Photoshop, Illustrator, Acrobat Pro, Dreamweaver and lots of other things that would probably be useful if I knew what they did. The offer is open until the 27th of October. Well worth a look.

Heading for London

DSC_0196.jpg

Ian Livingstone playing the game that got us to London. He reckons we should set it in space, and I think he might just be onto something….

To start with, a bit of history. What seems like ages ago David, Simon, Lewis, David and me took part in Global Game Jam Hull. And we built a game. Then Microsoft offered a prize for the best Windows 8 game that came out of the Game Jam and made it into Windows Marketplace. So David and Simon took the game engine, made it marketplace ready and shipped it. And Heartotron won. At the time we weren’t sure just what we had won, but part of the prize turned out to be a trip to London to tour a game development studio and meet up with some of folks who made the game industry what it is. And so we found ourselves on a train at 8:00 am in the morning, speeding through the sunshine and looking forward to an interesting day.

Which we got in spades. It was great. First up was a look around Lift London, a shiny new Microsoft game studio with a focus on making games the Indy way. No big (or at least huge) teams, flexibility, appropriate technology and total commitment to the product are the order of the day. Lift London also sees incubating fledgling games developers such as Dlala as part of their remit, which is very interesting.

With people on the team who can say things like “..and then we went on to write Banjo-Kazooie…” or “..and then we did Singstar..” alongside folks who have grown up writing and pitching games any way they can I reckon we can look forward to some fun stuff in the future.

We got to look at some work in progress, which was fascinating for me. The transition from ideas to drawings to models on the screen was intriguing.. I get very jealous of people who can draw, and loved seeing these people in action, and how they can turn out lovely looking artwork with just a flourish of their Wacom pens. Most impressive.

Then it was time to move on to Modern Jago, a pop up venue in Shoreditch, for workshop with the gaming legends Ian Livingstone (Vice chairman of Ukie, Games Workshop founder, president at Eidos), Andy Payne (chairman of UKIE and CEO of Mastertronic) and Philip Oliver (TIGA board member and CEO of Blitz Games Studios).

Each had plenty of time to speak and plenty to say. Some things that I took away, in bullet form:

  • There has never been a better time to be writing games. Cheap tools and an easy path to market give you amazing potential.
  • There has never been a more competitive time to be writing games. The statement above is true for everybody.
  • Put your monetisation in at the start. If you are going to sell your game, be up front about that (although recognise that very few people will part with cash to buy it). If you have a pay to play model, put that in the central game mechanic. It is impossible to add it later.
  • Use metrics and feedback. Track downloads, watch for reviews and scores, use telemetry to be able to tell how far people get through the game, how long they play for, and when they give up. Phase your releases so that you get feedback from one part of the world (for some reason Canada and New Zealand are popular for this) before you go global.
  • Look for the “soft” market. A big splash in a small pond with a future has more potential than trying to make an impression in a huge marketplace with scant resources.
  • Get a following. Napoleon reckoned that with 1,000 followers you have an army of your own. He wasn’t on Twitter, but you can be. Give opinions and help to people out there and build a following of folks who like you. A crowd who like what you do and want to see what you do next are great to have around. Be loyal to them and they will replay you by supporting what you do.
  • Get a job. You might plan to be a lone gunfighter releasing your fantastic stuff for the world to marvel at, but it much easier to do this with a roof over your head and a full stomach. One of the things you need to succeed is luck (everyone said this). Napoleon (him again) reckoned that he always preferred his lucky generals to his clever ones. If the luck isn’t there, and it may not be, you still need to eat. Make time for your development and go at it full tilt, but there’s nothing wrong with having a backup plan.
  • Get some “skin in the game”. This kind of goes against the above but I still feel it is something to think about. If you feel that the stars are aligning and that this is “the one” then feel free to go for it every way you can. Living in a van for six months while you raise funds and build your product base might be the thing you have to do to achieve success. Worst case maybe your boss (see above) will have you back – particularly if you part on good terms.
  • The three most important aspects of a game are playability, playability and playability. But graphics and high production values are a way to distinguish your product and get people in to discover just how good your game is. But this, of course, costs money and time. As does buying a place in the charts that gets you noticed, something else which might be a necessity.
  • Put yourself out there. I was particularly pleased to hear this one, as it chimes with what I’ve thought for years. You need to be able to do the “front of house” stuff. This is really bad news for software developers, who tend not to be the most extrovert folks, but it is a necessary skill. Get yourself in front of people. Practise doing stand-up, meeting and greeting and networking. If you don’t have these skills other people will not compensate for your lack of them. They’ll just find someone else more interesting to talk to. Ian Livingstone himself said that this is one lesson he took a long time to learn. The great thing about computer folks is that they are used to picking up new tools and APIs. Treat this as just another thing you have to learn and get good at.
  • Make a good story. The press is interested in you, but only if you are interesting to them. “I’ve made a fishing game” is not useful to them. But “I’ve made a fishing game that I wrote underwater whilst wrestling a Great White Shark on the Barrier Reef” is. Make sure that you have a good tale to tell. Use your followers (see above) to big you up and help you get noticed.
  • If you are working as a team, set some ground rules (another favourite of mine). Have a plan for what to do if your lead developer gets a “proper” job and stops writing your game engine. Have a protocol and a policy for re-negotiating your arrangements when these events happen.
  • You don’t need to be the best, or cleverest. Just there are the right time, in the right place, with the right thing. Try lots of things, in lots of places as frequently as you can. Don’t expect success to happen the first, second or perhaps even the third time. But as soon as you get a sniff of something that seems to be working, follow it, develop it and ride it, and you might be the next big thing.

All in all a fantastic day out. Thanks to Microsoft for setting it up.

Control the Horizontal and the Vertical

Flying

I got an email today from a student looking for an interpolation technique to create smooth curves from a series of points. The reason he was after this was that he was making a game. His problem was that the technique looked a bit complicated and hard to implement on the target platform.

My advice in these situations is always “don’t sweat the complexity”. The simplest way to do this kind of thing is as a series of straight line segments. These are easy and quick to implement and should let you get something working really quickly. If the gameplay works OK, just stick with that technique and work with it. Remember that the player enjoying the game doesn’t know that you originally wanted to add curves. Only put the curves in if your game needs it.

If it turns out that lines would not be appropriate for your game theme, just change the game to one where lines do make sense. Remember that games are like “The Twilight Zone”. You control the horizontal and the vertical. The player is entering your universe, so you can define it as you like. Straight lines or curves, it’s all up to you. But start simple.

Bye Bye Live Mesh

Bye Bye Live Mesh

Microsoft have released the latest version of Windows Essentials. When you start to install it you get the dialog above. The title “One Last Thing” is interesting, it is a kind of “By the by, we are about to take something away that could break your way of working” statement. I’m pressing Cancel just at the moment.

The writing has been on the wall for Live Mesh for a while. Pretty much ever since SkyDrive started doing the same kind of thing, i.e. let you transparently share files around your computers and back them up in the cloud. I’ve been a fan of this ability for ages. If you take any (or indeed all) of my machines and throw them in the river I won’t necessarily thank you, but I can take such vandalism in my stride because I use Live Mesh to sync all my work. Getting a new machine is quite relaxing for me as I just have to introduce it to Live Mesh and all my data appears as though by magic. The only restriction here is that Live Mesh limits you to 4G of file space in the cloud, but since we are talking about working data here (all the other important stuff is back home spread over a bunch of disks) 4G is fine.

It’s unfortunate that Live Mesh is going. The SkyDrive replacement works the same way, although it only synchronises via the cloud apparently. With Live Mesh two machines would directly exchange files if they found themselves on the same network. Live Mesh also provides a Remote Desktop feature which SkyDrive doesn’t. There have been a few complaints on the interwebs about the demise of Live Mesh. I think this is really a bit unfair. After all, it’s not as if it was a service that anyone has paid for. If someone gave you an apple pie every day for a while and then stopped it would be rather unfair to complain. Particularly if they then offered you a rhubarb crumble instead. If you want a premium service you can go for DropBox, which is excellent but not as cheap as I would like.

As for me, I’m presently copying my files from my Live Mesh folders into SkyDrive shared ones and I’ll press OK as soon as I’ve got all the files in place.

Event Today: Real Life Software Engineering

image

Anyone at Hull who fancies an hour’s break from coursework and revision today can pop along to a lunchtime event run by Robert Hogg and Steve Spencer of Black Marble. Rob and Steve are Microsoft MVPs (but none the worse for that) who have a lot (and I mean a lot) of experience of writing software for customers. If you want to hear some “Tales from Real Life” then you should go along to LTA in the Robert Blackburn Building at 1:15 pm today.

This event would be particularly useful for any First or Second Year students who want to learn more about the software development process.

I’ll be there…. taking notes….

The iTunes Experience

IMG_0984-Edit.jpg

Apple make carefully designed and beautifully presented products that amaze and delight their owners. They also make iTunes. Which is amazing, but not in any good way.

Yesterday number one dad got a new iPad. I heard the news with dread. Because it meant that I’d be the chap installing it. In theory this is easy, just back up the first iPad and then restore the backup to the new iPad. A doddle. Except….

The new iPad refused to talk to the version of iTunes on dad’s laptop. So I fired up the Apple Upgrade Manger. Which found an upgrade for itself. Which failed. Eventually I figured out that it was trying (and failing) to uninstall the old version. Nothing I could do would persuade the darned thing to get out of the way so that I could upgrade iTunes. Time for Plan B. Install a new version of iTunes on the desktop and use that to do the upgrade. Installation went well, tried to sign into iTunes and authorize the computer. Turns out that iTunes is incapable of remembering dad’s password for more than ten minutes. Go through the password reset. Authorize the computer. Plug in the old iPad to perform the backup. Fail. The iPad will only talk to the iTunes library on the broken laptop. One wrong press now and I wipe the iPad by restoring an empty library onto it. At least you get the warning now. I’ve known people wipe their iPods when they get a new computer. Why Apple persist in such a stupid library arrangement in this cloud connected world is beyond me. Anyway, no dice.

So decide to just register the new iPad so that we can do something with it. Find that that iTunes has forgotten dad’s password again. Get another password.  Finally get the registration completed and start restoring applications onto the new iPad. Three hours in and we now have something working.

I’m going to have to back up and rebuild dad’s laptop so that I can do a clean install of this idiotic program. I looked up the procedure to back up the iTunes library. It seems that there are two ways you can do this. Copy the files and hope or buy a program to help you do this.

I’ve thought for a while that Apple are probably quite happy to give users a horrible experience if they use iTunes on a PC. I’ve found PC installations to be very fragile and completely impossible to get off a machine. There’s no way I’d install iTunes on any of my PCs, in fact I keep an “emergency Mac” around with iTunes on it that I use to keep my Apple devices up to date. I’ve found the Mac version of iTunes to be a lot better behaved, thank goodness.

One of the great things about iOS 5 is that you can do pretty much everything without using iTunes. As for me, I’m off for a lie down….

Software Updates at the Humber Bridge

01monitor

All my own work

One thing which I’m very proud of is that I helped to write the software that manages the toll data from the Humber Bridge. Ian and I wrote the “Instation and Control Room Mimic” system which tracks the traffic over the bridge, makes sure that vehicles are registered correctly by the toll booth operators and totalises all the takings. We wrote the programs around 12 years ago which means that if my code was a child it would now be starting secondary school. Scary stuff. (and probably due for an update)

Some time ago the wonderful Verity Stob introduced me to Meir M "Manny" Lehman's Software Uncertainty Principle. Put simply, it states that at some point in the lifetime of a project certain assumptions that were baked into the solution when it was first built become wrong. Today that happened to me. One of the assumptions that I’d made in the design was that it would never be free to cross the bridge. The program was built to validate the price entry and reject any values which were less than or equal to zero. And then at the weekend the Humber Bridge Tolls were revised downwards (a very nice thing to happen) and it became free for a motorbike to cross the bridge. Thing is, my software didn’t allow for this. And so, for the last day or so the price of a motorbike crossing the bridge has been recorded as a single penny (although of course the money wasn’t collected)

Today I drove round to the Bridge Control Room and did a code update of the bridge software, effectively changing a >0 to a >=0 and now the prices can be set correctly.

Best Programming Language?

IMG_7331-Edit.jpg

There’s a program in the App Store called “Best Camera”. It takes as its starting point the idea that “The Best Camera you’ve got is the one that you have with you at the time”. The application then goes on to provide all kinds of useful tools that make the iPhone camera as good as possible.

I was reminded of this when there was a tiny bit of debate on my post about the CodeAcademy site, which teaches JavaScript. Now, JavaScript is not a great language, but it works and can be used to create useful stuff. So it is automatically a candidate for “Best Language”. In my opinion, the Best Language is the one that you are using at the moment. I base this on “Robs Rules for Programming Languages”:

  1. You can write great code in any language.
  2. You can write horrible code in any language.
  3. The user does not care what language you used to write the program they are using. The user only cares that it works and does what they want. And that they can afford it.

I’ve written programs in loads of languages. At the moment my personal favourite language is C#, but I have really fond memories of writing embedded C, since in that I could do anything I wanted and I could build all the underlying bits myself from scratch.

This is usually the point that people say things like “But blah doesn’t have blah.” or “Blah programs are really hard to use because the debugging support sucks.” So what. This brings me to the Rob’s Other Rule

  1. Having a nice place to work is much more important than the programming language you are using.

If the language you are using doesn’t have a feature that you need, find a way of programming around it. I’ve written lots of object oriented software in C. C doesn’t support objects, but I arranged the code so that it looked like it did and then programmed by “object rules”.

If the development/debugging support is horrible, wrap something around your program to make it easy to work with. I’ve built emulations of LCD panels and even lasers to avoid having to debug my programs on the real hardware. I’ve written code to make ten thousand customers from nothing, to save me having to type things in by hand. And I’ve added cheat buttons to games so that I can skip levels and inflate my scores and avoid having to play the game all the way through so that I can debug the last bits. 

Remember, when you are writing a program you don’t just control what the code does, you also control the environment the code sits in. Bending this to make things easier is something that will pay off tenfold. Can’t debug your program without a network connection? So what. Fake the web request responses so that you can feed the answers back yourself. This also makes test driven development much easier.

Of course, given the choice, you should pick the most appropriate language for the task. Give me an AI problem and I’ll be looking hard at what Prolog (or perhaps F#) can do for me. But for me programming is not about the language, it is about the problem solving, and that means a programmer should be able to turn their hand to whatever the occasion demands. Even if it is JavaScript.

High Dynamic Range Photography

hat1_2_3_4.jpg

I’ve been playing with High Dynamic Range photography. This is where you take a bunch of pictures of a scene at different exposures and then make a single shot which has a greater dynamic range. The picture above is just a snap I took last year. I didn’t have three different exposures, so I did some fiddling with the RAW file to fake the different exposure levels. I then used program called PhotoMatix to combine them and then tone map to get the grungy effect that you see above. If you look closely at the picture you’ll see that it has a Photomatix watermark which means I’ve not paid for the software yet. However, I’m very tempted to, as the results seem quite nice to me. Not particularly photorealistic in this shot, but definitely interesting.

If you are into photography you might find it fun to have a go. The only thing you really need is a tripod to keep your camera steady between the different exposures.

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.

Lightroom Rocks

P1030212.jpg

Last week I sold a MacBook and bought a camera. And got a free copy of Adobe Lightroom. And it is wonderful. Up until now I’ve been muddling through managing my many photographs, keeping them in folders and using Windows explorer to find and look after them. This mostly works, but it is a bit of a pain.

Lightroom provides a really good way to find and then fix your pictures. It works really well with raw files and the noise reduction abilities are awesome. It also has some rather cool picture styles built in. And it will upload directly to Facebook, Flickr and SmugMug, among other places. It also takes care of the importing and has very good tagging and metadata management.

If you are serious about your photography, then I think you should take a good look at it. The trial download runs for 30 days or so, by which time you should be hooked.