Plip's Weblog

Phil Winstanley - British .NET chap based in Lancashire. Enjoys tea and tech. Working for Microsoft.

December 2007 - Posts

Merry Christmas

I got into the festive spirit as you can see.

 

 

See you in 2008. :)

 

Phil.

History Repeating

 

New York 1776

 

King George III's Statue

 

Hungary - 1956

 

Stalin Statue

 

Baghdad - 2003

 

Saddam's Statue

 

I wonder who's next ....

Opera, the EC and Microsoft.

The European Commission are having to investigate Microsoft again, this time it's not Media Player but Internet Explorer which is getting it in the neck.

http://news.bbc.co.uk/1/hi/technology/7143912.stm

I have installed on my machine IE, Firefox and Safari. I'm a web developer, I expect to have lots of browsers. The average man on the street however has an icon on his desktop called "Internet", it opens the Internet. I imagine the vast majority of Internet users don't even know other browsers exist or even understand what a browser is.

Now, is if fair that Microsoft's Internet Explorer is the only browser shipped with the Operating System? To answer that, I think the question needs to be rephrased. Is it fair to Opera or Firefox? No. Is it fair to the users of Windows? I'd say yes; if my above statement is close to the mark, that users just want things to work then more choice can only be a bad thing.

The browser statistics at W3 Schools is interesting to read: -

http://www.w3schools.com/browsers/browsers_stats.asp

I think my tax money could be much better spent than being frivolously wasted on legal action against Microsoft.

Thoughts?

 

</whinge>

Is MVC right for you?

With the imminent release of the ASP.NET MVC Framework, I thought I'd explore some of the arguments behind using it.

This post will invariably be contentious and cause a ripple of indignation amongst the proponents of the MVC approach but I feel it's important to explore the arguments behind adoption of the new model as well as the technical and emotional implications of moving to the new development process.

One thing that has irritated me about the discussions which have spawned from the publication of details around the MVC framework is the smear campaign which has been started around the Web Forms model. I strongly support the Web Forms model and believe that the majority of the flaws in Web Forms that MVC purports to overcome are easily solvable by following the guidance and advice of experienced ASP.NET developers.

I want to bring the argument out of academia which is where it's been relishing in it's position for some weeks and back into the real world of actual day to day development.

So to help explore some of the propaganda issues raised by the MVC crowd we'll look at each of the arguments in depth (how deep will be determined by the appropriate level of rage it incites in me).

 

MVC is to Web Forms as Incarceration is to Liberty

It's true, MVC is not the model for people who want the freedom to be creative with their code. It's the pattern you follow if you want to conform with a particular doctrine of programming. There is (if you follow it to the letter of the law) not a huge degree of flexibility.

This is just the nature of the beast, it's designed in a way which not only encourages you, but in many cases, forces you to program in a certain way. Now, that can be a good thing, some of the ASP.NET code I've seen in my time has literally made me cry it's been so badly constructed.

With Web Forms as a developer, you're pretty much free to follow the path which suits you best. It works with both your level of knowledge and your approach to building Web Applications and allows you to do what's best for you. It helps you achieve your end goal by not obstructing you along the way.

lib·er·ty

–noun, plural -ties.

freedom from control, interference, obligation, restriction, hampering conditions, etc.; power or right of doing, thinking, speaking, etc., according to choice.

MVC forces these patterns on to you for good reasons, if there's only one way of doing things, there's only one thing to learn and only one set of advice to follow. No confusion, no misunderstanding, anyone can pick up the code you write and should be able to instantly understand it if they understand MVC. That's the theory anyway. In reality, you as a developer can still put code in the wrong place, you can still make bad decisions on how to structure your application and you can still essentially cock the whole thing up.

in·car·cer·ate 

–verb (used with object)

to imprison; confine; enclose; constrict closely.

The argument that you cannot achieve a level of maintainability and testability with Web Forms is not only misplaced, I believe it's fundamentally wrong.

If your Web Forms applications are written in a well structured way, where you separate out your Business Logic from your Presentation and where you're clearly defining the so called boundaries around tiers, then your application is in my mind as maintainabl4e as one following the MVC model to the letter, with one very important difference. You can take advantage of the full control framework with Web Forms which to date just doesn't exist with MVC. The time saving of control is I believe of fundamental importance.

"If you want a model that pretty much *forces you* to write your application in a way that is testable, maintainable, and pluggable, MVC is great."

It's very much an argument which closely follows the views of the two main political parties here in the UK. I'm sure that's just a coincidence though...

Here's what the Conservative Party say: -

Giving people more opportunity and power over their lives

In our open and dynamic world people's horizons are broader: their ambitions are greater, and they expect to be able to make more and more decisions for themselves. Government, politics and public services need to catch up.

Here's the approach the Labour party takes: -

The Labour Party is a democratic socialist party. It believes that by the strength of our common endeavour we achieve more than we achieve alone, so as to create for each of us the means to realise our true potential and for all of us a community in which power, wealth and opportunity are in the hands of the many, not the few.

Does that mean Web Forms is a more Conservative approach compared to the Socialist approach of MVC? Possibly. For reference, I'm neither a Conservative or a Socialist, I'm a Liberal.

I do however digress, let's return to the real world aspects of this.

 

MVC makes testing your applications possible

 

I'd agree testing is hard with Web Forms. In fact, I found it so difficult I abandoned trying to unit test my ASP.NET code and moved to a process of using Watir and testing the rendered HTML instead.

 

Now, I don't know how many .NET developers (and I'll include all .NET developers here, not just us superior Web types) perform unit testing but if I were to take a conservative guess, I'd probably put it at less than 1% of all .NET developers who unit test (I'd love it if I were wrong - but I fear I might even be being a little adventurous with those figures).

 

If people adopt MVC and consequently begin testing their web applications, MVC has done more for ASP.NET than four or five years of Test proponents like Andrew Stopford banging on about MbUnit has done; that can only be a good thing. However, if people adopt MVC and then consequently do not begin Unit testing their code, what's the point? Are the so called Maintenance and HTML/URL control benefits worth loosing all the Web Forms goodness? It's an interest point, one to which I do not know the answer.

 

Applications written using MVC will be more maintainable

 

Can't see the Code for the Patterns. Every developer has a way that they write code. A signature if you will, where you can pick up code and say - "This look's like Bob's work".

"It isn't impossible to achieve maintainability and separation with WebForms but it doesn't make life easy and leaves you to roll something yourself or follow a Patterns & Practices recommendation."

The quote above is from an internal Microsoft discussion list. I think it's very true. Those of us who have been building ASP.NET professionally for years are now in a position where it is easy. We have our pattern to follow and we know how to build good maintainable ASP.NET applications.

Structure and form becomes an integral part of our Web Forms applications.

If we're already following those methodologies, does MVC offer us anything more? One thing it does offer is conformity. Everyone will create MVC applications in the same way (I hope).

 

Learning curve

 

Teaching people ASP.NET isn't an easy thing to do because of the sheer size and architecture. There's the .NET Framework, ASP.NET on top of that, the Languages you might use to program against .NET and ASP.NET and then of course there's the implementation of the platform you're using. It's a huge amount to learn.

Luckily, one thing I've found with ASP.NET Web Forms is that you can teach people a small amount at a time and they can over a period of time incrementally build their knowledge of the platform. It's quite a smooth learning curve in my opinion.

 

What does this smooth curve mean? Well, for a start, people generally aren't that afraid of having a go, the concepts being shown to them aren't overwhelming (once you've convinced them to use C# and not VB.NET ;) ). The smoothness of the curve means people can learn just what they need to learn to do the job.

With the mass of technical articles, blog posts and snippets out there around ASP.NET Web Forms one other great advantage is that almost any problem you can face with ASP.NET will be documented and the solutions listed somewhere on the Web, it's just a matter of searching for them.

"Programmers more than nearly any other demographic, despise change. Programmers not only despise change, they run from it and tell other people that change will kill them as they trample innocent bystanders."

MVC, I fear, won't have this same curve.

If you're used to ASP.NET Web Forms and move to the MVC approach, so much of the knowledge you've gained (lovingly) over the years of ASP.NET development is effectively lost. You have to start again. Whilst the language, platform and the IDE are the same, that's pretty much it. The controls you use today aren't there, the way that you structure the events that happen in your pages no longer work that way, pretty much everything is different. It's a complete shift in the way you'll build your applications.

MVC needs you to learn everything in one go, whereas Web Forms allows you to incrementally build up your knowledge.

 

Inline Code (shudder) and control over your HTML and JavaScript with MVC

I've spoken with ASP.NET authors, trainers and speakers over the past few weeks and months about MVC and one thing comes up again and again in conversation. We as a community have spent years persuading developer that inline code is not only bad, but in fact bordering on evil. The mess that Classic ASP pages could get into because of nothing more than inline code was not only shockingly prevalent within the Classic ASP community but also was a massive overhead on maintaining applications.

One thing the MVC guys talk about is the separation of concerns which refers to the way in which you have the "model" and the "view" and the "controller" (MVC!); whilst they bang on about this, the separation of markup from code is completely disregarded as a non issue.

There are a set of MVCToolkit HTML Helpers which make life easier when constructing what we'd recognise as controls but again, it's for some, a shift in thinking again.

Inline code makes me very wary, whenever I see someone sneaking it into an ASP.NET page they get a good bollocking about it.

 

In Summary

I fully support the creation of the MVC framework and the ASP.NET implementation of it. I believe for a small minority of ASP.NET developers, it will being them huge benefits. I will personally be using and evaluating the MVC Framework over the coming weeks and months to continue to expand my knowledge of the processes and techniques required to build well formed MVC applications.

I'd encourage all ASP.NET developers to follow the posts Scott has been putting up about the MVC framework and give it a shot. It's got many advantages as we've gone through here. There's a phrase I've heard a few times, I believe it has an American origin. It seems to be quite apt when talking about the MVC Framework.

 

"Your Mileage may vary"

 

So, to summarise: -

  • It's important that people understand Web Forms are not being abandoned by Microsoft.
  • MVC is not perfect.
  • MVC is not easy (if you're a Web Forms person already).
  • You will have a choice moving forward of using Web Forms or MVC with you applications.

 

Please, if you're going to flame me, let me know first and I'll turn off the central heating.

Ta,

Phil.

 

Technorati Tags: , ,
Importing data into the ASP.NET profile table

 

I had a requirement to bring a bunch of data into the ASP.NET Profile table from a data export.

After some reading about the format of the PropertyValuesString table on 4guysfromrolla.com: -

http://aspnet.4guysfromrolla.com/demos/printPage.aspx?path=/articles/101106-1.aspx

I was able to come up with the following bit of SQL: -

INSERT INTO dbo.aspnet_Profile
(UserId,PropertyNames,PropertyValuesString,PropertyValuesBinary,LastUpdatedDate)

SELECT U.UserId, 'FullName:S:0:' + Convert(VarChar,LEN(RTRIM(C.[Contact Name]))) + ':' As PropertyNames, C.[Contact Name] As PropertyValuesString, 0x As PropertyValuesBinary, GetDate() As LastUpdatedDate
FROM Contacts$ C
    JOIN aspnet_Users U
        ON C.[Email Name] = U.UserName collate SQL_Latin1_General_CP1_CI_AS
WHERE NOT U.UserId IN (SELECT UserId FROM dbo.aspnet_Profile)

Thought this might be useful to share. Obviously this is structured for my own Profile which has but one column.

Thanks,

Phil.

Vista solves world energy crisis

This is a 100% Non-Photoshopped screen shot.

VistaPowerPlan

More Posts