Keeping methods small
As we’ve read before, while programming clean and readable code, it is important to keep the methods small. Preferably, in the C# world, it is best to keep methods under 10 lines long. The perfect length is no more than 10 lines.
A good way to keep methods small is to consider if you should be trapping for errors or bubbling them further up the call stack. With defensive programming, you can become a little too defensive, and this can add to the amount of code you find yourself writing. Besides, methods that trap errors will be longer than methods that don’t.
Let’s consider the following code, which can throw an ArgumentNullException
exception:
public UpdateView(MyEntities context, DataItem dataItem) { InitializeComponent(); try { DataContext = this; _dataItem =...