Why C# named parameters use colons

August 9, 2009 19:14

With the advent of VS2010, there's an explosion of interest around the new features of C#4.

Named parameters.

That's a cool one.  Look at the code below and note that without checking with the signature you can't really tell where's the title and where's the message:

public void SendMessage(string title, string message) { ... }
 
SendMessage("foo", "boo"); //that's how you call it


And look at the C#4 variant -
now it's much better, eh?

SendMessage(title: "foo", message: "boo");

More...


Disposing a DataSet: a play in two acts

May 17, 2009 16:22

Act I. Development office hall. Two developers, Кастусь and Пятрусь, standing near the coffee machine[1]. Late spring afternoon.

K:
Hey man, do you think it's necesssary to call Dispose on datasets?

П: Sure - everything that implements IDisposable needs to be explicitly disposed. Thus you release the unmanaged resources you're probably holding.

K: (exultedly) Fair enough - but
DataSet doesn't actually implement IDisposable! When you dispose a dataset you call Dispose on its parent, MarshalByValueComponent. And that guy has only managed dispose logic:

protected virtual void Dispose(bool disposing)
{
    if (disposing) {
    //some managed disposing code here
    }
}

More...


Enums turmoil

May 3, 2009 20:12

Do you think enums are simple? Well, they are not. Look at the following code

public enum Price
{
    None,
    Cheap,
    Inexpensive = Cheap
}
 
public static void Main()
{
    Console.WriteLine(Price.Inexpensive);
}


Ok so I hear you saying, "It will print Cheap". Cool stuff. You're right! If multiple enum members share the same value, the "main" member acts as a source for ToString. Now we move on - I will just add a few more members.
More...


Has shutdown started?

April 5, 2009 21:40

Salutary static adjunct for class declarations was introduced in C#2, aimed to solve the whole bunch of issues.

Previously, in order to set up a container of static methods you had to do some tricks while declaring that class.

  • First off, since it's useless to create an instance of such a class, you would create a private constructor that could never be called from the outside.
  • Then you would mark the class sealed so that nobody could inherit from it.
  • And then you would start adding your static methods, properties, etc.

Apparently there are few problems with this approach. More...


A genealogy tour in .NET: lady

March 8, 2009 20:00
To bring up a lady, start from her grandmother.
Eric Berne.

Anonymous types are nice since you write less code. You don't declare a class, and don't put its name when you create it. However, using them anywhere outside small Linq-like filterings is stultifying and dangerous (think about ASP.NET MVC here).  

But species transform themselves generation after generation, and so do software artifacts. As a corollary of this axiom, anonymous types of .NET 3.5 are about to give birth to another abstraction of .NET 4.0 [1]. Ladies and gentlemen, please make her feel welcome: Tuple, The Lady!
More...


A genealogy tour in .NET: mother.

February 22, 2009 17:16

A lady can become a lady only if her mother has teached her everything a proper lady should know.  Obviously the mother should learn that stuff from grandparents.

In this context, grandmother is Generics and grandfather is Linq. Surprisingly enough, they engendered a wacky abstraction of Anonymous Types, a great facilitator of data filtering. They teached it how to stroll, how to smile and how to say "no" politely.
More...


A genealogy tour in .NET: grandmother.

February 15, 2009 17:13
To bring up a lady, start from her grandmother.
Eric Berne.

Perhaps not a precise citation, but you get the idea. People take their habits and attitudes from their parents, while the parents imitate their own parents and so on. Inexplicably, this sort of upbringing can be
retraced in C# as well.

Far-fetched? Not more than anything else you'd try to compare to software development.
More...

Waltzing Lambdas

November 2, 2008 11:00

Microsoft Visual Studio 2010 and .NET 4.0 is available for download [1]. You probably know that but anyway. We can touch something real, more than a year prior to the actual release! A lot of room for MS to fix bugs and adapt to community requests as Tom Waits sings, the quality goes in before the name goes on, eh?

The flip side of this event is that, yes, we still have some time to catch up with the existing language features of .NET.

My hobbyhorse.

It's easy to get amazed with something new and shiny while overlooking the usual things that yet have a lot of unused power. So let's talk about lambda expressions and their practical use.
More...


Revisit and summarize

October 5, 2008 19:29

This Wednesday, yours truly was making a presentation at Microsoft premises here in Prague. Apart from passing along the beauty and usefulness of the "new" language constructs, I was trying to convey the atmosphere of those agitated days when I was discovering C#2 and C#3 myself [1].

Pelt me with rotten iPhones if I will be talking that fast next time.

More...


Chewing on iterators

September 28, 2008 21:53

One thing that is really giving me goose bumps about C#3 is its swag of auto generated code. Don’t get me wrong, the readability we get as a result is pretty much awesome. But auto generated code is an abstraction, and every abstraction leaks, as we were told[1].

Iterators are a good example of a complicated code generation. Without getting into gory details, a method with a yield operator gives birth to an auto generated class that is actually a state machine with logic of MoveNext and Current. Not only does it propel a more concise code, but also makes a certain impression upon your colleagues and family members.
More...