Maintenance vs Performance

On my routine article search on Test Driven Development TDD, I came across Jeremy D. Miller's blog. I found this article of his to be a good list of todo items for any one starting on a new project. A couple of other good articles of his are here and here.


Regular Expressions simplified

I have been relying on regular expressions a lot lately and there is one tool without which the job would have been very difficult. The tool is The Regulator. It is simply an awesome tool. You enter the input string and then start writing your regular expression, as you do it, you can keep testing the expression to see whether it works / tweak it. Once satisfied you can copy the expression into your code and be sure for it to work.

Well the maker of The Regulator has come out with a new even simpler tool. It's named Regulazy. As the name suggests, you don't have to write the regular expression anymore, just highlight the information that you want to be part of the regular expression, right mouse and click one of the options and the tool writes the expression for you. That simple.
Enjoy!


HTTP Compression

I serve my website off of my home computer which has a decent broadband connection. The upload speed however is a mere 384KB, which used to make my web pages slow in loading up until I enabled HTTP compression and let me tell you it is a real blessing. Not only does it save a lot of bandwidth, but more importantly my pages are a lot more responsive.

Most modern browsers support two compression algorithms, GZip and Deflate. I am using Blowery an open source compression software for serving my web pages in Deflate compression mode. The other thing I enabled last week on my site was AJAX using the new Microsoft Atlas Framework. What I saw was that one of the JavaScript files served to the browser was a whopping 242KB. Although script files get cached by the browser, the speed on the first serving on my web page would be aweful.

The Javascript files are served through a new concept in ASP.NET called Web Resources, where you can embed JavaScript and image files directly into your assembly as resources. When the ASP.NET engine gets a request for these resources it extracts these files out of the assembly and serves them. The file that does is called WebResource.axd. I don't have a clue as to what that file is / does, but I will do some reasearch to find out. The point is that by enabling Blowery the JavaScripts on my web pages stop working. I found a patch for this. You have to add the following lines to the httpCompress section required by blowery in the web.config

<excludedPaths> 
      <add path="ebresource.axd"/>
      <add path="webresource.axd"/> 
</excludedPaths>

Having fixed the web pages, I still wanted to do something about those huge Atlas files. Luckily some smart Atlas developers at Microsoft have coded a compression routine for the resource files that are served through webresource.axd. You can enable it by adding the following line in the httpModules section to your web.config.

<httpModules>
      <add name="WebResourceCompression"
           type="Microsoft.Web.Services.WebResourceCompressionModule" />
</httpModules>

An important point to note is that this needs to be above the blowery http module. That is blowery also is an httpModule that needs to be added to the httpModules section in the web.config. However by keeping the add tag for blowery above the atlas module, my Atlas JavaScripts were not getting compressed. Moving the tag fixed the problem.

Have fun!


Enable AJAX with Atlas

Start off by downloading and installing the latest CTP from the asp.net site. Watch the "Get Started with “Atlas”?" video on this page to install and setup Visual Studio to be Atlas ready. You can then watch the other videos that show how to use some neat tricks to avoid server postbacks.

For the view comments feature on my blog, I created the following:

  • A custom control (by extending System.Web.UI.WebControls.WebControl) that accepts a dataset as a property and loops through the dataset in the Render method to output the necessary html.
  • A webservice that talks to my business logic, gets the necessary data, passes it to the custom control and outputs whatever the control renders.

Let's look at a simple example:

HelloControl.cs

public class HelloControl : WebControl
{
      private string _text; 
      public string Text
      {
            get { return _text; }
            set { _text = value; }
      }
      protected override void Render(HtmlTextWriter writer)
      {
         writer.Write("<span style='font-weight:bold;color:#dd0000'>Hello "
                       + _text + "</span>");
      }
}

All this control does is given an input text, it outputs the text in bold and red.

HelloService.cs

class HelloService : WebService 
{ 
      [WebMethod] 
      public string SayHello(string name) 
      { 
            HelloControl c = new HelloControl(); 
            StringWriter writer = new StringWriter(); 
            HtmlTextWriter htmlWriter = new HtmlTextWriter(writer); 
            c.RenderControl(htmlWriter); 
            return writer.ToString(); 
      } 
}

That's it, you now have a webservice that spits out html which can then be used to fill certain sections of your web page. You can watch the "“Atlas” Enable an Existing Web Service?" video to see how to use webservices on the client side using Atlas.

Have fun!


Atlas

I have been playing around with atlas for the past couple of days. For those who don't know about atlas please visit here. It is a new AJAX framework that sits on top of ASP.NET and let's you enable AJAX on any ASP.NET control.

Today I added two features to the site using Atlas.

  • Ability to view comments without going to the feedback page
  • Ability to navigate the calendar without page refresh

UpdatePanel in Atlas is an awesome control. In order to enable AJAX on the Calendar control all I had to do was to add the UpdatePanel control on the ASP.NET page and move my existing Calendar control inside it. That's it, I now have a calendar control that can be navigated without a page refresh.

I will explain the code behind the view comments feature in another post.


Infragistics controls

Soon after using Component Art controls, I started testing Infragistics controls. Infragistics packs far more controls in the suite compared to Component Art. They include a ton of ASP.NET controls, Charting controls, and WinForms controls, all for the same $700. In working with the grid control I saw that it was very powerful with lots of settings but was difficult because of their naming conventions. With Component Art it was very easy, the names used for various control attributes made sense. All in all I think the $700 for Component Art was not justified when compared to Infragistics. The word in the market is that Infragistics is more mature and more used among developers. The developer inside me likes Component Art, simply because of it's ease of use, having said that Infragistics is not that hard too use. You would see immediate developer productivity with both tools, as well as AJAX support out of the box. Which one to buy is your choice depending on what you want to accomplish. If you are never going to need the extra controls that Infragistics has, go for Component Art, even though it costs more. Component Art follows the "keep it simple, stupid" mantra to which I would like to say "keep it cheap as well, stupid"


Component Art web controls

AJAX has been the buzzword of the industry for quite some time now, but coding in it has always been difficult. Writing code in JavaScript is not all that difficult but debugging the code is what's the most difficult part of AJAX. The second difficult part is training. I was looking at different components out there for ASP.NET when I came across Component Art.

I have seen Component Art ads in the MSDN magazine many times, but never paid much attention to it, until today. I decided to try it out and was completely blown away. If you ever have thought of doing AJAX and have been waiting for a tool, Component Art should definitely be on your short list. I have to admit I have not tried other tools out there, but I did check Infragistics, their live demos are not as polished as Component Art but I will still give it a try in a few days. Both companies pack 6 to 8 controls in their package and charge around $700. I think these tools are a bit pricy, but then you have to decide whether you want to be a rocket scientist or use the tools and move on. Bottom line, I think the controls are worth every penny given the kind of neat stuff you can do with it.


.NET Framework 3.0

There was too much confusion about the relationship between WinFX and .NET framework. In order to clear up the confusion, MS decided to unify all these technologies under one name i.e. .NET Framework. No more WinFX, the next version of .NET Framework will be 3.0 which would include all the WinFX technologies. Sweet... was my reaction until I found out that .NET Framework 3.0 internally will use Framework 2.0. Uhh!!!

Yes, I understand Microsoft's position on this, they have just released 2.0 and still fixing bugs and getting ready for SP1, they cannot expect customers to jump ships so soon from 2.0 to 3.0, hence they are going to keep the 2.0 Framework as is, and version all WinFX technologies as 3.0. During installation, the setup will detect the presence of 2.0 and will only install additional components. I am totally fine with them doing it for this release but I really want them to simplify and keep the entire stack under one version moving forward. It would be too confusing for developers working on different pieces to keep up with the version numbers. Hopefully they will get a lot of feedback from developers at TechEd and would clean up the versioning mess as well.


Cropper - Screen capture utility

I have always wanted a screen capture utility that would be really easy to use. My search was over when I downloaded Cropper. I think this is the ultimate screen capture utility. It is easy to use, you have tons of options and the best part for us geeks, it's written is C# and the entire source code is available. The highlight of the tool is, that you can select an area on the screen and double click to capture that area. You can choose from a number of output formats like jpeg, gif, png or the clipboard. All in all a very handy utility.


Men are from Mars, women from Venus?

Author: Lilly Wang

No, no, I am not talking about the different behavior, or habits, or thinking pattern between men and women, I am talking about the gender gaps when it comes to health.

I am reading an interesting article about the physical differences between men and women which can drastically affect the odds of getting a disease.  For that sake, men and women need to be treated differently - which is often referred to his and hers medicine.

Here are some facts of the gender gap listed in the article (written by Dawn MacKeen):

  • Heart disease - it strikes men at younger age but kills more women. 
  • Asthma - bulk of tthe patients are women;
  • Strokes - more men have strokes, yet 62% of the victims of fatal strokes are women;
  • Depression - before puberty, depression is about equally prevalent in boys and girls; by adulthood, however, depression is twice as common in females. Sad women are more likely to overeat and sleep too much, as well as ache from body pain.  But males are four times more likely to commit suicide;
  • Lung cancer - men suffer 60% of the death from it.  But the gender divide is shrinking (due to the fact that few men smoke these days)
  • Pain - males hold out pain longer than female; (hehe, we scream louder when pains come);
  • Rheumatoid arthristis - is twice as common in women as in men.
Well, looks like God is more in favor of men when it comes to health.  But women are better than men in other areas (oops, I start a war again...)