Today I received an email that has started this year off very well. Microsoft has honored me by re-awarding me with an MVP award in the area of ASP.NET this year. Thank you Microsoft.
Congratulations! We are pleased to present you with the 2010 Microsoft® MVP Award! This award is given to exceptional technical community leaders who actively share their high quality, real world expertise with others. We appreciate your outstanding contributions in ASP/ASP.NET technical communities during the past year.
I intend to continue working towards a better community. I hope everyone else is as well.
HAPPY NEW YEAR!
Anyone who has ever run a web site or a blog has probably taken a look at analytics packages to see who is visiting. I’ve recently been working on a very exciting project with Telerik, developing an application to provide this valuable information to bloggers and content creators.
To get things started we decided to tackle some of the basics first by asking these few questions:
- “How many people are visiting my site?”
- “Which locations drive the most traffic to my site?”
- “What is my most popular content?”
- “Who are the people visiting my site?”
From these simple questions we were able to start the application and get the cool demo set up that we were showing at the Telerik booth during PDC 2009.
The application is based around answering these four fundamental questions which are used to present the information to the users.
Site Visit Information
Most Trafficked Portions
I had a great opportunity to speak with Todd Anglin about the project at PDC last month. My discussion of the Silverlight Web Analytics Application is available for viewing on Telerik TV. This demo of the application is a great way to see what we’re working on and give you an idea of what is coming soon.
Subscribe to my RSS feed and come back to read more as I will be posting about the architecture and some of the design decisions we made about the application.
Reference types were created to make dealing with pointers a little bit easier. They hide away the details of the pointers, so that the programmer need not think about them. In many ways I think they’re awesome, because they really achieve that goal. The problem is that by abstracting away the details of the pointers they’re sometimes difficult to work with, because they can be a little bit confusing.
I received a comment about this topic on one of my ASP Alliance articles explaining value types and reference types in C#.
First of all the article is excellent.
But why the following program produces output as:: abc:xyz
it should produce xyz:xyz.
I am confused...Plz help
string myName = "abc";
string authorName = null;
authorName = myName;
authorName = "xyz";
The Actual Output:
The Expected Output:
as it's areference type only one copy is shared between references.
How about if we take this step by step looking at the variables and their values, and I’ll be able to explain why the behavior is as you’ve found. First here is the code we’ll be looking at.
string myName = "Brendan";
string authorName = null;
authorName = myName;
authorName = "Enrick";
We are expecting it to print out “Brendan:Enrick”.
Red is for the variables and orange is for referenced values for those variables.
Notice that when we set a variable equal to a literal string value we get a new location in memory, but when we set it equal to another variable all we are doing is copying the pointer to that memory location. However, when we then set that variable equal to a new literal value it doesn’t replace the old one for both since they each had a pointer. It just creates a new location in memory with that value and assigns a pointer to that variable.
The type of behavior that the writer of this code was trying to achieve could be handled by pointers very easily, but reference types take away control of pointers. Loss of freedom for the sake of safety one might say. Now that I’ve said that everyone will switch back to using c++ to get their pointers back.
Thank you for asking the questions saurabh. I hope this thoroughly answers your question. If you have any more, please feel free to ask them as well.
Earlier, I wrote a post about using inheritance with Silverlight UserControls. The post shows really quickly how one can have their UserControl inherit from another class. One tip I’ll mention is that the base class can be abstract, but not if you plan on using Expression Blend. Generally if you have a class which shouldn’t ever be instantiate, you should make it abstract.
The issue is one that I discovered, much to my annoyance, the hard way. As it turns out Expression Blend is currently unable to give a preview of a UserControl that is inheriting from an abstract base class. When you open one of these in Blend you’ll get the Red Box of Death and in it is a message stating, “Exception: Cannot create an instance of “MyClass”.
Not exactly very helpful, but it does at least point you to the fact that there is something wrong with your base class. If you run into this make sure you know that you cannot use a base class. I believe that Blend requires a default constructor, and an abstract class has no constructors.
If you have control of the abstract class, you probably just want to make it a concrete class and hope no one is dumb enough to use it as a concrete class. This is actually a good place for a comment so you have a reminder of why the class is not abstract. Otherwise you might make it abstract again. The comment will also tip someone off that they can make it abstract if Blend ever supports this.
If you don’t have control of the abstract class, perhaps because it is in a class library you’re referencing, you will want to place a concrete class between your class and the abstract. This new class will be the one you specify in your XAML and is thus used by Expression Blend. This one adds an extra layer which really adds nothing and could cause confusion, so I would lean towards the other solution.
One way in which we object-oriented developers try to achieve code reuse is by using inheritance. This allows us to have shared functionality in one place. Awesome we all know how to do this and it’s easy right? Try it in Silverlight for your UserControls. It is a little bit more challenging.
The problem we have is that we’re working with partial classes and these classes are trying to make things difficult for us. One of them is the noticeably declared one in the code behind file. The other one is created from the XAML file. The XAML file declares the base class it is inheriting from. In this instance it is the UserControl class.
Here are the steps required to use a different base class for your UserControls in Silverlight.
1. Create a class inheriting from UserControl and add your desired extras to the class.
2. Create a normal UserControl class and change the base class in the XAML file. You will need to declare an xml namespace for the namespace your base class is in, and use that namespace when declaring the base class.
<Grid x:Name="LayoutRoot" Background="White">
3. Change the inheritance in the code behind (.cs or .vb) file so that it is using the new base class. [Optional – Because of the way partials work you don’t need to declare this one as inheriting from the base class, but it does make things more obvious for someone using the code.]
Enjoy using your base class in Silverlight.