Nov 13 2009

.NET vs .NET (a quick performance test)

Category: .NET | Frameworks | Visual StudioJonathan @ 06:51

Since we can target our code to a specific compiler and target the platform of our choice, I thought it would be fun to see what sort of differences in speed, it would bring up.

I did two tests. First I looped through integer values, the columns on the left and then object assignments for the column on the right. For the object assignment, I created a simple class with a string property, created the class and set the property in the loop. Interestingly there were some differences.

The object assignment is obviously a large percentage of what we do in an object oriented world. Visual Studio 2010 was a lot slower than 2008 all round, but did perform decently for .NET 4.0. However small this simple test is it shows quicker times from 2008, and it shows that 2010 suddenly improves when using .NET 4.0. It took around 25 seconds longer to create the objects targeting the .NET Framework 3.5 using VS 2010, than VS 2008.

The test was done in Debug mode, Vista 64.

integer loop
2.0 2008 3.0 2008 3.5 2008
2.7735668 2.7634976 2.7670054
2.7659806 2.7567702 2.771937
2.7700194 2.7612681 2.7782053
2.7697211 2.7606385 2.7811199
2.7750242 2.7747622 2.7802291
13.8543121 13.8169366 13.8784967
2.0 2010 3.0 2010 3.5 2010 4.0 2010
2.7465096 2.7569809 2.7655086 2.734276
2.7577021 2.7531411 2.7583006 2.753255
2.7505392 2.7429336 2.7568989 2.753271
2.741854 2.7503117 2.7655838 2.761961
2.740013 2.7474619 2.7784012 2.759656
13.7366179 13.7508292 13.8246931 13.76242


object creation, string property assignment
2.0 2008 3.0 2008 3.5 2008
15.9305226 15.38386 15.8581671
15.2397368 14.59608 14.7847291
15.1368118 14.7387 14.6265273
14.7425454 15.42782 14.5719368
14.7806622 15.25851 14.9774767
75.8302788 75.40496 74.818837
2.0 2010 3.0 2010 3.5 2010 4.0 2010
20.3244424 20.76454 20.7134072 18.37988
20.2770724 20.61586 20.8497297 18.04806
21.2592798 20.74874 20.856723 18.32123
20.5916017 20.64923 20.897214 18.62922
20.3946783 20.61862 20.7991 18.42922
102.8470746 103.397 104.116174 91.80762

Tags: , ,

Nov 13 2009

Converting an Enterprise Level App from VS 2008 to 2010

Category: .NET | Frameworks | Visual StudioJonathan @ 02:53


The Wizard opened straight away, I clicked next.
After a few popup dialogs, requesting from me things such as Can't find the source control, remove source control binding? and would you like to upgrade the web projects to .NET 4.0?, which I responded yes to all.

The first problem came when the web project tried to bind to IIS, but failed. the wizard asked if I would like to create the virtual folder, I said yes and it failed, since it already existed. Accepting this to be a fair point, I created a new IIS Application, mapped to my project, edited the project file (right click on the project which failed to load) and selected Edit Project file. The edit context menu is a simply but great new useful feature.

I then reloaded the project from the same context menu and it loaded perfectly.

Running the application worked first time. I ran our manual Sanity Test, our automatic unit tests and all passed first time.

In short, upgrading the web app to .NET 4.0 upgraded and ran perfectly well.
but what would it do if I changed the target platform back to 3.5?

I went directly to the project properties and changed the target platform to 3.5, at which point I was informed that a project reload was required.
I then went through all 16 projects in the solution. Some had changed to 3.5, some were still on 4.0. I changed all projects to 2.5, compiled and ran.

The first Error

I got the following error:
"Could not load file or assembly 'xxx' or one of its dependencies. This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded."

Oops, I missed one.
I changed the version to 3.5, rebuilt. Still error.

What happened was all the projects hooked up to Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll - refused to change to version 2.*. The project reverted back to version 4.0, and I could not keep it in 3.5.
Eventually, after trying tons of manual attempts to reference alternative versions, rebuild etc, nothing worked and I was done.

Start from the top

I decided to start from scratch, get my backup up and start the wizard from scratch, this time, not upgrading to 4.0 from the get-go.

After repeating the exercise and not moving to .NET 4.0, I discovered that all the UnitTestFramework dependent projects had been forced to version 4.0 and I got the same error as before.

You can view the problem on Microsoft Connect, and as I did, discover that not much of a solve has been written there. (Please leave your feedback on the site)

STOP. It is a shame that one would consider the .NET Unit Testing Framework to be such a small piece of the whole 2010 pie, was the reason I cannot upgrade an Enterprise project. Not good for test first is it?

[Let me just point out that Visual Studio .NET 2010 is in Beta 2, at the time of this post]

Tags: , , ,

Nov 6 2009

First Look at VS.NET 2010 (for me)

Category: Visual StudioJonathan @ 02:09

I don't have time for a large introduction to this post, rather I'll jump straight in and tell you about the things that I picked up on.

- The start page, with its now big button, lots of padding approach, seem wasted space, especially on any wide screen monitors. the start page for VS.NET 2008 wasn't anything great, but you had the recent projects, some news and other bits all accessible with one click. A minor thing, but its not a better start page.

- The skinned look. This was a complete waste of time, in my opinion and in fact makes the experience in visual studio worse. With the extra padding, now around all the toolbars (the same width as the splitters), it makes everything seem smaller, and it is. The dragging of the toolbars are much cleaner, smoother than 2008.

I don't like the way the treeview lines and arrows disappear when it has no focus. If it is a setting, I could not find it, but now I cannot at a glance see if a folder has something in it vs one that does. A small point, but means you have to move the mouse and wait for the lines to fade in.

- The code editor now has filtering on what you type in the intelli-sense. Before it simply took you to the correct item in the intelli-sense window, now it removes entries that do not match. This is a massive negative point, as I use the intelli-sense as a browser as well.

- The code editor, firstly which is a major plus, is the selection highlight. Now it is not an inversion of text colour, with blue selection background, it is a translucent colour, which keeps the text colour as it is, untouched. This simple thing is a massive improvement.

- Unfortunately there is a microsecond delay now over 2008 when typing. Each character you type appears that little more slowly, which actually took me a while to get over. It was actually annoying to me. I know I am quite sensitive about it, but I think others will also have picked up on it.

- The skin colour of dark blue with white text on the tabs, now distract me. I always have a black windowed code editor, not the usual white. But now, the toolbar tabs for each file is more visible in my peripheral vision as I type in the editor. This is also distracting.

- The round break point icons in the margin is now that fraction smaller, which I don't like, but can live with.

- Overall, the skin has introduced too much contrast. It is much more stand out as an interface, which is better to look at, but worse to code in.

Why does Visual Basic appear on the root, and c# in 'Other Languages' - on new Project Dialog? Is this a VB editor, then if we are lucky some other languages? I thought .NET was about multi-language.
1. Visual Basic
2. Other Languages
3. Other project Types
4. Test projects


Tags:

Aug 20 2009

An ASP.NET web root link handler

Category: .NET | asp.net | c# | Visual StudioJonathan @ 02:56
In order to get a useful, all purpose, all use client-side href link back to root, from anywhere down the web folder structure, and paying attention to IIS6, IIS7, Cassini and other Visual Studio internal web hosting scenarious and of course the odd bug within ASP.NET and your own web site code, I created a handler for ~/.


Here is the html I wanted.


<a href="~/">Some link to root of site</a>



public class RootHandler : IHttpHandler
    {
        #region IHttpHandler Members

        public bool IsReusable
        {
            get { return true; }
        }

        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            string toUrl = context.Request.ApplicationPath;
            context.Response.Redirect(toUrl);
            context.Response.End();
        }

        #endregion
    }


    <handlers>
      <remove name="root"/>
      <add name="root" verb="*" path="~/" type="Namespace.RootHandler, Assembly"/>   
    </handlers>


Then with a little more code in the ProcessRequest method, you could find the ~/ part of the url, strip it down and modify the url.


        public void ProcessRequest(HttpContext context)
        {
            context.Response.Clear();
            
            string toUrl = context.Request.ApplicationPath + "/";
            string url = context.Request.RawUrl;

            int idx = url.LastIndexOf("~/");

            url = url.Substring(idx + 2);
            
            url = VirtualPathUtility.Combine(toUrl, url);

            context.Response.Redirect(url);
            context.Response.End();
        }


It is only with .NET Framework 3.5, where HttpHandlers have gotten to an acceptable bug free level for use.

Warning: this is a simplistic example for purpose of this post, please be careful in production scenarios.

Tags: , ,

Jul 23 2009

ASP.NET Framework Should Haves

Category: .NET | asp.net | c# | Design | Development Tools | Visual StudioJonathan @ 05:53


ASP.NET should have been a plug-in from the start. The IIS Handler, should have been split into (.NET with ASP.NET) and (.NET without ASP.NET). The idea of a config file and a WebConfigurationManager is not and should not have been specific to ASP.NET.

One cannot help but feel that ASP.NET was designed with Web Server Controls as the flagship feature. "Create that 3rd party market for web". No real thought paid into how people actually use the web on simple terms.

What I am writing here, probably resembled the paper David Heinemeier Hansson scribbled on when thinking and designing Ruby on Rails, but I have no intention of mapping features, just stating the obvious.

Get Server returns html
Post Server *saves data and returns html
Querystring may change what code is executed, and change the "context"
Url may require changing, remapping, extension changes etc

Now, to do this in ASP.NET is relatively straight forward?
Yes it is, simple enough to do each thing, but it gets more complicated when you want all these ideas together.

There is also a grey area as to what we should call easy. Yes it's easy to do x, but is it simple and will it remain simple as time goes by.
The minute you start asking some questions, ASP.NET starts to give varying levels of success. What if it was posted from a different server? What if the html had to be static and not dynamic? what if you need to create your own physical files and return those to the browser? What if you did not want an aspx page at all? What if your new Module wants to create the Page (HttpHandler)

Asp.NET is far too cluttered, and muddled. The design from, Web Server to a response, should have been completely extensible and pluggable.

The problems that I have come across, over the last few months (again), have all been relating to ASP.NET not being able to let go. ASP.NET has so many tenuous links to what you write, its everything but impossible to break away.

A framework should always be designed in layers. A framework should not be a large foundational block, written to sit at the bottom only.

if I am not entirely clear, perhaps a few links into oddities will help.
Actionless Form
Scenarios where switching viewstate off like this does not actually work.
and why caching problems like this does not work properly all the time.
Double postback scenarios
The ridiculous IsPostBack code and scenarios
and it does not end. Friendly adaptors, bad html to asp.net naming, lack of rudimentary support for url manipulation, deflected posts and more, makes ASP.NET a framework look like this.

In my humble opinion, on design/framework notions here are some ASP.NET should haves.

  • The HttpRuntime and associated server objects should have been better formulated and allow for better involvement. Allow extensibility.
  • The runtime should have made Pages (HttpHandler) an optional unit of packaging and code, not the complete target.
  • Better fine grained Page type. Split it into more pieces, separating cache, viewstate and more from the design. So we can use at any of the levels of interest.
  • HttpHandlers should have been designed as a clear open and extensible list of handlers. The pattern should be more workflow like.
  • The compilation process of asp.net syntax and html should have been an exposed set of objects, also extensible. (build providers)
  • Expressions should have been designed much better, and give us control of more of the syntax.
  • It should have been easy to create an aspx file and not have code behind, and include your own syntactical sugar.
  • Asp.NET should have been a plug-in to the .net engine for the web, and not soo tightly coupled.
  • Classic ASP should have been a continued 'available' and compatible unit within the framework.
  • Should have reduced the gap between Server and Client side code. not server controls writing client code out, but rather a whole new better solution
  • ClientID $ in Form and _ in Page? why not allow us to switch it off?
  • All that time it took to develop usercontrols and pages and server controls, could have been better spent on using existing syntax and an html object model for controls. It would have been compliant, less error prone and significantly better.



Personally, I cannot wait for the rewrite of ASP.NET. Unfortunately with all the man hours, money and face they have put into ASP.NET - they wont be brave to throw it away. Yes folks you will be stuck with it, and its even going to version 4.

I like the .NET framework as a whole, I love the c# language, but ASP.NET is a beast. Why on earth they built MVC on top, I'll never know. If it was not for Visual Studio supporting ASP.NET, it would be a disaster.

ASP.NET just should not have!

Tags: , ,

May 13 2009

VS.NET Add-ins worth looking at

Category: .NET | Development Tools | DOTNET | Visual StudioJonathan @ 04:53

Run VS.NET as Administrator on Vista.

Export your settings using Tools | Import and Export Settings, don't let another windows reinstall take it all away from you.

Get Regionerate
- but make sure you use the "Remove All regions" command, before trying to apply others. It wont replace your existing regions.

Get Studio Tools, for File manager and the tear off editor.

Download Dev /efor - not sure about the name, but it works nicely.

Snippet Editor, useful, for changing the way the existing snippets work, as well as new ones.

Carl J has a large list of add-ins.

Tags:

Apr 9 2009

Refactoring complex classes using Composition Part 2

Category: .NET | c# | Methodology | Refactoring | Visual StudioJonathan @ 04:07

Please Note: Please make sure you have proper unit test coverage on your classes, as you refactor.

From Part 1, I showed you how I initially split a large class into a few more, splitting the complexity of having the code in one place. However, you will still find that for a really complex class, there will still be quite a lot to do. Here are a few more composition based things to consider for continuing the refactoring process.

More...

Tags: , ,

Mar 30 2009

How much should you design Upfront?

Category: .NET | c# | Design | Design Patterns | Methodology | Visual StudioJonathan @ 07:22

FeelGoodFactor

I follow the FeelGoodFactor principle. Requirements at first glance can be cloudy and messy. It can ambiguous and abstract, or it could just be plain daunting. However, you need to list what you can, and the attempt 'solves'. By solves, I mean a logical route to a solve, a prototypical solution to that problem, or at least common consensus by a few good men (cough). You need to get most of the areas in your head sorted, and then commit a bit of that solution in your head to paper and a review by your peers.

More...

Tags: , , , , ,

Mar 25 2009

ExtensionMethods repository

Category: .NET | c# | Design Patterns | Visual StudioJonathan @ 07:15

Oh what joy. Fons Sonnemans and Loek van den Ouweland have created a repository for ExtensionMethods. Go on, you know you want to. The site ExtensionMethod, allows you to submit your own creations to the community.

Now I had this idea, just around 10 minutes before I found the site, so they beat me fair and square. (By a mile). So therefore here is my top three ideas for the site, which I had, and hope they think about.

1. Grade it
Allow us to vote for it. However more than that, flag it with Compiled, Tested. Little icons that the site show next to each method.

2. Open Source the ExtensionMethod
Allow the community to edit the code, which will improve it over time. If I use it, and it fails because of something small, allow me to edit it, and solve the problem for everyone. Add original author, and contributor names to the list. Perhaps allow an 'Editor' per Type, to look after it and make sure its tested and complete.

2. Give us an Assembly
Run a build, once a month, compile all the snippets, which could be done automatically, if you get the correct data from the submitted snippet.
As part of the grading, is whether your automated compilation worked, when including the snippet. (snippet compiler like, compile on the fly and validate the method).

Now we can all download an Assembly for all these community driven ExtensionMethods. Updated: I found this nice, yet strangely odd set of ExtensionMethods for boolean.

Tags: , ,

Mar 23 2009

Frameworks and the MSDN Library


We all know that the learning curve for Frameworks are quite high. We all know that Frameworks demand commitment, and learning time. We know this because we struggle with it everyday, whether its Java or .NET, Swing, or MFC.

1991-1993, Ralph Johnson and others wrote about Recipes and Cookbooks. There have been papers on documenting frameworks for more than 15 years. MSDN has some of the flavours but none of it is actually polished, nor tailored to the audience and the way in which people seek information.


My D4 Software Frameworks Pattern Language points you to some Patterns for documenting Frameworks:

WritingReference
You must provide a reference of interfaces.
WritingRecipe
You need to provide examples of isolated features of the framework that a pure reference cannot show.
WritingCookbook
You need to combine a large amount of recipes.
SelfDescribing
Using tools and generators, you can generate documentation.


All of them are self explanatory, except let me add, amazing that blogs seem to be the number 1 source for this kind of information, as well as google tends to find things on MSDN better than MSDN finds on their own material?.

The Solution to the MSDN Dilemna

The last one (SelfDescribing) is where I am particularly keen. Not GeneratingReference but SelfDescribing Imagine if a method on a class called MethodA() had been marked with an attribute called TemplateMethod()

Well a Tool, would be able to highlight it for you. If you had a tree of all Types, TemplateMethods and Hooks, you would now better understand the way in which the types where constructed. You would now know that MethodA() called Method(B) then MethodC(). The internals of MethodA() ois not known, shown or cared for. But from a documentation point of view it is crucual for certain designs.

It is this, that is missing from MSDN, because it is missing from all frameworks. Documentation needs to be better, but cannot, until the compiled code, can be examined in a much more thorough way. Developers of Frameworks, must declare their intentions of methods, class and patterns by attributing metadata onto it.

So the solution, is to mark the .NET Framework Types with documenting metadata. Allow all Framework developers to utilize this metadata descriptions for their frameworks, and provide a tool to inspect it.

Tags: , ,

Mar 2 2009

All New DSL's will be 2nd Class Citizens until at least 2018

Category: .NET | Design | Development Tools | Visual StudioJonathan @ 03:29

So you have heard of Domain Specific Languages, maybe even wrote your own. Maybe even rolled it out to the public. Maybe you don't believe you have used a DSL? What about Cascading Style Sheets? Ever used CSS?

Very soon we have to answer a very important set of questions.
How do we use the language? Text Editor? Smarter tools such as Eclipse or Visual Studio? How does it integrate with other languages?

The Common Language Runtime (CLR) puts Microsoft at the front of all this? or does Eclipse have what it takes to adapt?

More...

Tags: ,

Feb 26 2009

A Language Abstraction Layer

Category: .NET | New Ideas | Visual StudioJonathan @ 03:42

By the next turn, our industry will be largely focused on functional requirements, modelling and specific languages for specific tasks. However, having 5 different code files for 5 different languages, and having the spec# /*! !*/ syntax is fair enough, but we are setting ourselves up for a much messy, file managing, experience. Take web projects, where we have CSS, HTML, Javascript, ASP-like tags, code behinds, inline code and more. A typical site could have 4 or 5 different languages and technologies, sometimes different environments to edit and so on.

Towards this, I wrote a post on abstracting the code file from the language
which is the idea that you don't need to have a physical file that you edit, which contains code, but rather a file that contains xml metadata, modelling, code and everything together which is the input into a "View". The view could be textual code editing, a model or I believe more importantly "any". We should be able to code CSS in a VB like syntax if that is our understanding, and it should not matter to the developer, or the developers of CSS, because the SAL (see below) would help the interpretation.

The language is not important, because I should be able to write vb syntax and have it spit out c# into my file, but I always see it as vb. This can be achieved with this abstraction, I mentioned. If like me, you prefer C#, you can open the file and see it as c#, by simply clicking a language menu option.
Likewise, if I only want to see properties, I should be able to toggle this on/off, or if I want to see base class methods of the superclass 'merged' into my current class (grey-code),it should all possible through this abstraction layer, together with other filtering and language oriented viewing features.

More...

Tags: , ,

Feb 23 2009

Software Development Methodology Tool


A software development tool, capturing project data you can use, no matter the methodology.
However, the word "metric" must now cease. I don't like the word at all. I don't want the useless "10 0009 lines of code of which 5 000" is comments rubbish. I want a tool that actually provides me with valuable info.


Here is my idea for a new development tool extensions, plug-in or add-in. Whatever your lingo, a tool that provides real understanding of the project code. A tool helpful to both developer and manager.

Objective

To provide the Developer, Lead and Manager tools they need to evaluate performance of their current project and previous projects. Towards this purpose, the background tasks of the visual studio environment shall be monitored, for the purpose of presenting value to the team.

Graphs

- The following data captured and presented over a time period graph.
- Classes Created/Removed (methods, properties, fields, events and all the rest)
- Project Assets Created/Removed (Projects, Configuration files)
- Refactoring (when code is moved around, refactoring menus clicked etc)
- How fine grained is the project? A formula using the code stats

graph

Events as MetaData (The attachment icon above represents it)

Two kinds of Events, manual and automatic. Both configurable.

Manual Events
A developer has a small toolbar, with a Create Event button. The developer can press the button, and write a comment at any time, creating a piece of attaching MetaData. So when a server goes down, or when the team system server goes down for some reason leaving people stranded for 2 hours. It is a marker of that event occurring.

Automatic Events
When a certain amount of code lines are reached, without refactoring, raise event.
When a certain amount of classes, functions, methods are created, raise event.


One important aspect, is to be able to compare project to project. So the data should be exportable or comparable to another set of data.

Tags: , , , ,