Archive for the 'Not debugging related' Category

Sorry for being off topic (again) but I just had to comment a bit on some of the comments that were posted for the previous post.

Eyal said that this feature was also added to Delphi 2005 and that its very good for portability issues. It seems that the guys at Borland used that quite a bit to map missing functions that were in .NET and not in Delphi’s VCL which made porting a lot easier.

It’s still a dirty hack and its can and probably WILL be used in a wrongful way.

Yaniv Golan added that the Extension Methods lacks namespace support, so if I have two Extension methods named the same way (due to a reference I’ve added or some other issue) we will get unexpected behavior? Should the compiler yell about that? Will it automatically select only one?

Yaniv suggested using the syntax that includes the namespace. So if I’m taking the example from my previous post instead of having:


I will have:


After all what will happen if someone adds some extension method and in a future version of the BCL (Basic Class Library) someone adds an extension method with a similar name?

Barry Kelly said that Extension methods were added because “It is absolutely required in order to extend IEnumerable to support the new query methods such as Max, Select etc.“.

Perhaps I don’t have the exact vision that Anders Hejlsberg has for C#, and you can call me old school if you wish, but I think that this whole LINQ thing could have been implemented as a certain type of framework.

Yes ADO (ActiveX Data Objects) wasn’t part of the language but most Visual Basic 6 users were able to use it with little to no effort. So it wasn’t part of the language and the compiler didn’t understand a thing about it. So what?!

As far as I know (and people, please correct me if I’m wrong) the compiler can only check the syntax correctness of the statement but can’t perform any other checks at compile time.
Yes, this syntrax might be a bit more intuitive but I’m quite sure this could have been made without brutally hacking the compiler and adding these features.

What’s wrong with a syntax like:

int[] numbers = { 2,2,2,4,5 };
int count = LINQ.Count(LINQ.Distinct(numbers));

I also wonder what happend to the whole XQuery idea? I remember Microsoft releasing an XQuery implementation? XQuery is a language that can be used not only for XML querying but to query and intersect information from various places much like LINQ’s features.

I might be missing the vision of marrying data access with the language itself, but I really don’t think this is the MOST necessary feature that will boost productivity and will ascend to a level of a killer feature.

I know this is a bit off topic, but I just had to comment about it here.

Since I was not able to attend to PDC I’ve been hearing a lot about the announcements and new stuff coming out of it.

One of these things is some of the features in C# 3.0 spec called “Extension Methods”.
In short, Extension Methods allows you to extend an existing class that is sealed by creating a class that has a static function with a special syntax which allows you to call that function on an instance of that object as if it was a member function.

For example, if I want to extend the the String class (which, as you all know, is a sealed class and has its reasons to be like that which I won’t get into at the moment) I would create a class like this:

public static class MyExtension {
public static void Foo(this string s) {
Console.WriteLine(“MyExtension::Foo = {0}”, s);

Notice the “this” keyword near the function’s parameter. This is the keyword that does the magic.

To invoke this method I would use the following syntax:

string s = “Testing Extensions”;

You see, it looks like the String class always had a method named Foo.

Now as much as some people think this feature is cool I don’t see the point of actually having it and showing it like a big thing.

This “functionality” could have been used in previous version of C#. In previous version all you had to do is this:

public static class MyExtension {
public static void Foo(string s) {
Console.WriteLine(“MyExtension::Foo = {0}”, s);

and invoke the code like this:

string s = “Testing Extensions”;

Which, in my opinion, is a lot clearer when reading this code since I know that there is a class somewhere in the code (either from a reference or inside the same .cs file or in another .cs file in the project) that is called MyExtension and have a method called Foo.

So why do we need this functionality?

I guess we don’t, but the only reason I can think of came to me from seeing all the examples out there which involves the String class. Perhaps because the String class (and a few other classes in the Base Class Library (BCL)) are sealed, some people whined too much about it and someone decided on adding this to make them get the same feel as if they inherited from a sealed class and extended it.

Now I know that the C# Spec is saying: “Extension methods are less discoverable and more limited in functionality than instance methods. For those reasons, it is recommended that extension methods be used sparingly and only in situations where instance methods are not feasible or possible.”

But what I do know is that every feature which is not very specific and limited and can be used in a wrongful way, WILL be used in a wrongful way.

So the main question here is, why add such a feature if there are a LOT of other features that are more needed and can get a enchance productivity?

(I wonder how can one get into the language design meetings or at least for the review process of the specs before they are submitted 😉 ).

This is a bit off-topic, but I thought I would recommend some books on .NET debugging and general issues that are related to that.

I’ve setup a page with links to Amazon (so you will get a full description of the book).

Some of the books I recommend personally (and I’ve written bit below the link). Some were recommended to me by others.

I’ll try to update this page with recommendations that I will find/get but if you feel there are some additional books that you know are useful, please contact me and I will add them to the list.

The link also appears on the right in the “Links” area.