double.IsNaN is 100 times slower

Its not just your programming group that can’t get it right. I work in a semi-disfunctional group on contract for a client who, not matter how hard we try, doesn’t seem to listen to basic software engineering principles.

I feel a little better (and a great deal worse after thinking about it) when I see that the largest software company in the world deals with some of the same problems.

I found this gem in the WPFToolkit (it is MSPL) source.

// The standard CLR double.IsNaN() function is approximately 100 times slower than our own wrapper,
// so please make sure to use DoubleUtil.IsNaN() in performance sensitive code.
// PS item that tracks the CLR improvement is DevDiv Schedule : 26916.
// IEEE 754 : If the argument is any value in the range 0x7ff0000000000001L through 0x7fffffffffffffffL
// or in the range 0xfff0000000000001L through 0xffffffffffffffffL, the result will be NaN.        
public static bool IsNaN(double value)
{
    NanUnion t = new NanUnion();
    t.DoubleValue = value;

    ulong exp = t.UintValue & 0xfff0000000000000;
    ulong man = t.UintValue & 0x000fffffffffffff;
    return (exp == 0x7ff0000000000000 || exp == 0xfff0000000000000) && (man != 0);
}

 

My jaw was open pretty far for quite a few seconds as I read this.

An Application of iPad

I really hate the timing of this post, but the ideas are fresh in my head. You can consider this ‘just another iPad post’ if you want.

Ever taken a survey on the streets from someone with a PC style tablet? I’ve taken a few. I’m always surprised by the hardware choice. For some things, it seems like a clipboard and paper would be better.

At work, there is an upcoming project that involves something like the above. Here is why I think the iPad is a better choice. It mostly comes down to boring IT Operations reasons, aka management of the underlying platform.

  • With iPad, you never have to defragment your disk.
  • With iPad, you never have to run antivirus or update antivirus definitions.
  • With iPad, you never have to run anitspyware or update antispyware definitions.
  • With iPad, there is no moving and spinning disk which is prone to higher failure.
  • With iPad, you don’t have to worry about some slick-kid or script kiddie downloading and installing some crazy software that turns your computer into a bot or even just overwrites important files preventing you from booting the next time.
  • With iPad, you don’t have to worry about not having a replacement part available if a piece of hardware fails.
  • With iPad, the user will have a more familiar experience. Given the prevalence of iPhone, it is likely that an end user will understand many of the touch and drag gestures.
  • With iPad, there is no stylus like the PC Tablets of old.
  • With iPad, there is a very clear future. When was the last time apple canceled a product line? Newton? Ok, how about under Jobs? I’ve no idea.

I’m as anti-fud as any person that I know. Yes, the above is definitely anti-windows fud cited by Mac and Linux lovers everywhere and normally I’m the first person to refute it. However, I think under that fud there are tiny grains of truth. For certain applications those bits of truth are highly amplified. It is a different risk vector. These things become very important and translate directly to cost of ownership.

Notice that I’ve listed no pros or cons for iPad as a general purpose device. I don’t care to go there. I’ve also not mentioned if there is much of a market for the above use case (there isn’t enough to sustain the device alone). These are all things to be answered elsewhere. My point in short: here is a use case if you have been wondering for what kind of things iPad can be used.

My Whole App is a LINQ Expression

I just published an application which I consider useful over on codeplex with source hosted on launchpad.

http://wlanchannelinfo.codeplex.com/

https://code.edge.launchpad.net/~evarlast/+junk/WlanChannelInfo

I wrote this because Wifi in my home is very slow. Its so slow I’m tempted to run a network cable to my couch so that even when I’m couch surfing I can have fast access to my server.

In an effort to diagnose my slow Wifi, I tried to see if my neighbors were causing interference by running Wifi on the same or overlapping channel as me. I downloaded netstumbler; it didn’t work. I downloaded some other tool; neither did it.

So I wondered how hard it would be to write my own. It turns out Windows 7 added to the Wlan* api to expose all of the necessary data. After some digging I found the managedwlan project on codeplex. Now I got to play.

Once I figured out the api, I was able to write the entire application with pretty much one LINQ expression:

var client = new WlanClient();
var retval =
from wlanIface in client.Interfaces
from bssentry in wlanIface.GetNetworkBssList()
from network in wlanIface.GetAvailableNetworkList(Wlan.WlanGetAvailableNetworkFlags.IncludeAllAdhocProfiles)
where InterfaceService.GetStringForSSID(network.dot11Ssid) == InterfaceService.GetStringForSSID(bssentry.dot11Ssid)
select new WifiInfo
{
bssentry = GetStringForSSID(bssentry.dot11Ssid),
channel = Wifi.FrequencyChannelMap[bssentry.chCenterFrequency],
frequency = bssentry.chCenterFrequency,
linqQuality = bssentry.linkQuality,
strength = bssentry.rssi,
signalQuality = network.wlanSignalQuality,
wifitype = network.dot11BssType
};

The result of that expression is directly databound to a WPF DataGrid and I can now view the data that I want to.

I really love the platform (C#+.NET) on which I work.

I’m Lazy And I Need My Helpers

public static class NumericExtensions
{
public static bool IsZero(this byte number)
{
return 0==number;
}
public static bool IsZero(this short number)
{
return 0==number;
}
public static bool IsZero(this int number)
{
return 0==number;
}
public static bool IsZero(this long number)
{
return 0==number;
}
public static bool IsZero(this float number)
{
return 0==number;
}
public static bool IsZero(this double number)
{
return 0==number;
}
public static bool IsZero(this decimal number)
{
return 0==number;
}
}

I wanted something like this today as I was toggling between NUnit and MSTest. Sure, Assert.That( something, Is(0) ) is readable, but its not portable. Its NUnit only, and for this project, I can’t do that. I also like the english reading of IsZero() vs. Is(0)

I think I’ve stated before that any code on this blog (c) by me and licensed under the MIT/X11 License, but for certain bits of code, I see no point in that. So I’m going to start tagging code with CC0, Unlicense and/or WTFPL.

Windows Home Server backup database

I’m seriously thinking I should change my backup strategy. I use Windows Home Server for one thing and one thing only, Backups. Sure the file share stuff is nice, but I already have a Linux server with samba with my file shares. WHS lovers will say I should migrate, but all I see that gaining me a day or so of copying files and no real benefit.

I recently got a new laptop and when adding this into the mix I had to add more storage to my WHS. I did, and after doing so I got this:

HomeServer-AllBackupsLost

What good is a backup system if it loses your backups? Not much good IMO.

Windows 7’s backup is very good now and I think I may benefit from just using it rather than WHS. I’ll duke it out with WHS one last time, but I won’t be recommending it to Mom, Dad or Grandma anytime soon.

Geeks drive girls out of computer science

My wife linked me to this article about a cultural study done on certain masculine aspects of things which often surround computer science.

http://www.msnbc.msn.com/id/34437233/ns/technology_and_science-science/

She (my wife) brought it up in the context of cables and cords lying around and I’d guess that extends to the unused laptop, mouse or keyboard. She is a very neat person. I am less so, but she keeps me in check. This is good.

The article talks about the physical environment of a computer science classroom or office. I don’t know what classrooms this study is looking at. I can only assume that they are primary and secondary classrooms because the college classrooms in which I teach and in which I attended are the same boring sterile classrooms in which all subjects are taught.

I can comment on offices. The quote from the article is a quote by the lead researching Sapna Cheryan from the University of Washington. She says “… the image that immediately pops into many of their minds is of the computer geek surrounded by such things as computer games, science-fiction memorabilia and junk food.”

I’d like to address each of things. There are no computer games on my desk at home nor at work. At home, I share a desk with my wife, occasionally there is a game left out. They are hers. I have her Rollercoaster Tycoon CD in my backpack right now, because she left it in my disk drive. I do not play video games. It is a choice. I used to play a few video games. I think that when Starcraft 2 comes out, I’ll probably play that video game.

I have some science fiction memorabilia stuffed in drawers at home. A hat from the cast of the original Stargate movie. A signed Richard Dean Anderson photograph. Both of these were gifts from people who knew that I love Stargate. I don’t leave them out. I don’t talk about them. In fact, if any of my coworkers read this, both items will probably be a surprise to them, and they will probably make fun of me greatly for each of them.

Junk food is bad. I’d probably eat lots of junk food if I didn’t have my wife to take care of me and she didn’t constantly remind me about good nutrition and encourage me by talking to me about the food industry, summarizing books for me and watching movies with me such as Supersize Me and Food Inc. I bring my lunch to work almost every day rather than eat out. As I write this many of my coworkers are out at the monthly Ann Arbor “Nerd Lunch”. I try to eat healthy.

I try to eat healthy to the point that food preparation is something that I can talk at length about. Last night I made cottage cheese. I bake all my own bread. I’ve not bought bread from a store in over 6 years. I make my own chicken stock. I make a lot of things that are often bought. I do not consider any of these things add to my computer geek. If anything I’m a non-geek. These things are also traditionally non-masculine activities. Although more recently I think they are more niche hobbies than feminine activities.

What is the point? I guess I’m trying to say, look deeper. Yes, on the surface there is a video game, bad-sci-fi, junk food culture to computer science, but as soon as you peel back the first layer there is a variety and depth as wide as any other profession.

I still like wired networks

I needed to archive 472MB of photos onto the home file server so that my wife could access them.

Over wifi, I got an estimate of 35minutes. Yes this is horribly slow, even for a 54Mbit “G” speed network.

So I plugged in the CAT5 cable, I disabled wifi on my laptop and I pressed refresh in windows explorer so that SMB2 was now talking on the wired network.

I performed the exact same drag and drop to copy the files and it was done in 5 seconds, almost faster than I could expand the Windows 7 copy dialog and see the transfer rate of > 50MBytes/second.

Learning WPF… For real this time.

I’ve been diving into WPF, again.

WPF is different now and will be even more different in 4.0. The WPF Toolkit is not an “option” in 3.5, it is a requirement. Just like I wouldn’t want to write .NET Code without certain 3rd party libraries (castle, elevate, etc..), I would not want to write WPF without the toolkit.

WPF in .NET 4.0 includes many things from the WPF Toolkit. The one thing that makes Winforms developers like me feel right at home is DataGrid, but the WPF DataGrid is not DataGridView for WPF. I keep running into surprises.

The latest surprise had to do with a prototype I was building. In Winforms, I often just databind a DataGridView to any IList<T>, and let magic do the rest for me. After all, it is just a prototype.

I tried to do the same thing with WPF DataGrid and I was met with a surprise. Surprise! Don’t do that. As soon as I changed from a IList<T> to an ObservableCollection<T> the binding worked. AutoGenerateColumns=”True” makes it very easy to prototype.