code, tdd comments suggest edit

Jonathan de Halleux, aka Peli, never ceases to impress me with his innovations within MbUnit. In case you’re not familiar with MbUnit, it’s a unit testing framework similar to NUnit.

The difference is that while NUnit seems to have stagnated, Jonathan is constantly innovating new features, test fixtures, etc… for a complete unit testing solution. In fact, he’s even made it so that you can run your NUnit tests within MbUnit without a recompile.

His latest feature is not necessarily a mind blower, but it’s definitely will save me a lot of time writing the same type of code over and over for testing a range of values. I’ll just show you a code snippet and you can figure out what it’s doing for you.


[TestFixture]public class DivisionFixture{    [RowTest]    [Row(1000,10,100.0000)]    [Row(-1000,10,-100.0000)]    [Row(1000,7,142.85715)]    [Row(1000,0.00001,100000000)]    [Row(4195835,3145729,1.3338196)]    public void DivTest(double num, double den, double res)    {        Assert.AreEqual(res, num / den, 0.00001 );    }}


And if you’re anal like me and wondering why I chose “num” instead of “numerator” etc… Purely for blog formatting reasons. ;)

UPDATE: Jonathan points out that negative assertions are also supported. Here’s an illustrative code snippet. I can’t wait to try this out.


[RowTest] [Row(1000,10,100.0000)] ... [Row(1,0,0, ExpectedException =              typeof(ArithmeticException))] public void DivTest(double num, double den, double res) {...} 

comments suggest edit

Xclef Saw this on Gizmodo. It’s bigger and not as nice looking as an iPod, but it is 100 GB.

The DMC Xclef 500 also supports Ogg Vorbis and even WAV—with a 100GB drive, you could start ripping your CDs with no compression at all. The 100GB version is $450 from DMC’s online store.

humor comments suggest edit

My friend Michael who lives in London for now sent me this.

Once again, The Washington Post published its yearly contest in which readers are asked to supply alternate meanings for various words (& leave it to the Post to search for new meanings).

And the winners are …

​1. Coffee (n.), a person who is coughed upon.

​2. Flabbergasted (adj.), appalled over how much weight you have gained.

​3. Abdicate (v.), to give up all hope of ever having a flat stomach.

​4. Esplanade (v.), to attempt an explanation while drunk.

​5. Willy-nilly (adj.), impotent.

​6. Negligent (adj.), describes a condition in which you absentmindedly\       answer the door in your nightgown.

​7. Lymph (v.), to walk with a lisp.

​8. Gargoyle (n.), an olive-flavored mouthwash.

​9. Flatulence (n.) the emergency vehicle that picks you up after\      you are run over by a steamroller

​10. Balderdash (n.), a rapidly receding hairline.

​11. Testicle (n.), a humorous question on an exam.

​12. Rectitude (n.), the formal, dignified demeanor assumed by a\       proctologist immediately before he examines you.

​13. Oyster (n.), a person who sprinkles his conversation with\       Yiddish expressions.

​14. Pokemon (n), A Jamaican proctologist.

​15. Frisbeetarianism (n.), The belief that, when you die your Soul\       goes up on the roof and gets stuck there.

​16. Circumvent (n.), the opening in the front of boxer shorts

office home workspace comments suggest edit

I know a lot of people like to post picturesof their workspace online. Not sure why (vanity!), but they just do. So I thought I’d jump on that bandwagon and do the same.

This first picture shows my work office with it’s nice 17th floor view.

Work Office

Strange green bands take over the screens.

This next one is our home office.

My home office

As you can see, the home setup is much nicer than the work setup with dual 17” flat panels monitors, and a slick looking aluminum Shuttle case. I wish my company would invest in nice monitors. My work monitors flicker, make me cross-eyed and spit in my food. If you look closely at the top picture, the computer case is literally held together with scotch tape on top. The IT department wouldn’t budget duct tape.

The little figurine on top is the “Buddy Christ” from Dogma. You can purchase that on Kevin Smith’s website. My wife painted the red shoe on the left.

comments suggest edit

Copernic LogoAfter reading the reaction around the net about Google Desktop (GD for short), one common complaint I noticed is the use of a web browser for local searching. Why use a web browser to search locally and forego all the utility and benefits a rich client can provide?

So I thought I’d start trying out some of the free alternatives to GD. One that is mentioned quite often is Copernic. I decided to uninstall GD and give it a whirl.

So far, I’m not quite satisfied. I left it running overnight and it’s still not done indexing my hard drive. Not only that, while it’s indexing, my computer runs at a snail’s pace at times. I often have to restart it to reclaim my computer’s resources. In comparison, GD finished indexing within a much shorter time span with a nearly imperceptible impact on my computer’s performance.

One area where Copernic shines above GD is the UI. Copernic provides options for refining the search parameters just below the search input. When you search for emails, the search result window breaks down the results by date. You can see them grouped into emails received Today, Yesterday, Last Week, Last Month, This Year, and so on…

One shortcoming that both engines share is the inability to specify file types to search other than the preconfigured ones. For example, I would like to search my C# files that have the .cs extension. No can do.

So the search continues. I could shell out for X1, but I’d like to find a free product I can use at both work and home. I read about another product to try at home, but forgot its name. In any case, I’ll keep you posted.

UPDATE: Whoops! Apparently you can configure Copernic to index arbitrary file types through the advanced options dialog. Thanks to Eric for the tip.

comments suggest edit

A strange phenomena occurred last night and into this morning here in Los Angeles. I kid you not, but water… fell from the SKY!

Near panic ensued throughout the city as Angelenos tried to make sense of this unexpected situation. My league soccer game was cancelled due to poor field conditions (aka mud).

Fortunately, I had a backup plan. Every Saturday and Sunday I have a pick-up game with a wonderful group of people. The field we play on was in need of water and by 2 PM was in perfect condition. Water even fell from the sky again in the midst of our game. It was a beautiful experience.

Afterwards, my brother-in-law took us out for dinner at The Lobster. Oh man, is that food ever good! Try the scallops.

comments suggest edit

Saw this post by Craig Andera about Test Driven Development and I have to say I completely agree with him.

I’ve been doing TDD for several years now and I tend to restrict it to testing business and data access layers. Currently, it’s not practical to perform comprehensive TDD for UI layers (though tools like NUnitAsp and NUnitForms help).

Even these tools don’t address one of the biggest challenges when it comes to testing a UI layer. The UI layer is the layer most likely to change and change often. After spending a few hours building your tests, some guy in marketing will call you up and say, “can we replace that button with a table of data with clickable rows?” What now?

Unit tests tend to be quite fragile when faced with a changing UI layer. Human testers have no problem dealing with such change, but your unit tests definitely will.

My recommendation for testing the UI layer are combining test scripts (for human testers) along with writing unit tests when a bug is found in the UI layer. At that point the UI should hopefully be frozen enough that writing a unit test that exposes a bug and then fixing the bug will be a worthwhile investment for regression purposes.

comments suggest edit

FastCompany Read this article at FastCompany pointed to by Steve Maine and maybe I’m lazy, but I totally disagree.

The article makes the point that the concept of “work-life balance” is a pipe dream. What the article fails to mention are the associated health problems for many workaholics. For programmers in particular, ailments such as RSI are common (though many programmers such as myself count programming as a hobby as well which would also contribute).

The article briefly dismisses the European notion of “Working To Live”. I think in doing so, it fails to address the societal and cultural issues that often drive a work-life imbalance. How successful is this notion of succeeding at all costs as a source of fulfillment? The article mentions that imbalance is required to gain real productivity, but is that the measure of one’s success?

It’s well documented that Americans tend to spend their hard earned money on things and possesions while Europeans spend more on vacations and events. Should work be the primary defining character trait of a person? In the U.S., the first question in any social setting is “What do you do?”. In many European countries, it’s a social gaffe to ask that of a stranger. Why not ask, “What do you like to do?”.

It’s my contention that this single minded focus on materialism (and I’m not totally against materialism as I LOVE my iPod) is the driving force behind working too much. If one were to step back and look at what really gives one fulfillment, I think priorities will often be rearranged. Not that I’m against working hard. I love to write code and read books about coding and software management in my spare time. However, I also realize the value of defining myself along other interests as well. I realize the value of maintaining my health via excercise and of my mental health through maintaining meaningful relationships with friends and family.

It reminds me of something I’ve heard somewhere or other. How often do you hear people in the twilight of their lives or on their death beds reflect on the wonderful time they spent at the office?

comments suggest edit

Bush PraysSaw this going around the web. Classic!

Dear President Bush, Thank you for doing so much to educate people regarding God’s law. I have learned a great deal from you and try to share that knowledge with as many people as I can. When someone tries to defend the homosexual lifestyle, for example, I simply remind them that Leviticus 18:22 clearly states it to be an abomination. End of debate. I do need some advice from you, however, regarding some other elements of God’s Laws and how to follow them:

​1. Leviticus 25:44 states that I may possess slaves, both male and female, provided they are purchased from neighboring nations. A friend of mine claims that this applies to Mexicans, but not to Canadians. Can you clarify? Why can’t I own Canadians?

​2. I would like to sell my daughter into slavery, as sanctioned in Exodus 21:7. In this day and age, what do you think would be a fair price for her?

​3. I know that I am allowed no contact with a woman while she is in her period of menstrual uncleanliness (Lev. 15:19-24). The problem is, how do I tell? I have tried asking, but most women take offense.

​4. When I burn a bull on the altar as a sacrifice, I know it creates a pleasing odor for the Lord (Lev. 1:9). The problem is my neighbors. They claim the odor is not pleasing to them. Should I smite them?

​5. I have a neighbor who insists on working on the Sabbath. Exodus 35:2 clearly states that he should be put to death. Am I morally obligated to kill him myself, or should I ask the police to do it?

​6. A friend of mine feels that, even though eating shellfish is an abomination (Lev. 11:10), it is a lesser abomination than homosexuality. I don’t agree. Can you settle this? Are there “degrees” of abomination?

​7. Lev. 21:20 states that I may not approach the altar of God if I have a defect in my sight. I have to admit that I wear reading glasses. Does my vision have to be 20/20, or is there some wiggle-room here?

​8. Most of my male friends get their hair trimmed, including the hair around their temples, even though this is expressly forbidden by Lev. 19:27. How should they die?

​9. I know from Lev. 11:6-8 that touching the skin of a dead pig makes me unclean, but may I still play football if I wear gloves?

​10. My uncle has a farm. He violates Lev. 19:19 by planting two different crops in the same field, as does his wife by wearing garments made of two different kinds of thread (cotton/polyester blend). He also tends to curse and blaspheme a lot. Is it really necessary that we go to all the trouble of getting the whole town together to stone them (Lev. 24:10-16)? Couldn’t we just burn them to death at a private family affair, like we do with people who sleep with their in-laws (Lev. 20:14)?

I know you have studied these things extensively and thus enjoy considerable expertise in such matters, so I am confident you can help.

comments suggest edit

Colin sent me an email pointing me to an add-in he wrote for VS.NET that allows you to copy selected source code to the clipboard as syntax highlighted HTML.

By selecting some code and right clicking the code editor, you’ll see an option to Copy Source as HTML.

Selecting that menu item brings up a dialogue where you can configure some options. It’s based on my favorite code to HTML formatter by Manoli.

Below is an example of a code snippet using this tool:

/// Sets the stack trace for the given lock target 
/// if an error occurred.
/// </SUMMARY>
/// <PARAM name="lockTarget">Lock target.</PARAM>
public static void ReportStackTrace(object lockTarget)
        ManualResetEvent waitHandle = 
                 as ManualResetEvent;
        if(waitHandle != null)
        _failedLockTargets[lockTarget] = new StackTrace();
        //TODO: Now's a good time to use your
        //favorite logging framework.

Colin, thanks for pointing me to this. This is freakin’ awesome!

Now, if I could have a short-cut that would use the default options and immediately put the selected source in the clip-board, that would just rock my world. Also, one minor niggle I’ve had with the Manoli formatter is that the xml comments tags and the triplle slashes (such as /// ) should be gray to mimic VS.NET instead of all green. How hard would it be to fix that?

comments suggest edit

Dave Winer points to a blog posting by Erik Speckman calling Google Desktop Search a disappointment. One complaint that Dave shares is that Google search only works with certain file formats. He wants to be able to add plug-ins for file formats it doesn’t already understand.

Well first of all, this is a BETA technology. I think it’s a tad bit premature to call it a disappointment just yet. It’s already far better than any other free desktop search utility out there.

Secondly, it may well be as extensible as Dave and Erik would like, but as a BETA product, we can’t be sure yet because such interfaces are not published. Scott Hanselman started digging into it a bit and noticed various dlls used to implement searching across IE and Outlook. That suggests that there might be a plug-in architecture they will expose later (perhaps after getting feedback during the BETA trial). In any case, Scott’s peek inside is a worthwhile read.

UPDATE: Erik notes in reply on his blog that I have a valid point regarding Google Desktop’s BETA status, but that the point of a BETA is to gather criticism. I agree wholeheartedly and I think he gives some solid suggestions to the Google team. The title of his reply is “Google Desktop Search BETA is a disappointment” (emphasis mine). That clears it up for me. :)

If you’re a Windows, Office, and Outlook user like me, I think you’ll find the BETA worthwhile. If not, Google has some work to do to make sure the final product isn’t a disappointment for users like Erik and Dave. Hopefully we’ll see an extensibility framework come out for it.

code comments suggest edit

By now you probably think I have an unhealthy obsession over the TimedLock struct. Well, you’re right. I think it’s emblematic of the right way to do things and shows that the right way isn’t always the easiest way.

In Ian’s last post on the TimedLock, he talked a bit about the performance considerations with my solution to keeping track of stack traces in a multi-threaded situation. To sum, my solution is pokey in certain situations. As always, measure measure measure.

However, Ian mentioned a solution outlined by Marek Malowidzki that avoids creating a stack trace on every lock acquisition. Instead, he only stores the stack trace when a lock timeout occurs, thus avoiding the performance penalty of my implementation. Unfortunately, there’s no source code posted for examination.

So I decided to implement Marek’s solution based on Ian’s write up. As Ian mentioned, it would probably be best if the blocking thread didn’t throw an exception, but logged diagnostic information if it detects that some other thread timed out while trying to acquire a lock on the target. I put a very helpful //TODO: right where that should happen since everyone has their own preferred logging framework.

As stated in the write-up, when thread fails to acquire a lock, it adds the object it was trying to lock to a Hashtable as a key with a NULL value. When the blocking thread is about to exit the synchronization block, it checks this hash table and if it finds the object it is locking in there, it will set the value for the Hashtable item as its own stack trace.

Thus if you catch the LockTimeoutException, you can have it try to obtain the stack trace from the Hashtable (supplying a wait since it might not be there immediately). However, there’s one potential problem here. If you don’t remove that object from the Hashtable after you’ve looked at it, the next time you lock on that object and then release it, your blocking thread will think an error occured and log some diagnostic information. This isn’t too bad since it doesn’t cause a LockTimeoutException to be thrown.

One thought I had was to check the Hashtable when I first successfully acquire the lock on a target and remove the target if its already there. However, that’s not safe as it’s quite possible that another thread failed after the blocking thread acquired the lock but before it examines the Hashtable.

Instead, when you call GetBlockingStackTrace, it retrieves the stack trace from the Hashtable, stores a reference locally, and then removes it from the Hashtable.

In any case, I’ve posted the source code in my TimedLock repository on GitHub.

DISCLAIMER: The code to keep track of stack traces is designed for debugging only and is turned on by setting the conditional compilation variable #DEBUG = true. I make no guarantees and pity the fool who deploys this version of TimedLock.cs in a production system with #DEBUG = true. Please let me know if you see any problems with this implementation. So far it passes my tiny suite of unit tests.

UPDATE: I accidentally linked to the old TimedLock. The link above has been updated.

UPDATE #2: Eric discovered a subtle bug in my older implementation of TimedLock which he describes here. Nice work in tracking that down!

comments suggest edit

Found this on Boing Boing. School photos will never be the same. I always thought the point was to look miserable.

\ Mrs. Xiang sex-ed class demonstrate a keen knowledge of their studies.

Click the pic for the larger image.

UPDATE: Found a news story about this particular photo here.

blogging, humor comments suggest edit

PubSub is no longer around, so those links will be broken. I’ve written a new post that provides fresh opportunities for being a vain blogger.

Vanity I’m not the first to say it and I probably won’t be the last. But blogging is pure vanity, and new services out there just make it easier and easier to inflate one’s head.

For starters, the vain blogger will subscribe to his own RSS feed (or ATOM feed) in his favorite RSS reader. The vain blogger will assure you that this is for quality assurance purposes, but the astute reader can see right through that smokescreen. Obviously this is just the blogger’s vain longing to gaze at his own writing akin to staring at a mirror.

The next step is to install the Google Toolbar so the vain blogger can check his Google PageRank every day, in hopes of seeing even the slightest climb validating his pathetic existence.

“Hey! Look at that. It moved up a notch from 3 to 4!!! I’m a GOD! You really love me! Now please click on the ads below and make me RICH!”

Naturally, if the vain blogger is using .TEXT, he’ll religiously check the admin section hourly for page view and aggregator stats and pore over the referrer lists looking for that lone referral that is NOT a result of a Google search.

The more sophisticated vain blogger realizes poring through referrer logs is futile and steps it up a notch by using tools such as Technorati, Feedster (no longer around), and PubSub (also gone bye-bye). These tools enable the vain blogger to register his or her blog on their search engines and then subscribe to a feed of blogs that mention or link to his own. Ah… this takes the blogger to the next level of vanity. But it doesn’t stop there.

Pubsub provides a link rank page. Enter a domain and it displays where it ranks in the blogosphere. Today my blog jumped from 2048 to 1893! Wohoo!…I think. I have no idea what that number means or what the total range is, but that’s inconsequential to the vain blogger. It’s a number, and it’s better than it was. That’s all that matters.

What is vanity if there is nobody around to behold it. Thus the vain blogger whores himself out by linking to Scoble or Dave Winer in hopes of a back referral and perhaps endorsement. Better yet, he’ll try to get link to his blog posted on BoingBoing to drive some real traffic to the site.

Ah yes, as we see, blogging is pure vanity. As the author of this respectable blog, I vow not to drag it and its readers through the dirt of such degrading procedures. No no. I will not debase myself in such manner and will strive to stay on the high ground. I will retain my dignity and integrity.

Unless of course you can get me on Slashdot…

UPDATE: One tool on the vain blogger’s utility belt I forgot to mention is blatant self promotion. Got that one from Brian Bailey’s tips for a better blog, but it applies just as well to vanity.

Tags: blogging, Meta blogging

comments suggest edit

My knee is now to the point that I’m ready to play in a local soccer league. My first game is this Sunday in Van Nuys. Wish me luck and no injuries. I’ve been watching World Cup Highlights so I’m ready to samba the beautiful game.