Thursday, October 30, 2008

DemoCamp 4 Review

Last night (October 29 2008) was the latest installment of DemoCamp here in Edmonton. It took place at the University of Alberta and there were well over 150 people there! Big turn out....I believe the biggest yet.

One of the speakers with a great application was electionbuddy. They created a nicely polished app around the simple idea of elections. What really astounded me was that the guy who created it is a student and is going to go to medical school. Hard to know if the code was clean but from the outside the application was well planned and easy to use. It was a hit with one of the Venture Capitalist type people who was there when he suggested that electionbuddy charge more for it. The guy was definitely getting alot of attention.

Another presentation was from a small company here in Edmonton, gskinner that has done an astounding job in Flash. Their list of clients is impressive: Adobe, Sony, AOL, GE, etc. I never knew that people like that existed here in Edmonton. Using Air and the Flash programming language they have been able to develop some impressive stuff. They have even been able to create something for Flash and sell it back to Adobe. They have also worked with BioWare on one of their games.

One of the worst applications I have seen so far is TheHistoryBooks. Around the idea of posting peoples history for a *small* fee. Seriously! Who Cares!! The guy who created it actually flew down from regina to present it. I believe he thinks it is still 1999 and the bubble hasn't burst!

Monday, July 14, 2008

Going to Alt.net


Calgary here I come!!


ALT.NET

Tuesday, February 12, 2008

Notebook

A new way I found to manage my day is to use the notebooks app found in google apps.

NOTEBOOK

I find it a great way to write down the goals I have for the day, affirmations and any links I find during the day. It is a really great scratchpad to help organize what is happening.

I currently have a work log where I write down everything that goes on that I would like saved. Each day I create a new entry.

Tuesday, January 29, 2008

Chain of Responsibility

This pattern is part of a group of patterns that deals with communication between two or more different objects. This pattern allows us to provide loose coupling between objects and also encourages testable code. In Chain of Responsibility we will have a chain of command objects that are passed requests. As we go down the chain....those objects that can handle the request do so....those that can't pass the request down the chain.

Our command objects will adhere to the ICommand interface. Any of the command objects that are part of the chain will have the 'Run' and 'Successor' methods defined in the interface.I can use the Successor method to allow us to setup the chain or we can use the constructor that is defined in each one of the following classes. I have chosen to simply utilize the constructor for simplicity.




public interface ICommand
{
ICommand Successor { get; set;}
void Run(int request);
}


I am going to define three different classes that will implement the ICommand interface.




public class EmailLogger: ICommand
{
private ICommand successor;


public EmailLogger()
{
}

public EmailLogger(ICommand successor)
{
this.successor = successor;
}

public ICommand Successor
{
get { return successor; }
set { successor = value; }
}

public void Run(int request)
{

if (request==1)
Console.WriteLine("I am the Email Logger. I can handle one.");
else if (successor != null)
successor.Run(request);
}


}


public class StdErrLogger: ICommand
{
private ICommand successor;


public StdErrLogger()
{
}

public StdErrLogger(ICommand successor)
{
this.successor = successor;
}

public ICommand Successor
{
get { return successor; }
set { successor = value; }
}

public void Run(int request)
{

if (request==2)
Console.WriteLine("I am the STD Error Logger. I can handle two.");
else if (successor != null)
successor.Run(request);
}
}

public class StdOutLogger : ICommand
{
private ICommand successor;


public StdOutLogger()
{
}

public StdOutLogger(ICommand successor)
{
this.successor = successor;
}

public ICommand Successor
{
get { return successor; }
set { successor = value; }
}

public void Run(int request)
{
if (request==3)
Console.WriteLine("I am the STD Out Logger. I can handle three.");
else if (successor!=null)
successor.Run(request);
}
}


You will notice that the meat of the object for the chain to work according to the pattern is each of the Run methods. It is here we will check the original request. If our current object in the chain can handle the request...it will...otherwise we will pass on the request to the rest of the chain.

I am going to define a place where I can kick off the chain creation. This chain could also be created separately as part of some factory class.



public class ChainOfResponsibility
{
private ICommand stdOutLogger;

public void Initialize(int request)
{

stdOutLogger = new StdOutLogger(new EmailLogger(new StdErrLogger()));
stdOutLogger.Run(request);
}

}


The 'StdOutLogger' is the outmost part of the chain and will start everything off. Calling Run here...we will check the request. Let's say that the request is '3' coming from the Initialize method. StdOutLogger can't really handle this value...so it passes the request off to EmailLogger. EmailLogger's Run method can't handle this value either. The request is finally passed on to StdErrLogger which can handle three.

** Note that based on our code...once a request is dealt with no other command objects are called.**

Friday, January 25, 2008

Observer Pattern

Using a change observer in your application is really useful in windows forms applications where you have textboxes, checkboxes etc. that are inherently designed for event generation. A great implementation of the pattern is to observe a dirty property on your form letting you know if anything has changed.

A great starting point to learning the basics of the Observer pattern is on wikipedia. The subject (your form) will maintain a list of observers, remove observers from the list and notify all observers of any changes. Here is the interface for the subject.




public interface ISubject
{
void RegisterObserver(IObserver observer);
void UnRegisterObserver(IObserver observer);
void NotifyObservers();
}


When you implement this interface on your form, you create your observer and register it. For my purposes I only need to create one observer to monitor changes on any of my form controls. Here is the interface for the observer.





public interface IObserver
{
void Update();
bool IsDirty { get;}
}




As soon as a change occurs on any control I need to let the change observer know. So, whenever a TextChanged event occurs on my controls I can handle it and notify the change observer that something has happened by calling the NotifyObservers method.




public void NotifyObservers()
{
foreach (IObserver observer in changeObservers)
{
observer.Update
}
}


NotifyObservers will loop through all my registered observers and call the Update method. The Update method on the observer is really simple....it just flips the dirty property to true.

So now my form is dirty. If I happen to for example close my form without saving I can check with the changeobservers and see if there is anything dirty. If there is I can let the user know and ask if they want to save.





public void HandleFormClosing(object sender, CancelEventArgs e)
{
DialogResult result;

if (FormIsDirty)
{
result = MessageBox.Show
("You have unsaved Changes. Do you want to save?", "Unsaved", MessageBoxButtons.YesNoCancel);
if (result.Equals(System.Windows.Forms.DialogResult.Yes))
MessageBox.Show("Saved!");
else if (result.Equals(System.Windows.Forms.DialogResult.No))
MessageBox.Show("Not Saving!");
else
{
e.Cancel = true;

}
}
else
MessageBox.Show("No changes detected.");

}


One limiting feature of this implementation is that there is very little re-use.
I need to wire up all of my Handlers for each control on the form and then call NotifyObservers. If I have another form and want to do the same thing I have to write the same thing again. A better solution would be to push this event handling onto the ChangeObserver to register the controls and the event to fire whenever a change occurs.

public void RegisterControls(Control.ControlCollection controls)
{
foreach (Control control in controls)
{
if (control.GetType().Equals(typeof(TextBox)))
control.TextChanged += new EventHandler(HandleChange);
if (control.GetType().Equals(typeof(CheckBox)))
{
CheckBox checkbox = (CheckBox) control;
checkbox.CheckedChanged +=new EventHandler(HandleChange);
}
if (control.GetType().Equals(typeof(RadioButton)))
{
RadioButton radioButton = (RadioButton) control;
radioButton.CheckedChanged +=new EventHandler(HandleChange);
}
}
}

void HandleChange(object sender, EventArgs e)
{
Update();
}


So now I can reuse this code on any form that I want to observe.
If I have other types of controls I can throw them into the RegisterControls method.

Wednesday, November 14, 2007

ReSharper Templates

JP has posted some great templates on his blog for everyone to use in their projects.

For the file templates you can add keyboard shortcuts to help add new testfiles to your project… just look for the following in your ‘Show commands containing’ Keyboard mapper:

“ResharperAddIn25.FileTemplates_CreateFrom…….”

Tuesday, August 21, 2007

Becoming a better developer

As a part of the process to becoming a better developer I find it easier to write down and prioritize tasks. These tasks are things I think I should be doing to be better such as reading a book, studying code or learning a new language. I usually break down the tasks rather than generalize it. This way it is more approachable and manageable. For example instead of making a task called:

"Read Refactoring by Martin Fowler"

I'll say...

"Read chapter 9 today out of the book Refactoring"

This way I'm breaking down what I want to accomplish to something that is achievable and I am also putting a deadline against it. I want to get it done today. Since it is a small goal...most likely I can get it done.

One way to organize these tasks is using this really cool application called:

"Remember the Milk."

It is a very 'google-ish' type of app and has the ability to help me organize almost anything.