The Law of Demeter, The crux of

June 21, 2009 20:12
var zipCode = order.Customer.Address.ZipCode;

Have something like that in your code? Suprise, surpsire - this is called "train wreck" coding style. To get the zip, we should know (and rely on) the whole chain of components. An unrelated change somewhere else in the system can break the line above.

To get rid of such chains, we should recall The Law of Demeter and, generally, the notion of "shy" code. Shy is two-fold:
  • don't reveal too much of yourself to others. Do not mark things public if they can be private (or internal, etc), avoid putting several methods of a similar purpose on your public API, avoid global data (and avoid singletons - if feasible - because they are global).   
  • don't interact with others more than it's necessary. Basically, call as few methods as possible. Methods with smaller response set (response set is a number of functions/properties called by a method) are less prone to error and break less frequently, as they're less coupled with the rest of the system. 

More...


Why learn Resharper

June 14, 2009 20:05

The ability to use tools is innate to humans, but not only to them.

Sea otters use stones to open recalcitrant mussels (and could keep a favorite stone tucked under the armpit, for the next use). Monkeys use sticks to dig holes. Herons use twigs as bait to catch fish and dogs use ticket stampers to validate tickets in trams.
More...


Mystical Story Point

June 7, 2009 21:55

Whenever I hear the word "agile" I reach for my revolver.

A huge pile of chest-thumping and vapid articles about benefits - and a lot less about pitfalls. Often, people just say "uhm, you know, it's not a silver bullet" and "just don't change the process" and then you have to glean the rest yourself.

So google for pitfalls of agile and read over, learn the salutary science of Agileology, and this post will be sitting here until you're done.
More...


Making the Right Moves

May 24, 2009 20:30
If you've ever played chess, you know how important openings are: castle early, protect your king, get some control... Time-proven, standard ways of starting a game, they lay a foundation for your victory.

It's similar in software development.
Before you start a project, there's a lot of pretty standard things you should think of - from development process to architecture to testing and deployment.

These are your openings. More...

Ivonna for free

May 19, 2009 14:05

If you ever tried to unit test ASP.NET apps, you know how hard it is. There are Watir, WatiN and Selenium for client side testing but those tests, inherently, are integration ones. And if you are looking for a unit tests solution (especially in a legacy app) - welcome to Ivonna.

Bad news is that it costs €599.00

Good news is that Typemock is now giving away free licences for Isolator+Ivonna bundle: in order to get one, you just need to post on your blog that Typemock is now giving away free licences for Isolator+Ivonna bundle.

Easy? Read more about the rules and fire away!


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...


The Shark Fin: Pex

April 26, 2009 10:02
Imagine: you have a method that needs to be tested.

You right click on it, select "Generate Tests" and a tool generates a suite of tests that cover all code paths. If you later update the original method, you just need to regenerate the tests and the missing coverage is back.

Given that you are still reading,  I will assume that you're ready to take the red pill.
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...


Three types of development

March 30, 2009 20:56

There are three types of development:

  • (Re)design
  • (Re)implementing the functionality
  • Bugfixing and refactoring

Of course, sometimes your "implement the stuff" timespan can be interrupted with high priority bugs. And indeed your redesign sometimes can come along with new functionality from the get go.

However, it is important not to mix the approaches you use in each case. More...