Archive for .NET tag

Web site vs web application in Visual Studio

February 2008 .NET (, , ) • 37,445 views • 13 responses

Rob Conery got me thinking about web site maintenance and I put forward a brief comment on the two distinct types and how Visual Studio handles them which I have expanded upon here.

Web site

Primarily for working with ad-hoc web sites that have programmed elements. Easily identified by customer-specific content present in aspx files.

No solution or project files are required and the pages and source can reside locally (file system, IIS) or remotely (FTP, WebDev/FrontPage extensions) via the File > Open > Web Site… menu option.

Code-behind and classes are typically stored on the web server which compiles them in-memory on demand. Changes can be made to the files without restarting the application and losing sessions.

For Against
Quick edit, test, deploy cycle Syntax errors at runtime
No need to compile or restart app Can’t create an installer
Source always available Source on server useful to hackers

Web application

Web application projects were introduced as an add-on for Visual Studio 2005, later rolled in to VS 2005 SP1 and made a full first-class citizen with Visual Studio 2008.

Like the name implies these are primarily for web applications, those times when you have written a product or solution that happens to have a web interface.

Web application projects exist on your local drive and are treated like any other VS project type and can be added to existing solutions are subject to full compilation, validation and build steps.

Deployment is typically via MSI installers however you can also utilise the addition Web Deployment Projects add-in which allows you to deployment directly to servers which is useful for deploying to test environments.

For Against
Controlled build & deploy process Deployment causes application restart
No class files on web server, dll only Can’t deploy individual classes
Syntax errors at compile time  

Hybrid

Sander and I were discussing this article and thought an interesting solution might be to use the Web Application model for local development but to use the Publish option to publish all solution files to an intermediate directory.

Then in the intermediate directory just remove the bin/applicationname.dll file and copy to the target. This should prevent an application restart unless the web.config or global.asax/global.asax.vb files have been modified.

[)amien

The pragmatic .NET developer

January 2008 – April 2008 .NET (, , ) • 1,024 views • 10 responses

Long-time friend, fellow co-host of the GSDF and the coding genius behind the open-source Ogre3D engine Steve Streeting has written an interesting piece on Open source adoption; countering the fear and doubt. I have no doubt that this was fuelled by a lengthy discussion last night in the Ship & Crown pub – a common ritual after our GSDF meetings.

The reasons why I adopted .NET as my primary platform despite being tied to a single-supplier are:

  • Ease of deployment & set-up
  • Low resistance to adoption
  • Great tool integration
  • Official & community support
  • Love for C# and the CLR

The ALT.NET movement

Many .NET developers are reluctant to look wider afield but this is not exclusively the case and a person focused on the .NET platform but open to selecting beneficial alternatives to the Microsoft prescription is exactly what the ALT.NET moniker was coined to encapsulate.

SourceForge lists over 6,000 open-source C# projects alone and many well-known open source Java & PHP projects have made their way to the .NET platform. NHibernate, NUnit, NCover, Spring.NET & DotNetNuke alongside new .NET developments such as xUnit.NET, SubSonic, Subtext etc.

Best of breed

Where a non-Microsoft option is functionally superior or more cost effective I will consider it whether it is proprietary or open source.

I do not however select a solution simply because it is considered the “best of breed” at that particular moment. Integration, training, availability of support and experienced developers, deployment, cost, barriers to entry and roadmaps must be taken into account.

Given that Microsoft provide the .NET platform anything ‘in-the-box’ scores highly in many of these areas.

Sometimes a non-Microsoft solution comes out on top or there is a compelling reason to adopt it anyway. This is why my toolkit already contains Subversion, TortoiseSVN, AnkhSVN, Reflector and NUnit.

It’s also why I currently run Mac OS X alongside Vista, use WordPress as my blogging platform, prepare my presentations with KeyNote and use OmniFocus to organise my life.

Robust alternative projects

I have concerns about longevity and support on projects from companies and hobbyists regardless of whether they are open source or proprietary.

NDoc, CVS & NullableTypes are three I’ve used which died when an alternative commercial or open source project gained more momentum and SourceForge is seemingly littered with thousands of dead projects.

If a project you rely upon dies you have one of a number of options:

  1. Migrate to something new (gained little from open source)
  2. Fix bugs and problems yourself (time spent working outside your business domain)
  3. Have a support contract with somebody else to work on it (single-supplier scenario?)

Competition is important

Competition is important but I can not, in a professional capacity, recommend to customers something that I believe is less suitable in the interest of keeping the competition healthy.

Confusion about choice

I hit this one first hand developing my final-year degree project which required development of a web site in Java.

The number of choices for Java was incredibly confusing despite knowing the syntax. J2SE or J2EE? JSP, Struts, Spring or another servlet package? What about the database and ORM? Application server? What versions work together? What overlaps? Would I be able to get experienced developers? If not how long to train them up?

.NET has many options too but I can start with the .NET Framework and get right into solving the domain problem. If the going gets tough I may have taken a wrong turn and need a different solution. That could involve choosing an alternative component or framework but now I’ll know what problem I’m trying to solve when I go looking.

Developers on complex projects felt that WebForms wasn’t ideal – it is hard to maintain, the output bloated with leaky implementation (ViewState) but it serves many developers well enough.

Open-source projects such as MonoRail addressed this taking cues from Ruby on Rails. Microsoft acknowledge this and add a similar MVC framework going so far as to support additional engines and components allowing elements of MonoRail to be used. Those guys could drop the glue required to get their engines into the pipeline and just concentrate on engines if they wish.

What works for me

Stay small and focused until you feel friction.

Friction isn’t always technical or immediately obvious. It might be future plans and it’s often people. It might be what isn’t there and will never be.

Time lost on friction is not spent developing your domains features.

If another solution causes less friction, use it but don’t underestimate unknowns.

I guess that’s just being pragmatic.

[)amien

Language Integrated Query: An introduction talk tomorrow

January 2008 – March 2008 .NET, Guernsey (, , , ) • 793 views • no response

I’m just finishing up the slides, notes and writing code samples for my LINQ presentation at the Guernsey Software Developer Forum tomorrow evening.

Hopefully the broader scope of this presentation will mean a few new faces – the previous talks on Subversion and web application security might have been a little specific for a such a small audience (Guernsey is around 70,000 people on an island 9 miles long).

As always I will put the presentation up here afterwards but will also revise the older ones with the new style and put up both PowerPoint and Keynote versions under an open licence as well as a couple of cheat sheets.

Is there any interest in adding audio narration and transcripts?

This presentation is now available on-line.

[)amien

Calculating Elf-32 in C# and .NET

November 2007 – October 2009 .NET (, , ) • 1,724 views • 4 responses

Because you can never have enough hashing algorithms at your disposal this one is compatible with the elf_hash function that forms part of the Executable and Linkable Format.

using System;
using System.Security.Cryptography;

public class Elf32 : HashAlgorithm {
   private UInt32 hash;

   public Elf32() {
      Initialize();
   }

   public override void Initialize() {
      hash = 0;
   }

   protected override void HashCore(byte[] buffer, int start, int length) {
      hash = CalculateHash(hash, buffer, start, length);
   }

   protected override byte[] HashFinal() {
      byte[] hashBuffer = UInt32ToBigEndianBytes(hash);
      this.HashValue = hashBuffer;
      return hashBuffer;
   }

   public override int HashSize { get { return 32; } }

   public static UInt32 Compute(UInt32 polynomial, UInt32 seed, byte[] buffer) {
      return CalculateHash(seed, buffer, 0, buffer.Length);
   }

   private static UInt32 CalculateHash(UInt32 seed, byte[] buffer, int start, int size) {
      UInt32 hash = seed;

      for (int i = start; i < size; i++)
         unchecked {
            hash = (hash << 4) + buffer[i];
            UInt32 work = (hash & 0xf0000000);
            if (work != 0)
               hash ^= (work >> 24);
            hash &= ~work;
         }
      return hash;
   }

   private byte[] UInt32ToBigEndianBytes(UInt32 x) {
      return new byte[] {
         (byte)((x >> 24) & 0xff),
         (byte)((x >> 16) & 0xff),
         (byte)((x >> 8) & 0xff),
         (byte)(x & 0xff)
      };
   }
}

[)amien