Archive for August, 2008

14 Aug 2008

Is Stackoverflow.com really a Web 2.0 site?

1 Comment Uncategorized

I have been lucky enough to be one of the few and many people that have had the chance to preview the beta of stackoverflow.com. It has a very nice look and feel in my opinion and seems to work very well for an early beta. Jeff Atwood deserves major kudos. However I have had one plaguing question?

Is stackoverflow.com really a Web 2.0 site?

I started thinking about this question a couple days ago, because as many of you know I have my own project, that isn’t much different functionality wise than stack overflow. As I started cataloging everything that a Web 2.0 site is suppose to consist of, the more I asked the question what is a Web 2.0 site, and is stackoverflow.com really one?

Tim O’Reilly defines Web 2.0 as the following:

Web 2.0 is the business revolution in the computer industry caused by the move to the Internet as platform, and an attempt to understand the rules for success on that new platform.

In my opinion a platform has the following characteristics and so does a Web 2.0.  There are probably many more, but these are the top 4.

  1. It must have a fluent interface.  (this is usually implemented through AJAX)
  2. It must have an externally available API.  (because a closed platform is what Web 1.0 was all about)
  3. Users can own data and have control over who sees it.
  4. It is an obvious advancement from the previous Web 1.0 version of the software if one exisited.

http://stackoverflow.com

Just as a precursor to the following discussion, I have never heard Jeff proclaim that stack overflow is a Web 2.0 site, so this is just my ramblings.  Jeff has also done an awesome job with the site in a short period of time so everything I am saying now will probably change in the future.

Stackoverflow.com has only really done #1 of the first 3.  However what I really want to have a discussion on is if it really has advanced it self enough beyond the old forum model to really be considered 2.0 worthy or is it just a display layer on the 1.0.  For all intents and purposes we are going to use the forums on ASP.NET for comparison.

  • Allows users to create posts? (both yes)
  • Allows users to create reply to the posts? (both yes)
  • Allows users to talk to each other? (asp.net only)
  • Allows users to rank posts? (both yes, but different mechanisms)
  • Allows users to rank replies to posts? (stackoverflow.com only)
  • Allows users to get a system ranking against other users? (both yes)
  • Allows users to tag posts? (both yes)
  • Allows users to tag replies? (asp.net only)
  • Allows users to mark a reply as an answer? (both yes)
  • Allows categorization of posts? (asp.net only)
  • Users aquire badges of honor in the system? (both yes)
  • Users can have a profile of themself and their activity? (both yes)
  • Can easily follow a posting? (asp.net only)
  • Can easily follow a grouping of posts? (asp.net only)
  • Allow users to delete posts? (stackoverflow.com only)
  • Allow users to delete replies? (stackoverflow.com only)

Using the above questions it makes stackoverflow.com look like it is playing catch up to the asp.net forums, which has had a 6 year head start.  But it still begs to ask the question is the technology and application of it worth of the title 2.0 or just 1.1?  I think Jeff needs to impliment the following beyond the typical forum to really claim that 2.0 title.

  • An external API (REST seems popular)
  • Become less of a destination and more of a service:
    • Render in other platforms. (Facebook and/or Open Social)
    • Allow posting and following via SMS and IM.
  • Allow users to follow certain tags, categorizations, users, etc. through RSS, JSON, XML, etc.

I do beleive that Jeff has a long way to go before stack overflow is considered an advancement beyond the standard forum, but if anybody can make that leap it is Jeff.

13 Aug 2008

Using a Parameter Attribute to set a Default Value in MVC

2 Comments Uncategorized

A couple days ago I came across a breaking change in ASP.NET MVC PR4 that wasn’t reported.  The breaking change is that defaults from routes are no longer used as defaults for parameters in the action method, if no appropriate parameter is found in the request.  Basically what this means is the following:

I have the following route:

URL: /home
Controller: Home
Action: Index
Defaults = page: 1

I set the page so that it always defaults to “1″ if no value is found in the query string for “page”.

So when a request is executed, the Route passes back the RouteData.Values = controller: “Home”, action: “Index”, page: 1. Then it goes through it’s normally processing and the value of the page’s query string is passed in to my action method for the page parameter. So if query string page = 1 then 1, query string page = 2 then 2, and so on. This is how it worked in PR3 and how I understood it was suppose to work as a concept.

However, in PR4, this doesn’t work anymore because of Line 166 in ControllerActionInvoker. It specifically checks that the value is in the route values. However they are always going to be in the route values if they have been defined as a default.

I reported it as a bug, because it was an obvious break from the last 3 preview releases and nothing was reported about this breaking change, and went on my merry way.  However today I received a message back from auriel confriming that this was the correct process flow, and that I should set the parameter either in my action method or the action filter.

So I decided to take this obvious disapointment and turn it in to something I have been thinking about for a long time, but never really had the motivation to impliment.  In .NET you are allowed to add attributes to anything that can be defined via reflection, including classes, interfaces, structures, and even return types and parameters of methods.  So I created an attribute called DefaultAttribute that is a parameter attribute that can be added to your action methods like this:

public ActionResult Index([Default(1)]int? page)

This method tells us that page has a default value of 1 if the value of page is null or undefined.  The DefaultAttribute is rather simplistic, because it is only suppose to hold the default value:

[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false)]
public class DefaultAttribute : Attribute
{
	public DefaultAttribute(object @default)
	{
		if (@default == null)
			throw new ArgumentNullException("default");

		Default = @default;
	}

	public object Default
	{
		get;
		private set;
	}
}

As you can see from the above code I have told the attribute to only allow it to be attached to a parameter by specifying this in the AttributeUsageAttribute.  The next and last thing that we need inorder to complete our goal of being able to set the defaults in a parameter attribute is an action filter that can read the DefaultAttribute from the parameter and set the default if the parameter value is null or undefined.  We are going to process the parameter defaults in an action filter called UseActionParameterDefaultAttribute that can be attached to the controller or direction to the action method.  The code to process the defaults is:

public override void OnActionExecuting(ActionExecutingContext filterContext)
{
	var defaults = GetDefaults(filterContext);
	var actionParameters = filterContext.ActionParameters;
	foreach (var value in defaults)
		if (actionParameters[value.Key] == null)
			actionParameters[value.Key] = value.Value;
}

internal static IDictionary>string, object< GetDefaults(ActionExecutingContext filterContext)
{
	string key = filterContext.ActionMethod.ToString() + "_ParameterDefaults";

	// get from application storage
	IDictionary>string, object< defaults = filterContext.HttpContext.Application[key] as IDictionary>string, object<;

	if (defaults == null)
	{
		defaults = new Dictionary>string, object<(filterContext.ActionParameters.Count);
		foreach (var parameter in filterContext.ActionMethod.GetParameters())
		{
			if (parameter.IsDefined(typeof(DefaultAttribute), false))
			{
				DefaultAttribute attr = parameter.GetCustomAttributes(typeof(DefaultAttribute), false)[0] as DefaultAttribute;
				string parameterName = parameter.Name;
				string actionName = filterContext.ActionMethod.Name;

				try
				{
					defaults.Add(parameterName, ConvertParameterType(attr.Default, parameter.ParameterType, parameterName, actionName));
				}
				catch (Exception exc)
				{
					throw new InvalidOperationException(String.Format(
						CultureInfo.CurrentUICulture,
						"The value of the DefaultAttribute could not be converted to the parameter '{0}' in action '{1}'.",
						parameterName, actionName), exc);
				}
			}
		}

		// add to application storage
		filterContext.HttpContext.Application[key] = defaults;
	}

	return defaults;
}

Each parameter of the action method is scanned for a DefaultAttribute and if found is added to the defaults dictionary to be used later when checking if each parameter is null or undefined in the OnActionExecuting method. Creating this code actually led to another request for the MVC team. The request was for a static storage collection for each action method so that compile-time code like attributes on the parameters don’t have to be processed with each request, since they can only possibly change when the code is recompiled. So I have my fingers crossed that they will actually implement this feature. In the mean time I implemented a application level storage for the parameter defaults so I don’t have to reprocess the parameters with each request.

I have added the two source files to my Google Code Project for Coder Journal, you can find them at:

12 Aug 2008

Visual Studio 2008 SP1 Released

No Comments Uncategorized

Visual Studio 2008 SP1

  • Improved WPF designers
  • SQL Server 2008 support
  • ADO.NET Entity Designer
  • Visual Basic and Visual C++ components and tools (including an MFC-based Office 2007 style ‘Ribbon’)
  • Visual Studio Team System Team Foundation Server (TFS) addresses customer feedback on version control usability and performance, email integration with work item tracking and full support for hosting on SQL Server 2008
  • Richer JavaScript support, enhanced AJAX and data tools, and Web site deployment improvements

The .NET Framework 3.5 SP1

  • Performance increases between 20-45% for WPF-based applications – without having to change any code
  • WCF improvements that give developers more control over the way they access data and services
  • Streamlined installation experience for client applications
  • Improvements in the area of data platform, such as the ADO.NET Entity Framework, ADO.NET Data Services and support for SQL Server 2008’s new features

Team Foundation Server 2008 SP1

A number of improvements have been made to Visual Studio Team System 2008 Team Foundation including:

Version Control

  • Simplified the user experience through cleaner “Add to Source Control” dialogs, drag and drop support to the Source Control Explorer and a much easier to use “Workspace” dialog for working folder mappings.
  • Version control now automatically supports non-solution controlled files.
  • Various changes to the Source Control Explorer such as a new checkin date/time display column, local path hyperlink support and en editable source location field.

Work Item Tracking

  • Microsoft Office 2007 integration is now done using the standard Office “Ribbon” delivering a cleaner and easier to use integration to the different Microsoft Office 2007 products.
  • Email integration for work items and links for Team system Web Access to make it easier to use email as part of the development lifecycle.

Visual SourceSafe migration tool

  • The migration tool has been dramatically improved through many performance and reliability improvements. SP1 provides support for the elimination of namespace conflicts, automatic solution rebinding, improves timestamp coherency and increases the amount of migration logging information available.

Additional Features

  • Support for using SQL Server 2008 with Team Foundation Server.
  • Team System Web Access provides “live” links to work items and checkin emails. This improves the customer experience for users who do not use Team Explorer.
  • Scripting support for the creation of Team Projects.

Performance and scalability

  • With SP1 a large part of the focus was to improve the performance and scalability of Team Foundation Server through changes such as faster synchronization with Active Directory, improved checkin concurrency, a faster way to create source tree branches, online index rebuilding for less maintenance downtime and better support for very large checkin sets.
  • Improvements in the number of projects a server can support that make not only the scalability of the server better but also the client experience when connecting to a server with a large number of projects on it.

During the install, of TFS 2008 SP1, I received the error: Failed to call WMI on the RS server.  I did some searching on Google and found a post that I did back in November on the same problem.  I followed my exact same steps and it fixed the issue.  I don’t know why this DNS issue continues to cause Microsoft problems, but I really wish they would fix this bug.