Why learning new technology is important


I was originally going to focus on build or buy when I started this blog entry. This morning, however, I was running through some website code and found a custom skinning engine and a custom membership/roles methodology (not a set of custom providers). The whole thing uses rather elabortate code to determine the look and feel of the site, as well as determine menu options (based on roles).

As usual, I am more inclined to head towards the K.I.S.S. principle (Keep It Simple Stupid). And, since Microsoft took time to add funcationality to ASP.NET for these types of items, I wanted to see if it was simpler, and potentially less error prone, than the current methodology.

First step: Try to skin the site

For this part of the exercise, I created two theme folders with simple css files. Nothing extravagant at this time. I then looked at the requirements of the site (how to determine theme) and started to work.

First, I added the following urls to my hosts file (%windir%/system32/drivers/etc).

127.0.0.1     site1.mySite.com
127.0.0.1     www.mySite.com
127.0.0.1     beta.mySite.com
127.0.0.1     site2.mySite.com
127.0.0.1     mySite.com

I then added the above host headers to my local IIS instance. I could then test the site with www.mysite.com/myweb or beta.mysite.com/myweb, etc.

The next step was a bit of code. I had to pull the host name and get the actual host (in normal domain nomenclature, the site is set up in the format: host.domain.topLevelDomain – Example: in site1.mySite.com  site1 = host, mySite = domain, com = topLevelDomain.). I just wanted the host. This was done easily with the following code:

        Uri uri = Request.Url;
        string host = uri.Host;

The host, in ASP.NET contains the full string (site1.mySite.com). This has to do with the concept of "host headers" in IIS, thus the word has two names. I only want the first part, so I am going to split it.

        if (host != null)
        {
            string[] hostSplit = host.Split(".".ToCharArray());

 I can then grab item 0 and use it to figure out which host the person is using. As I might want to reuse this functionality elsewhere (determining host), I am placing this routine into a helper library. Currently, this is not static (for ease) as I do not want to instantiate a Session object to set things. I would normally have a static routine, but this is just a simple test to see if this is possible.

    public void SetTheme(string host)
    {
        switch (host.ToLower())
        {
            case "www":
            case "beta":
            case "test":
            case "mysite":
            case "localhost":
                Session["Theme"] = "microtrak";
                break;
                
            default:
                Session["Theme"] = host;
                break;
        }
    }

Ultimately, I will switch this to pull from a database, but the current app has no concept of an application in the database schema, so I will have to add it to pull from there. As it requires a schema change and refactoring should be done in baby steps, I am not going to tackle this monster right now.

To set the theme, I create a default.aspx page and add a PreInit method.

    protected void Page_PreInit()
    {
        string theme = Session["Theme"].ToString();

        if (theme == null)
        {
            Session["Theme"] = "microtrak";
            theme = "microtrak";
        }

        this.Theme = theme;
    }

Finally, I open the body {} style in the css files and give it a different background color in each. I now have a working site that is themed.

Next: Providers

The next task is to set up providers for membership, roles and profile to match the database schema.

The Point?

The concept of themes has been around for quite a few years. The same is true of the Provider model. If you learn technology, rather than plod on ignorantly (which might be called stupid), you would know what is out there. Don’t get me wrong, there are times when you need to "reinvent the wheel" as the current wheel does not fit your needs and tailoring it to your needs would just create a kludgy wheel. But, more times than not, using technology will help you avoid the pain, and expense, of writing tons of custom software.

The story is actually a bit worse than what I have touched on thus far. I was not going to go into details, but I feel this is a good learning opportunity, as well.

The site I am retooling was actually based on another site’s code. Much like "based on a true story" in Hollywood, there is little resemblance to the original site in the current site. The original HAD providers. They could have afforded a refactoring to custom providers, but they were working. And, they were ripped out. The original site could have been refactored with themes, but the developer decided to build his own. The moral of this story: Don’t rip things out just because you do not understand them; gain some understanding first. You might still rip some stuff out, but you will be doing it in an intelligent manner.

Advertisements

Have you bitten the beta bug?


Kathleen Dollard, whom I concider a dear friend, wrote an guest opinion in VSM recently. Her premise? The pace of change in technology is so rapid that it is leaving everyone in the dust and nobody is competent to write software any more. In 2004, she mentioned that Visual Studio 2005 was leaving the hobbiest programmer in the dust (guest opinion here). And, even Rocky Lhotka spoke out in 2006 that software was too hard (guest opinion here).

While the picture is not completely bleak, the crux of the matter is the technology is outpacing the tools. In the past few years, we have seen major changes to ASP.NET and the .NET Framework. Add on top of that WPF, WF (originally WWF, but it soundy to "wrestly") WCF, and CardSpace. We now have Silverlight (once WPF/E), LINQ, ADO.NET Entity Framework (soon to be dubbed with a catchy Gen X marketing label?) and XAML has grown up before our eyes to take on new tasks. Unfortunately, the tools have not kept up.

Expression Web Designer is a great tool for creating CSS compliant sites, but the tool has more features than it can support. One of its nicest features, the Expressions, does not aid the user in placing "expressions" into web.config or .resx files. In fact, EWD is absolutely no help in this regard, leaving the poor designer that does not want to hard code in the lurch. In fact, EWD does a really bad job of ASP.NET, outside of the few controls the developers have focused on. To date, Microsoft has not created an SDK for those wishing to extend EWD.

Silverlight is already in a 1.1 "alpha" release and the only way to design without writing huge amounts of XAML is to download a CTP of the next version of Expression Blend, or possibly Visual Studio Orcas, although Orcas currently only supports the Silverlight 1.0 beta. I wonder if the Expression products will catch up with the infrastructure some time this year. Perhaps, as they also have May Preview (CTP?) releases of blend, the media encoder, etc. As Microsoft is trying not to break interfaces on released bits, it may end up a bit bloated by release, but it is more likely they will hone it down, as they have not really released anything to RTM yet. Since 1.0 is still beta, as well, it is more likely those tasting the water this early will end up getting scalded.

On a positive note here, some Third party vendors are stepping up to the plate to fill in where Microsoft is lagging. Telerik has it’s first set of R.A.D. controls for Silverlight, although they are currently more eye candy than anything else (cube pictures). Infragistics has WPF controls, but they are currently focused on windows forms and xbap applications (pre-Silverlight browser applications).

Serious WPF "smart client" (dubbed "windows client" in the latest presentations) can be developed in Visual Studio, but the current bits are in an early beta stage (November 2006). "Acropolis" was released earlier this month to help those who want to develop WPF applications, but it is early CTP and only contains one "template". Microsoft promises more "templates" over the summer, but when will the template designer come out. For those not needing the themes, there is also "Cider", the WPF designer. This is set to release with the next version of Visual Studio, dubbed Visual Studio "large dolphin" (aka "Orcas" – NOTE: Orcas here is actually an Island, not a mammal).

And what about SQL Server? SQL Server 2008 (formerly code name "Katmai") was released in CTP form at TechEd this year. You can download it from connect right now. In this gem, we have the ADO.NET Entity Framework, including links to LINQ. On top of that, Visual Studio "Orcas" has bits for LINQ and there is "Japser", which is designed to help us rapidly develop data driven apps.

And what about ADO.NET AJAX? Asynch applications are a reality, but you have to write an awful lot of code unless you pop into the "futures market". Fortunately, some of the third party vendors have developed AJAX aware controls that rock. Telerik, DevExpress, Syncfusion, ComponentArt , Obout, and Infragistics all do a great job in this respect. I am sure there are others, but I have not gotten the bits for others yet. I will get a chance to post my reviews of these products by the end of the year … hopefully.

What is most interesting, to me, is Micrsoft is currently competing with itself, both in tools and frameworks. Hopefully the different groups are speaking to each other and we will not end up having to buy a plethora of tools to get all of the bits.

If you have not been bitten by one of the beta bugs (or perhaps CTP bugs or alpha bugs or preview bugs), you are going to get left behind. If the tools catch up, this will not be too bad, as you can drag and drop your way through the minefield later. Unless, of course, Microsoft’s underlying architecture continues to develop at a leopard’s pace.