Click here to Skip to main content
15,885,936 members

Leslie Sanford - Professional Profile



Summary

    Blog RSS
105,764
Author
2,562
Authority
3,913
Debator
121
Enquirer
252
Organiser
2,232
Participant
0
Editor
Aside from dabbling in BASIC on his old Atari 1040ST years ago, Leslie's programming experience didn't really begin until he discovered the Internet in the late 90s. There he found a treasure trove of information about two of his favorite interests: MIDI and sound synthesis.

After spending a good deal of time calculating formulas he found on the Internet for creating new sounds by hand, he decided that an easier way would be to program the computer to do the work for him. This led him to learn C. He discovered that beyond using programming as a tool for synthesizing sound, he loved programming in and of itself.

Eventually he taught himself C++ and C#, and along the way he immersed himself in the ideas of object oriented programming. Like many of us, he gotten bitten by the design patterns bug and a copy of GOF is never far from his hands.

Now his primary interest is in creating a complete MIDI toolkit using the C# language. He hopes to create something that will become an indispensable tool for those wanting to write MIDI applications for the .NET framework.

Besides programming, his other interests are photography and playing his Les Paul guitars.

Reputation

Weekly Data. Recent events may not appear immediately. For information on Reputation please see the FAQ.

Privileges

Members need to achieve at least one of the given member levels in the given reputation categories in order to perform a given action. For example, to store personal files in your account area you will need to achieve Platinum level in either the Author or Authority category. The "If Owner" column means that owners of an item automatically have the privilege. The member types column lists member types who gain the privilege regardless of their reputation level.

ActionAuthorAuthorityDebatorEditorEnquirerOrganiserParticipantIf OwnerMember Types
Have no restrictions on voting frequencysilversilversilversilver
Bypass spam checks when posting contentsilversilversilversilversilversilvergoldSubEditor, Mentor, Protector, Editor
Store personal files in your account areaplatinumplatinumSubEditor, Editor
Have live hyperlinks in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Have the ability to include a biography in your profilebronzebronzebronzebronzebronzebronzesilverSubEditor, Protector, Editor
Edit a Question in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Edit an Answer in Q&AsilversilversilversilverYesSubEditor, Protector, Editor
Delete a Question in Q&AYesSubEditor, Protector, Editor
Delete an Answer in Q&AYesSubEditor, Protector, Editor
Report an ArticlesilversilversilversilverSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending ArticlegoldgoldgoldgoldSubEditor, Mentor, Protector, Editor
Edit other members' articlesSubEditor, Protector, Editor
Create an article without requiring moderationplatinumSubEditor, Mentor, Protector, Editor
Approve/Disapprove a pending QuestionProtector
Approve/Disapprove a pending AnswerProtector
Report a forum messagesilversilverbronzeProtector, Editor
Approve/Disapprove a pending Forum MessageProtector
Have the ability to send direct emails to members in the forumsProtector
Create a new tagsilversilversilversilver
Modify a tagsilversilversilversilver

Actions with a green tick can be performed by this member.


 
GeneralApplying Generic Programming to Runtime Polymorphism Pin
Leslie Sanford22-Feb-10 10:28
Leslie Sanford22-Feb-10 10:28 
GeneralGeneric Programming [modified] Pin
Leslie Sanford19-Jul-08 5:53
Leslie Sanford19-Jul-08 5:53 
GeneralOff-topic Pin
Rajesh R Subramanian19-Jun-09 12:48
professionalRajesh R Subramanian19-Jun-09 12:48 
GeneralRe: Off-topic Pin
Leslie Sanford19-Jun-09 19:06
Leslie Sanford19-Jun-09 19:06 
GeneralEnsuring Object State [modified] Pin
Leslie Sanford27-Jun-07 8:00
Leslie Sanford27-Jun-07 8:00 
Many times a method needs to perform a series of steps. The problem is that one of these steps can fail. Usually, this results in an exception being thrown from the source of the failure. When this happens, it's important that the object whose method is being invoked is left in a valid state.

Here is an example of the problem:

public class MyClass
{
    private SomeObject obj;
 
    private int a;
 
    private int b;
 
    public MyClass(SomeObject obj)
    {
        #region Require
 
        if(obj == null)
        {
            throw new ArgumentNullException("obj");
        }
  
        #endregion
 
        this.obj = obj;
        this.a = obj.CalculateSomething();
        this.b = obj.CalculateSomethingElse();
    }
 
    public void DoSomething()
    {
        a = obj.CalculateSomething();
 
        b = obj.CalculateSomethingElse();
    }
}


Now in the above example, suppose that the call in DoSomething to the CalculateSomething method succeeds but that the call following it to CalculateSomethingElse fails and an exception is thrown. Also suppose that a and b should always be updated together. If one is updated successfully and the other is not, the object is no longer in a valid state. It's not hard to think of "real" examples of this type of situation, e.g. updating values in an object by loading data from a file (suppose a read operation fails?), but here we'll just have to assume this is the case.

A way to circumvent this is to cache the results from each step temporarily and update the object at the end of the method. At this point, all of the steps have been completed successfully and we can update our object while ensuring that its invariants are maintained.

public class MyClass
{
    private SomeObject obj;
 
    private int a;
 
    private int b;
 
    public MyClass(SomeObject obj)
    {
        #region Require
 
        if(obj == null)
        {
            throw new ArgumentNullException("obj");
        }
  
        #endregion
 
        this.obj = obj;
        this.a = obj.CalculateSomething();
        this.b = obj.CalculateSomethingElse();
    }
 
    public void DoSomething()
    {
        int tempA = obj.CalculateSomething();
 
        int tempB = obj.CalculateSomethingElse();
 
        // Now we can update the object's fields.
        a = tempA;
        b = tempB;
    }
}


In the second example, the calls to CalculateSomething or CalcualteSomethingElse can fail without our object being left in an invalid state.

When it's necessary to perform many steps in a method, caching the results can get complicated. My current approach is view this as an opportunity to refactor. What I do is take the values that need updating and put them into a seperate class. The previous example then looks like this:

public class RefactoredValues
{
    private int a;
 
    private int b;
 
    public RefactoredValues(SomeObject obj)
    {
        #region Require
 
        if(obj == null)
        {
            throw new ArgumentNullException("obj");
        }
  
        #endregion
 
        this.a = obj.CalculateSomething();
        this.b = obj.CalculateSomethingElse();
    }
 
    public int A
    {
        get
        {
            return a;
        }
    }
 
    public int B
    {
        get
        {
            return b;
        }
    }
}
 
public class MyClass
{
    SomeObject obj;
 
    RefactoredValues v;
  
    public MyClass(SomeObject obj)
    {
        #region Require
 
        if(obj == null)
        {
            throw new ArgumentNullException("obj");
        }
  
        #endregion
 
        this.obj = obj;
 
        v = new RefactoredValues(obj);
    }
 
    public void DoSomething()
    {
        v = new RefactoredValues(obj);
    }
}


Any time DoSomething is called, it creates a new object representing the updated values. If an exception is thrown, the MyClass's values are left intact.



-- modified at 14:09 Wednesday 27th June, 2007
GeneralEvolution of Messaging Pin
Leslie Sanford19-Oct-06 5:15
Leslie Sanford19-Oct-06 5:15 
GeneralEnumerators as Synthesizer Components Pin
Leslie Sanford20-Sep-06 20:53
Leslie Sanford20-Sep-06 20:53 
GeneralAnonymous Methods as Glue Pin
Leslie Sanford17-Sep-06 14:30
Leslie Sanford17-Sep-06 14:30 
GeneralRefining the approach Pin
Leslie Sanford22-Jan-06 7:52
Leslie Sanford22-Jan-06 7:52 
GeneralFlowing down the Sink Pin
Leslie Sanford21-Jan-06 16:45
Leslie Sanford21-Jan-06 16:45 
GeneralFlow-Based Programming in C# Pin
Leslie Sanford29-Dec-05 13:07
Leslie Sanford29-Dec-05 13:07 
GeneralCombining Visitor, Observer, and Iterator Pin
Leslie Sanford25-Dec-05 21:29
Leslie Sanford25-Dec-05 21:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.