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.

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


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
    Inexpensive = Cheap
public static void Main()

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.

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!

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.

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.

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.

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.


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.

One man's constant is another man's variable

September 14, 2008 19:18

There’s probably only one good reason for a type to keep its state unchangeable (apart from using it as a key in a hash table). This reason is multithreading.

Unchangeable state means the type methods designed to update the instance will instead return a new-minted one. By and large, this is immutability: you manacle yourself in terms of performance but gain from ease of multithreading development. Quite straightforward, isn’t it – all multithreading issues appear because you have to make sure only one thread at a time can update an object, but immutable objects don’t need synchronization at all, huh![1]

So, the overall idea is somewhat familiar to most of us but very soon everybody will need to understand the basics of immutability – because Eric Lippert said: "Immutable data structures are the way of the future in C#", and Eric Lippert does understand what he is talking about[2].

So, let's peel off the tasteless wrappings and see what we already knew.