September 28, 2005

Working with ASP.NET 2.0

These days I spent some time working with VS2005 and especially with ASP.NET 2.0. The new release is really amazing and I remembered what someone recently said - “The experienced programmers fear it (ASP.NET 2.0) because it will leave them out of job.” The point was that it provides so much functionality and it is so simple that every one would be able to use it.
Well I must say that this point of view is far away from the truth. All this new stuff is so facilitated that it can take days to understand what is going on behind the ready-to-use-and-drag-and-drop-friendly programming framework.
Let me share some of my experience with it.
First of all – use IIS whenever possible. I found out that the ASP.NET development web server (the one that comes integrated with VS2005) is too slow. It can also cause timeouts during debugging sessions and problems with detaching from the debugger. At last you do not have any way to control the properties of this web server so troubleshooting problems become pain in the neck.
Next – use SQL Server 2005 whenever possible too. When you first start using ASP.NET 2.0 a lot of things will not work from the first time. Chances that that will be data related problems are big. If you use SQL 2005 Express there will be no SQL Profiler either and that’s a big step back in data related problem solving.
Avoid the new feature that allows hot swapping and XCOPY deployment of SQL databases on your development machine. (Basically this is a new option in the connection string that allows you to point out where the .mdf file resides eliminating the need to create database in some SQL instance.) This feature may be useful in production site, but it has some side effects.
Beware that the windows account of the user that first creates the connection in this databaseless manner, becomes exclusive user for this file and no other windows account will be able to create a connection to this file. The error is quite useless in this case:

“An attempt to attach an auto-named database for file C:\acme.mdf failed. A database with the same name exists, or specified file cannot be opened, or it is located on UNC share.”

Also keep in mind that in one occasion I had to give write access to NETWORK SERVICE account to the folder above the one that was holding my .mdf file. I have not research it what is the case however.

September 17, 2005

C# 3.0 specification

The C# 3.0 specification is available here. The new features include (along with my comments):

1. Implicitly typed local variables

Basically this means that one can write

var p = 3;

Come on dudes, this one makes me sick. I see its benefits using LINQ syntax, but it should not be allowed to be used anywhere else. This language will soon mutate to a JavaScript like.

2. Extension methods

Sucks, mucks, pucks, *ucks, and sucks all at one.
Allows you to extend one class functionality through another. Thus the following:

public static class Extensions
{
    public static int ToInt32(this string s)
    {
        return Int32.Parse(s);
    }
}


can be invoked using the code below:

string s = "1234";
int i = s.ToInt32(); // Same as Extensions.ToInt32(s)


Instead of removing the sealed keyword (it is OO language after all), now we have extension methods that can come from all over the code and extending every single object. Debug this one now. Sucks big times. ARHRGHRR.

3. Lambda expressions

I am against anonymous methods so I will save my comments on this one.

4. Object and collection initializers

As Stoyan Damov says, we expected this feature in C#1.0. What this means is that you can now write the following to initialize objects and collections:

Point p = new Point { X = 0, Y = 1 };

instead of

Point p = new Point { X = 0, Y = 1 };
p.X = 0;
p.Y = 1;

and

List digits = new List { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

instead of - you guess what.

5. Anonymous types

One more feature to make C# behave like a type less javascript or VB language. Creates a new type without naming it, hence – anonymous. Works with var keyword (see 1.)

var p1 = new { Name = "Lawnmower", Price = 495.00 };

6. Implicitly typed arrays

One more feature that should be available in C# 1.0. Allows you to create array without defining explicitly its size and type. The drawback is that the var keyword has took over this feature also. Thumbs down.

var[] a = new[] { 1, 10, 100, 1000 };

7. Query expressions

I wrote about query expressions in my previous post. Pretty big one. Still not sure if C# is the right language for this feature. Good idea, but I would prefer to be separated from the language.

8. Expression trees

This is too much for my brain capacity. I leave it for you :)


Eric Gunnerson has some comments about C# 3.0 specification also.

For now I am seriously considering to jump over C++/CLI implementation. Like the good old days :)

September 15, 2005

LINQ and database definition

Microsoft presented the LINQ (Language Integrated Query) Project , a new syntax for querying databases and objects from C# 3.0. LINQ has been founded on generics, anonymous methods and nullable types that are going to be delivered in C# 2.0. The SQL integration is amazing. For example if you want to define a table created with the following DDL:

create table Orders (
OrderID nvarchar(32) primary key not null,
Customer nvarchar(32) not null,
Amount int
)


the CLR representation will be like next one:

[Table(Name="Orders")]
public class Order {
[Column(DbType="nvarchar(32) not null", Id=true)]
public string OrderID;

[Column(DbType="nvarchar(32) not null")]
public string Customer;

[Column]
public int? Amount;
}


I suppose that in the future the database model will be enough to create the database DDL script, data class definitions and data access layers using a code generator.

September 10, 2005

Multiple IIS sites in Windows XP

Ha, I never knew that Windows XP Professional allows creating more than one web site per machine. I though that it is a restriction buried deep down into IIS. Well it is possible to programmatically create multiple instances. The company firstServed has provided a nice tool IISAdmin that does the work for you.