I found a bug in IE7

Looks like I found a bug in IE7. Sometimes the tab title “sticks” and stays the same regardless of which page/site you navigate to.

I was reviewing a blog post I had just made, so the tab title correctly said “Chinh Do”:

IE Bug 1

I then clicked on a link to navigate to Technorati, which normally has a title of “Technorati: Home”, but here the tab title still said “Chinh Do”.

IE Bug

I tried clicking on various links to navigate to different web sites, the title remained “Chinh Do”.

System.Transactions: New and Improved Transaction Management Model for .NET 2.0

Ok, so System.Transactions is not new to many .NET developers but it’s new to me. We have just started to research transaction management in my current .NET 2.0 project at work and  System.Transactions is looking beautiful. It gives us exactly what we need without the overhead of the old EnterpriseServices model (registering with COM+, having a strong name key, etc.) or the high maintenance of manual transaction management.

System.Transactions is more light-weight compared to EnterpriseServices. The programming model is relatively simple. You use the TransactionScope class to wrap your code inside a transaction. TransactionScope can be nested and can be assigned different transaction options such as Required or RequiresNew, similar to the various transaction attributes for EnterpriseServices.

using (TransactionScope scope = new TransactionScope()) 
{ 
  // do some work here (like executing a SQL, calling a method, etc.) 

  // The Complete method commits the transaction. If an exception has been thrown, 
  // Complete is not  called and the transaction is rolled back. 
  scope.Complete(); 
}

In my brief testing with Enterprise Library 2.0 and an Oracle database via Oracle Data Provider, I found that System.Transactions always enlist my transactions in MSDTC (Microsoft Distributed Transaction Coordinator). I am sure there is some overhead associated with this. I will do some more performance test later to find out exactly what the overhead is. I was hoping that for a transaction involing a single database/connection string, that MSDTC would not be needed. But further research indicated that the non-MSDTC/light-weight transaction only works with SQL Server 2005.

If your transaction management needs extend beyond databases, you can even write your own resource manages so that operations such as copying a file can be wrapped inside a transaction as well. Look into the IEnlistmentNotification interface.

Here are some good articles about System.Transactions for your further reading:

StringBuilder is not always faster – Part 1 of 2

How often have you been told to use StringBuilder to concatenate strings in .NET? My guess is often enough. Here is something you may not know about string concatenation: StringBuilder is not always faster. There are already many articles out there that explain the why’s, I am not going to do that here. But I do have some test data for you.

When concatenating three values or less, traditional concatenation is faster (by a very small margin)

This block of code took 1484 milliseconds to run on my PC:

for (int i = 0; i <= 1000000; i++) 
{ 
    // Concat strings 3 times using StringBuilder 
    StringBuilder s = new StringBuilder(); 
    s.Append(i.ToString()); 
    s.Append(i.ToString()); 
    s.Append(i.ToString()); 
}

And this one, using traditional concatenation, took slightly less time (1344 milliseconds):

for (int i = 0; i <= 1000000; i++) 
{ 
    // Concat strings 3 times using traditional concatenation 
    string s = i.ToString(); 
    s = s + i.ToString(); 
    s = s + i.ToString(); 
}

The above data suggests that StringBuilder only starts to work faster once the number of concatenations exceed 3.

Building strings from literals

When building a large string from several string literals (such as building a SQL block, or a client side javascript block), use neither traditional concatenation nor StringBuilder. Instead, choose one of the methods below:

+ operator

// Build script block 
string s = "<script>" 
       + "function test() {" 
       + "  alert('this is a test');" 
       + "  return 0;" 
       + "}";

The compiler concatenates that at compile time. At run-time, that works as fast as a big string literal.

@ string literal

I sometimes use the @ string literal which allows for newlines (I find this syntax is harder to maintain, formatting-wise, than using the + operator):

string s = @"<script> 
        function test() { 
        alert('this is a test'); 
        return 0; 
        }";

Both methods above run about 40 times faster than using StringBuilder or traditional string concatenation.

Rules of Thumb

  • When concatenating three dynamic string values or less, use traditional string concatenation.
  • When concatenating more than three dynamic string values, use StringBuilder.
  • When building a big string from several string literals, use either the @ string literal or the inline + operator.

Updated 2007-09-29

I have posted a follow-up article to provide more detailed analysis and to answer some of the questions asked by readers.

Google Maps on Your Windows Mobile Phone

Google has just made available Google Maps for Windows Mobile. Here’s the blurb on Google Maps Mobile Page:

Take the power of Google Maps with you on your mobile phone.

Real-time traffic — See where the congestion is, and estimate delays in over 30 major US metropolitan areas.

Detailed directions — Whether you plan to walk or drive, your route is displayed on the map itself, together with step-by-step directions.

Integrated search results — Local business locations and contact information appear all in one place, integrated on your map.

Easily movable maps — Interactive maps let you zoom in or out, and move in all directions so you can orient yourself visually.

Satellite imagery — Get a bird’s eye view of your desired location. (It’s like you’re there, we swear.

I tried the app on my Samsung i730 Windows Mobile phone and it worked great. Map data is retrieved from Google’s servers as needed just like regular Google Maps. Response time is slower than on a desktop but still very usable on my Verizon EDVO connection.

If you are a user of Google Maps then the screen below will look familiar to you:

Google Maps

Note the transparent buttons. Great idea.

Searching for local businesses is a snap. Click Search . Type in the name of the busines. Hit OK. Search matches are displayed on the map as pushpins:

Google Maps

There is also the Satellite View, but missing is the Hybrid View.

Google Maps

More info here.

Google Co-op

Google Co-op allows you to create customized search engines to fit your search interests. .NET developers, you may want to give the following pre-customized search engines a try:

For me, Co-op is a good idea but for now I will stick with just regular Google, at least for .NET related searches. I gave SearchDotNet.com a try and was initially underwhelmed my the number of matches. For example, searching for “EntryAssembly” using the DotNetSearch engine above yielded two pages of matches. Regular Google returns 387 pages.

Test Your Web Site in Internet Explorer 6 Using Microsoft IE6 Virtual Test Image

We all know that it’s a good idea to test our web pages in all popular browsers (to me that’s the various current versions of Internet Explorer and Firefox). It’s also a good idea to back up your data frequently, to listen to your elders, to not take a bath right after dinner, etc. Ok, so I admit I didn’t test my latest WordPress theme in IE6. While browsing the web on a friend’s PC, I discovered that my blog did not render correctly in IE6. It was broken in a major way. The right side bar completely disappears. Ouch!

I needed a way to test my site in Internet Explorer 6 at home, and since I have upgraded all of my PC’s at home to IE7, it seems like it’s a good time to give “virtual appliances” a try.

It took me about an hour to download the Internet Explorer 6 Application Compatibility VPC Image, install it, and have the virtual machine up and running. It helped that I already had Virtual Server installed. Yes Virtual Server works with Virtual PC disk images just fine. The current IE6 image expires on 4/1/2007 but I am sure Microsoft will replace it with another one when the time arrives. There is a blog entry on IEBlog about the image here.

Now I can reproduce the problem on my PC using IE6. That’s going to be the easy part I am afraid.

IE6

Update (2/8/2007): I fixed the IE6 problem. Apparently I had some sort of error in my sidebar.php file which messed up the HTML code, causing problems with IE6.

E.T. Will Probably Not Find Us in Our Lifetimes

According to this Guardian article, other advanced life forms just have not found us yet because they have not had enough time to look. According to the calculations, it may be a while before we get to say hello to E.T.

An alternative theory that I have is that once a galactic civilization advances past a certain level, it learns about an unwritten rule of the universe. That is growing civilizations are to be left alone untouched?

Google Reader Mini Review, Sharing Google Reader Items

I have settled on Google Reader as my RSS aggregator since they came out with the last upgrade (9/2006). My last aggregator was RSS Bandit. Google Reader has a slick interface and the article summaries are pulled/cached on Google server(s) so they usually come up pretty fast. Reader uses a lot of asynchronous rpc calls (known to some of you as AJAX) to provide a responsive experience. I love the ability to use keyboard shortcuts to do things such as moving to the next article, mark all items in a feed as read, etc.

Some people find the Google Reader Start Page useless… I sorta like it ok. Anyway, with the latest version, you can override the default Start Page with your own.

Another unique thing that Google Reader does is that it collects your reading statistics. It can tell you how many feed items you read in the last week/month out of the total items received. While this data is interesting in itself, I can see the potential of using it to automatically determine the most interesting items based on everybody’s reading statistics. If you can accurately track how long people spend reading certain items (hint: check the keyboard, mouse and scroll wheel movements), there is gold to mine there. Oops, did I just give away the main idea for my upcoming Web 2.0 startup?

One problem I have had so far is an HTML rendering issue in Internet Explorer 7 with certain feeds. I have not seen it lately so perhaps it has been fixed.

Google Reader

If you are already a Google Reader user, it provides an easy way to share interesting items from your feeds. When you run across something you want to share in Google Reader, just press shift-s or click on the Share link and the item will show up in your Public Shared Items web page. You can insert a clip into your blog to display the shared items there too. For Bloggers users, there is even an easier way.

Speaking of sharing items, you can also do the same thing with any of the social networking service these days. Del.icio.us comes to mind. With del.icio.us, in addition to Network Badges and Link Rolls, you can also have the ever more popular Tag Rolls. More ways to help the occasional bloggers out there add some signs of life to your blogs without having to actually write original/substantial/interesting content!