Saturday, January 22, 2011

How to ignore files in Git

If you have files which you don't want to commit to repository, you can add entries to .gitignore file and these files won't be tracked any more.

You can add entry to .gitignore file with echo command:

echo csharp/Presentation/Presentation.suo >> .gitignore

If .gitignore file is not presented in your root directory of the project, you must create it.

The .gitignore file should be in your repository, so that changes to it can be merged and so on.

Tuesday, January 18, 2011

Do not use regions

"A violation of this rule occurs whenever a region is placed anywhere within the code. In many editors, including Visual Studio, the region will appear collapsed by default, hiding the code within the region. It is generally a bad practice to hide code, as this can lead to bad decisions as the code is maintained over time." - one of readability rules of style cope.

If you have regions in your code, you can solve this problem in Visual Studio 2010 by expanding all regions by default.

Got to 'Tools->Option->Text Editor->C#->Advanced' and 'Enter outlining mode when files open' must be unchecked.

Saturday, January 15, 2011

Passive view

Passive view is an approach of the Model-View-Presenter (MVP) pattern. In Passive View the view is devised as thin and passive as possible.

In a Passive View approach, the view is a raw sequence of UI elements with no additional data binding or formatting. The presenter acts directly on the UI elements and works simply by loading data into them.

Advantages:
  • You have an inherently more testable system because the logic in the view is reduced to an absolute minimum.
  • You run no risk at all by not testing the view.
  • The Passive View is very explicit mechanism. This makes is much easer to read the code see what is happening - particularly useful if you're trying to debug when things go wrong.
  • It easy to support multiple GUIs. The presenter ignores any UI technology behind the view.
Disadvantages:
  • A really passive view can be quite cumbersome to write  and maintain and can add a lot of complexity to the presenter. 

See also this post in Martin Fowler's website to get more details.

The core of the MVP is interaction between the view and the presenter, why I don't declared any interface or class for the model.

Here is my implementation of Passive View:

IView.cs
using System;

namespace NOrca
{
 public interface IView : IDisposable
 {
  IPresenter Presenter { get; set; }
  event EventHandler<ActionEventArgs> Action;
  void RaiseAction(object sender, string actionName, params object[] arguments); 
 }
}

IPresenter.cs
using System;

namespace NOrca
{
 public interface IPresenter : IDisposable
 {
  IView View { get; set; }
  void Initialize();
 }
}

Saturday, January 8, 2011

Access windows-host shared folders from ubuntu-guest

Mount the shared folder like this:

sudo mount -t vboxsf folder-name /media/windows-shared

See also this post.

Model View Presenter (MVP)

Model View Presenter (MVP) is a user interface design pattern. It's dedicated to isolate domain logic from the user interface and permits independent development, testing and maintenance of each.

A scenario in which you need to support multiple GUIs MVP is the best choice. It allows to write a presenter and reuse it in Windows and ASP.NET.

MVP is not a pattern that can be implemented quickly, because it can be a bit expensive to implement in relatively simple applications. On the other hand, it shines in enterprise applications, where you really need to reuse as much presentation logic as possible, across multiple platforms.

MVP is based on three actors: the view, the model and the presenter.




Model is a business layer with domain model, a table module or any sort of object model that suits you.

View is an interface that displays data and routes user actions to the presenter.

Presenter is a class which receives input from the view and passes commands down to model. When it gets results from the model it updates the view through the contracted view interface. Also presenter responsible for jumping to the new user interface.

MVP can be separated into Supervising Controller and Passive view.