Something I've been taught when I first started with Object Oriented programming languages.
When declaring a field in a class, don't initialize it yet, do that in the constructor.
In C#:
public class Test
{
private List<String> l;
public Test()
{
l = new List<String>();
}
}
But when someone recently asked me why to do that, I could come up with no reason. I'm not really familiar with the internal working of C# or other programming languages for that matter, as I believe this can be done in all OO languages.
So why is this done? Is it security? Properties? What is it?