Thursday, October 29, 2009

Unit testing and code conversion

Python

I've just done a little exercise in code conversion from Python to C# and the icing on the cake were two unit tests written in the Python code that confirmed that my code had been converted correctly.

I know nothing about Python so it was lucky that this code was about 10 functions and only a few pages long. For the bits of code (mostly syntax) that weren't obvious I found an online quick reference to Python and used that to search for the unusual keywords and work out what they did.

The code conversion I did inline by copy pasting the Python code into a C# class in a Visual Studio project and then converting each line into C# leaving the variable names and code structure intact as much as possible. I had the original Python file open in Notepad++ on a second monitor as a reference.

At the bottom of the Python file were a couple of unit tests with expected results and input parameters. I rewrote those unit tests in Visual Studio's Unit Tester and used the same inputs and expected outputs and they ran successfully. As a result of those unit tests that was probably the most successful code conversion that I have ever done and a very productive one as well.

Quicken Deluxe 2010 spams your desktop

Quicken

I just bought and installed Intuit Quicken Deluxe 2010 from their site for $59. The first thing to disappoint me was the fact that there was nowhere during the purchasing procedure to enter my coupon code and get a discount. I was in too much of a hurry to bother with hunting around for how to do this so they got to keep my $10 discount.

The second thing that really annoyed me was that the installation procedure dumped three spam links on my desktop for other products that they sell.

I haven't even run their software yet and they've had two strikes that annoyed me sufficiently to blog negatively about them. It might be great software but so far it looks like a shady company using back-alley tactics.

Edit on 11/30/2009: That link above (Intuit Quicken Deluxe 2010) has the software priced at $54.99 so you save a through dollars through NewEgg. I didn't know about it at the time so paid the full $59 to Intuit.

Tuesday, October 27, 2009

Network Saturation Finally




I have finally achieved my goal of network saturation on my home network.
As with most people, I have a small off-the-shelf router that does the standard 100 Mbs. Most of the computers in my house are hardwired because the wireless signal is slower and weaker in the far corners of the house and also because we bought a spec home that had all the rooms pre-wired with Ethernet.
In the past, when I've been copying files from one computer to another and I've looked at the transfer rate over the network I've been disappointed that only 40% to 60% of the available bandwidth was being utilized. The hardware supports 100 MBS so why isn't it transferring data at that rate dammit?
The reason is because of the slowest component in the chain which has always been the hard disk speed. Well not anymore. I've just bought myself a new computer and with this I got a Patriot Torqx PFZ128GS25SSDR 2.5" Internal Solid state disk (SSD) which promises 260 MBS read and 160 MBS write.
The computer that I was copying from had the data sitting on a Seagate Barracuda LP 1.5TB 3.5" SATA 3.0Gb/s Hard Drive -Bare Drive. I don't know what the read speed of that is (yet - I'll come back and update this later) but I'm guessing that it's over 100 MBS or I wouldn't have achieved network saturation.
Is it going to be worth getting a faster router? Not yet I think. The times I'll be copying between computers with fast hard drives is probably going to be rare. I'll wait until my internet connection exceeds 100 MBS. My prediction is that will happen in about 7 years time.

DVDBurn.exe in Server 2003

I've just been battling for the last 30 minutes to try and burn an ISO as an image to a DVD. I have a version of Nero Burn and tried to line up the planets with this bit of not-so-great software and ended up creating a data DVD with the ISO as the single file on this DVD. I took a second attempt with Nero but just couldn't find the option to create it as an image.

Did I mention that I was burning this DVD image from Windows Server 2003?

I stumbled across this little gem of a utility that I must have installed on this server with the Resource Kit Tools. It's called dvdburn.exe and has a younger brother called cdburn.exe.

DVDBurn.exe takes 3 parameters:

dvdburn <drive> <image> [/Erase]

Worked like a charm:

C:\Software>dvdburn d: en_windows_7_ultimate_x64_dvd.iso
Media type: DVD-R
Preparing media...
Error setting timestamp; this error will be ignored, some drives can work without this
- 100.0% done
Finished Writing
Waiting for drive to finalize disc (this may take up to 30 minutes).............

Success: Finalizing media took 10 seconds
Burn successful!

Saturday, October 24, 2009

10GUI

The genius behind NinjaCamp recently sent me a link to 10/GUI. I try and follow the zero Inbox policy but for him I made an exception and allowed this email to languish in my Inbox so that I could take a relaxed 10 minutes out of the weekend to watch what he was so abuzz about. I have to agree with him, this is an amazing concept and I want one now.

From what I can work out this is as simple as a touch pad with up to 10 points that are recognized by it. Instead of the mouse you have a surface lying in front of the keyboard that will understand all your fingers including the motions now recognized by hand held devices such as the Android and iPhone.

The only thing missing, and I think this is just a matter of time, is for a keyboard to appear on there. If there were keys that could quickly inflate themselves on this device when you needed a keyboard and then disappear when you wanted the touch pad that would be the ultimate human interface.

Friday, October 23, 2009

C# Math.Round Banker's or Mathematical Method

I wasn't even aware that there was a banker's method to rounding numbers until I came across what I though was a bug in the Math.Round() function in the .NET library today.

If you call this function:

double x = Math.Round(.005, 2);

then you will discover that x is set to zero. If you call this:

double x = Math.Round(.0051, 2);

then x will be set to 0.01.

I was always taught that you round up from 5. This is still correct and is known as the mathematical method of rounding. However I have recently learned that there's another method and if the least-significant-digit is 5 and you're using the banker's method then you round down instead of up. This is the method that Math.Round() uses by default.

If you want to use the expected mathematical method for the round function then you need to add another parameter to the overloaded Round() function which specifies how you want it to handle midpoint rounding. AwayFromZero will do the trick:

double x = Math.Round(.005, 2, MidpointRounding.AwayFromZero);

This will cause x to be set to .001 as you would expect. The other value defined in the MidpointRounding enum is ToEven and this will do the default of round the midpoint down to zero.

Mystery solved!

1 Sep 2010, just discovered this:

Banker's Rounding

When you add rounded values together, always rounding .5 in the same direction results in a bias that grows with the more numbers you add together. One way to minimize the bias is with banker's rounding.

Banker's rounding rounds .5 up sometimes and down sometimes. The convention is to round to the nearest even number, so that both 1.5 and 2.5 round to 2, and 3.5 and 4.5 both round to 4. Banker's rounding is symmetric.

Predictably Irrational

I've just finished reading Predictably Irrational by Dan Ariely. This is a great book that applies to everyone and should be required reading before you leave school. Everyone is guilty of being irrational in their decisions and some of us continue to do it everyday even though we know that it's stupid and, yes, irrational.

One of the stories that I loved was the pen and the suit comparison. If you were buying a pen and saw it on sale for $30 and knew that you could buy it across town for $23 then you'd likely jump in your car, make the drive, and save yourself that $7. However, if you were buying a suit for $400 and the same applied you're highly unlikely to make the same trip to buy the suit for $393. Why would you do that.

One of my favorite experiments that they did was that with Lindt Truffles and Hershey's Kisses. They priced the Truffles and Kisses at 15 and 1 cents respectfully and found that 73% of customers chose the Truffles. They were willing to pay that extra 14 cents to get a superior product. However, when the dropped the price by 1 cent and made the Kisses free then suddenly everything reversed and 69% of customers took the free Kiss over the Truffle even though the price differential of 14 cents was still there.