csharp dotnet comments suggest edit

Ok, I admit it. I’m a unit-tester-aholic. I’m compulsive about it. Sometimes going overboard:

string s = "hello world";
Assert.AreEqual(s, "hello world", "s changed. How about that?");

MbUnit is my friend. I feel a great sense of accomplishment when I can write a fully automated end to end unit test of an email Newsletter mailer. Previously, testing such an app required me to run the code, open up Outlook, check my email, and “uh huh, looks good.&8221; Now, by using a custom SMTP server class running on a separate thread (and on a custom port), my unit test can send a batch of emails and then ask the server if everything looks as its supposed to. “Aye aye. Everything checks out capt’n.”

However, there are certain cases that threaten to cure my obsessive compulsive behavior. For example, unit testing the pathological cases. Now ideally, these cases should happen infrequently enough that perhaps you can let them go. Sweep them under the carpet. Nobody has to know. Besides, who runs out of memory these days?

raising hand Well I did today. And I didn’t have a unit test for it. I could probably be forgiven for this one. I’m writing a Windows service that reads data into 10 DataSets. As each DataSet is read, I asynchronously open an SMTP connection and begin performing a mail-merge on that data set. I made sure to cap the number of concurrent connections to 10.

Now this app passed all my unit tests, but when I deployed it to the production server, it ran out of memory. After some analysis with a memory profiler, I discovered that I had violated Performance Rule #6, “90% of performance problems are designed in, not coded in.”

Each chunk of data I read in from the database is wrapped in a RecipientBundle class. The service then gives this class to an SmtpPool class which then schedules it to be sent on an available thread. The SmtpPool class keeps an ArrayList of the scheduled bundles to avoid sending duplicate bundles.

Hopefully you see the problem with this approach. I had a complete brain shutdown when I wrote the code to add the bundle to the ArrayList. Since the ArrayList is only used to avoid duplicate bundles, all that is necessary is to store the ID of the bundle. By adding the bundle, the ArrayList is holding a reference to the bundle, thus making sure it never gets garbage collected until the entire mailing is complete. Bad move. These bundles should be generation 0 objects. Created, sent, garbage collected.

So in any case, I’m thinking about whether or not I should write a unit case for dealing with OutOfMemoryExceptions. There are a lot of difficulties in doing so. Typically, for a case like this, I will try to write a unit test that fakes it. I will talk about how I do that later.

I already have a unit test for dealing with the ThreadAbortException. That’s also a story for another time as there are several difficulties with deaing with the ThreadAbortException. For example, it doesn’t seem to get raised in my methods that are running asynchronously. They just seem to die without a whimper. Also, there’s a slight issue with the CLR such that the finally block isn’t guaranteed to execute.

Till next time

comments suggest edit

So I was off to a running start with my ambitious new goals of contributing to several open source projects and creating a blog worth reading. But as my wife so keenly pointed out, as soon as I get an inch better, I try to take it a yard.

You see, I’ve been going to Occupational Therapy and will soon get some Physical Therapy for my back and wrist problems related to RSI (Repetitive Stress Injury). Carpal Tunnel is a form of RSI, but it is not what I am afflicted with. I have ulnar neuritis with a dash of tendinitis and a sprinkle of cubital tunnel syndrom (carpal’s lesser known cousin from the Bronx) thrown in.

After reading Dare Obasanjo’s and Scott Watermasysk’s blogs, I was inspired to contribute to their respective open source projects. I started out with a mad flurry of documentation writing for RssBandit without taking frequent enough breaks. I know, bad move. My back and wrists have flared up and I’m in a bit of pain.

To add to my misery, I’ve caught a bad cold. Yippee Kiyay! Anyways. I’m going to turn things down a notch, but will try to write something worth reading every so often.

comments suggest edit

I thought this was a joke until I realized that it was on Yahoo news. Bush and Cheney say we attacked Iraq because Saddam COULD HAVE made weapons of mass destruction. “Could have”. Gee, well North Korea “could have” made WMDs. Should we attack them? How about India who DO have. Heck, with a bit of time, I think I have enough intelligence and skill to make a WMD. Should I expect an airstrike on my apartment sometime soon? I hope not, my wife would not be pleased.

This turnaround is particularly amusing because didn’t Bush and his cronies attempt to educate the country about the concept of “Imminent Threat”. Saddam posed an “Imminent Threat”. I don’t know about you, but “Could Have” does not seem so immiment to me. It’s like locking me up because I could have made a baseball bat and beat you down. Certainly I could, but it will take me time to find the right piece of oak.

washingtonpost.com - President Bush and Vice President Cheney yesterday said the war in Iraq was justified because Saddam Hussein could have made weapons of mass destruction.

[Via Yahoo! News - Top Stories]

comments suggest edit

So I keep blabbing and blabbing about my new RSS Feed. I keep imploring you to get an RSS aggregator and subscribe to my feed. What the hell am I talking about?!

Well to clear things up, I wrote an article about how to get started with RssBandit, a very nice RSS Aggregator created by Dare Obasanjo et all. Please take the time to read it and follow its instructions. Especially you Dad. If I’ve done well, the article will clear thing up and you will have a subscription to my blog.

You can also download it as a word doc

comments suggest edit

My latest tech toy is an HP Scanjet 5530 Photosmart Scanner (wow that’s a mouthful). The defining feature of this scanner is the photo feeder built in. Simply add a pile of photos (around 24 max at a time) into the feeder, press a button, and go watch your Tivo’d episode of 24 while your photos scan (it doesn’t take all that long).

The incessant creaking of my bookshelf as it strains under the load of my accumulated photos spurred me to purchase this scanner. Having shuttled around the planet while growing up, it’s important to me to archive the memories of the havoc I created.

To that end, I also spent a lot of time searching for the perfect photo organizational software. The ideal program would have a clean nice interface and allow me to tag photos, organize photos into albums, search with face and image recognition, and automatically fix bad hair-day pics. I ended up purchasing Adobe Photoshop Album 2.0, which I’m quite happy with, though it doesn’t have image recognition (nobody really does just yet) and won’t fix my bad hair (a lost cause).

However, this new memo from Microsoft Research describes several advances that Microsoft is working on that will make their way into future products. Examples include image recognition, improved ability to fix red-eye and cut people from one photo and paste into another. One neat feature that currently works in Asian versions of Office 2003 can convert a picture of a person into a cartoon character with pretty good resemblance. Currently it only works for asian faces. I have to admit, I’m very excited.

Read about it here to see the examples.

comments suggest edit

This is just too funny! It’s a skit about a white family with an unfortunate last name which sounds just like a terrible racial epiteth, “Niggar”.

Dave Chappelle is a master at getting a laugh out of race issues. He’s testing the boundaries of racial issues and finding laughs.

If you like this video, I suggest you check out Chappelle’s Show - Season 1 on DVD. His most memorable skit is the one in which he plays Clayton Bigsby, a white supremacist who is both blind and black, only he doesn’t know he is black because no one ever told him.

comments suggest edit
  1. Specifications are for the weak and timid!
  2. This machine is a piece of GAGH! I need dual Pentium processors if I am to do battle with this code!
  3. You cannot really appreciate Dilbert unless you’ve read it in the original Klingon.
  4. Indentation?! – I will show you how to indent when I indent your skull!
  5. What is this talk of ‘release’? Klingons do not make software ‘releases’. Our software ‘escapes’ leaving a bloody trail of designers and quality assurance people in its wake.
  6. Klingon function calls do not have ‘parameters’ – they have ‘arguments’ – and they ALWAYS WIN THEM.
  7. Debugging? Klingons do not debug. Our software does not coddle the weak.
  8. I have challenged the entire quality assurance team to a Bat-Leth contest. They will not concern us again.
  9. A TRUE Klingon Warrior does not comment his code!
  10. By filing this SPR you have challenged the honor of my family. Prepare to die!
  11. You question the worthiness of my code? I should kill you where you stand!
  12. Our users will know fear and cower before our software. Ship it! Ship it, and let them flee like the dogs they are!

comments suggest edit

I usually ignore the spam that I get (and I get a bunch), but I read one of them a bit more carefully:

We hereby inform you that your computer was scanned under the IP 194.90.37.141 . The contents of your computer were confiscated as an evidence, and you will be indicated.

Umm… I think that the author was probablyÂlooking forÂâ€inditedâ€.

[Via Eric Gunnerson’s C# Compendium]

comments suggest edit

Quick, what’s the hex code for question mark? How about the ampersand? Since, like me, you probably don’t waste valuable space in your brain with that type of information, I have a little trick for you to quickly look up the hex encoding (or URLEncoding) for a character that doesn’t require you building an ASP or ASP.NET page and calling Server.UrlEncode().

Go to Google and type the character in the search box and then click “Google Search”. Now look in your address bar at the very end. Everything after the “q=” is the encoding of your character. For example, if I search on “?” I get:

http://www.google.com/search?hl=en&ie=UTF-8&oe=UTF-8&q=%3F

Thus the hex encoding for ? is %3F.

comments suggest edit

So this kid has a dorky moment alone at school in a little studio where he films himself. Next thing you know, his friends upload the tape to Kazaa and this kid is everywhere! People all over the net are remixing the video. Here is the Original and a remix:

Matrix Agents Remix

A lot of the remixes don’t work.

security networking comments suggest edit

Port knocking is a method of establishing extra security between a networked computer and the outside world. It seems like a great idea. For hosts that are running private services that need to be connected to the net, require clients to make a specific series of connection attempts to various ports. After the correct sequence is made, the firewall opens up the port for the client. This would be very difficult to uncover via a port scan.

comments suggest edit

My coworkers have been sending me some funny videos to get me caught up with pop-internet culture. Click on the “Humor” category to the left to see the latest funny videos. The Dave Chappelle one is especially worth watching.

comments suggest edit

Can somebody out there point me to a reference that explicitly says whether or not we can count on the underlying order of a DataTable rows to be the same order that is returned by a SQL statement or a Stored Procedure?

I read a posting somewhere where the author states that though it appears to be the case that the DataTable rows are ordered in the same order as retrieved from the database, that this ordering is not guaranteed by ADO.NET and should not be relied upon. For those familiar with hash tables, you know that a hashtable gives no guarantees about how elements are sorted.

Now I know all about the DataView class and how that can be used to have a sorted view of items in a DataTable. But my concern is this. Suppose the DataTable does respect ordering (for now) and thus my underlying data is already sorted. If the DataView uses traditional Quicksort to sort the data, that is the pathological worst case. Now there are new variants of quicksort that handle already sorted data just fine. I have yet to run benchmarks to find out how the DataView performs.

comments suggest edit

It’s amazing the fallout over the Janet Jackson breast incident.

My god people! It’s a breast!

It was on for three seconds!

We’ve all suckled on one when we were children (some even later) so I don’t buy the concern “think about the children!” Children see a breast on tv they think, “Hee Hee, a booby.” They don’t think, “Oh! I saw a breast. My innocence has been stolen, I think I’ll go out and engage in promiscuous unprotected sex.” Show a kid the closeup they’ll probably think, “Oh! That’s gotta hurt!”

In any case, I think Chris Sells makes a good point here:

Severe Beating Shown, CBS Shocked/FCC Investigates

Or rather, that’s the headline I wish I could post. However, instead of CBS and the FCC getting freaked out about the insane amount of severe violence on TV, available to our children any time of the day or night, they’re worried about 3 seconds of breast.

Idiots.