Welcome to Joe E. Bennett Sign in | Join | Help

Prism Demo

I’ll be speaking July 22 about building a simple WPF application using Prism (Composite Application Guidance or CAG just doesn’t roll off your tongue like Prism) for the TRINUG Design Patterns group.  If you’ve never seen Prism and what it can do for you, you should come see it.  It’s very cool stuff.

Posted by jbennett | 0 Comments
Filed under: , , ,

Code Contracts and Pex

I’ll be presenting on Code Contracts and Pex at the June 17th meeting of the TRINUG .NET in Depth SIG.  If you haven’t used these two products from Microsoft Research, you have missed a treat!  Code Contracts allow you to express pre and post-condition coding assumptions as well as object invariants in .NET source code.  Pex is automated white box parameterized unit testing with very high levels of code coverage.  Both products are very cool and together they are awesome!  Code Contracts has been released as a separate .NET library and will be a part of .NET 4.0 when it’s released.  Pex is still pre-release software but has been very stable for me and is definitely worth getting for some eye-popping demos at the next geekathon.  Get yourself some Code Contracts and Pex bits and have some fun.

Posted by jbennett | 0 Comments
Filed under: ,

Windows 7 RC1

Windows 7 RC1 has been released to the public.  This is the replacement for Vista that so many have been waiting for.  This version is available through July 2009 and expires June 1, 2010.  You will want to get some new bits though before March 1, 2010, because that is when your PC starts shutting down every two hours as a friendly reminder.  So, dig out a PC that isn’t used for production and install the bits.  Get them while they are hot.

Posted by jbennett | 0 Comments
Filed under:

Richmond Code Camp

I went to the Richmond Code Camp 2009.1 event this past weekend.  It was a last-minute decision to go and I’m glad I was able to attend.  It was an excellent event, well organized, plenty of good speakers, and pizza for lunch.  What more could you possibly want?  I spent the day immersed in WPF and Silverlight sessions.  They make me want to write code!  I really enjoyed it and will definitely go back again.  Thanks to Andy and the rest of the gang in Richmond.

Posted by jbennett | 0 Comments
Filed under: , , ,

Good Free Stuff

I may have mentioned before that I love free stuff.  If someone is giving away a free T-Shirt or coffee cup, I’m in line.  I also like to learn about different technologies.  Now, if I could just find a way to combine the free and the learning I’d be a happy man.

As it turns out, our friends at Microsoft created Ramp Up for guys just like me.  So if you want some free basic technical training, head on over and take a look.  You may not get a free coffee cup, but you do get some good things to put in your head.

Posted by jbennett | 0 Comments
Filed under: ,

Sentient DSLs

The Channel 9 guys made my day today!  Check it out.  http://channel9.msdn.com/shows/10-4/10-4-Episode-14-Sentient-DSLs/

Posted by jbennett | 0 Comments
Filed under:

Back by Popular Demand

Last month I spoke with the TRINUG Design Patterns group about Dependency Injection with the Unity framework.  There was a lot of interest and some of the folks wanted more.  So, this month I will be speaking there again and demonstrating the interception capabilities of Unity.  I'm also going to demo the Validation application block from the Enterprise Library.  EntLib and Unity together offer some interesting possibilities. 

Posted by jbennett | 0 Comments

Intercept Something

I've been working with the Unity DI framework lately.  The guys at P&P have created a piece of work you really should get to know.  Unity encourages developing highly cohesive and loosely coupled modules for use in your application.  That's great, but there are some cross-cutting concerns that tend to muddy up our code.  For example, logging various kinds of information at runtime is a common task.  Sometimes it seems as if we have as much logging code in our applications as we have code that actually does what our application was intended to do.  Including that logging code just kicks our cohesiveness out the door.  We are no longer focused on just one task.  We now are focused on one task and logging.  It can make a method hard to understand just because the logging code tends to mask what the method is actually doing.  Unity provides a solution to that problem.

The Interception Extension for Unity provides the capability to intercept a method call, do something before the call and after the call.  That sounds like it's ideal for logging doesn't it?  As it turns out, it actually works very well for handling that kind of cross-cutting concern without muddying up our code.  An easy way (but not the only way) to accomplish interception is to create a new LogAttribute and override its CreateHandler method.

Make sure you have references to Microsoft.Practices.ObjectBuilder2, Microsoft.Practices.Unity, and Microsoft.Practices.Unity.Interception in your project and a using Microsoft.Practices.Unity.Interception directive at the top of your source file.

public class LogAttribute : HandlerAttribute

{

    public override ICallHandler CreateHandler(Microsoft.Practices.Unity.IUnityContainer container)

    {

        return new LogCallHandler();

    }

}

Now create the LogCallHandler class like this:

public class LogCallHandler : ICallHandler

{

    private int order;

    public LogCallHandler() : this(0) {}

    public LogCallHandler(int order)

    {

        Order = order;

    }

    public int Order

    {

        get { return order; }

        set { order = value; }

    }

    public IMethodReturn Invoke(IMethodInvocation input, GetNextHandlerDelegate getNext)

    {

        ILogger logger = container.Resolve<ILogger>();    // get your logger

        logger.Write("Precall logging");    // log whatever you want before the call

        var result = getNext().Invoke(input, getNext);  // this invokes the method you called

        logger.Write("Postcall logging");    // log whatever you want after the call

        return result;

    }

}

Now, add the Interception Extension to the container and configure it to use the InterfaceInterceptor.

container.AddNewExtension<Interception>();

container.Configure<Interception>().SetInterceptorFor<IMessenger>(new InterfaceInterceptor());

You have the container configured so that any class that implements the IMessenger interface can have its methods intercepted.  To wire everything together, use the LogAttribute  you created on the methods of IMessenger you want logged.  In the concrete class, when you call a method of the IMessenger interface that has the LogAttribute on it, it will be intercepted and the Invoke method above will be called instead.  The information you wanted logged before the call is logged, then the call is made to the method you called, then the information you wanted logged after the call is logged.

Enjoy!  More information is available on using Interception with Unity.

Posted by jbennett | 0 Comments
Filed under: ,

Object Responsibility

One of the most basic concepts of object oriented design is the class.  A class is one of those things that we know when we see one, but describing what it is, is a little harder.  More importantly, how do we know when we are through creating one in code?  What should be included in it and what should not?  One definition could be when we quit typing, and that is a definition I have unfortunately seen too often in code.  Designing a class correctly is more than looking at a source file and saying "This Widget doesn't have too much stuff in it, I think I'll put the code for the new Zinger in here."  An object should be responsible for maintaining its own state and behaving in a way that is reasonable.

I like to think of a class as a model of something real.  Suppose I had a class named Apple.  What is an Apple and how do I represent it in code?  Well, it probably has a name and depending on your point of view it might be "Fuji" or "Mac."  Let's take the fruit and think of other things that might help describe it.  Size and weight are possibilities, and so is color.  We might even need some indication of whether it is ripe or a measure of its sweetness.  All those things are the state of an Apple.  They represent a particular instance of an Apple with variables that contain values at a particular point in time. 

An object is more than just state, it also includes behaviors.  Behaviors are represented by methods in our classes.  What kind of behaviors can an Apple have?  Watch one for a while and see what it does.  If you actually did that exercise, your list of behaviors is probably pretty short.  This is characteristic of a category of objects called Entities.  Entities have very few behaviors.  When you describe what software should do, they are some of the nouns in the description.  They are typically inanimate, have very few of their own behaviors, and are acted upon by other objects.  While that description is not always accurate, if you find something that fits that description you have probably found an entity.  Examples of entity objects might be a Book in a library application or a DVD in video store software. 

Should an Apple have a Find method that locates a particular Apple in a Basket of Apples?  No, it is not the responsibility of an Apple to find other Apples.  An Apple should be unaware of other Apples or even the Basket instance that is its container.  So how is a particular Apple found in a Basket of Apples?  Should the Basket class have a method named FindApple?  No, have you ever seen a basket search for anything?  I haven't.  The way you model an object in code should be as close to the object in the real world as possible.  It is the responsibility of a Basket to hold things, not search for them.  A Person might be interested in a particular Apple.  So, should a Person have a FindApple method?  Probably not, but people use tools to help them do things.  A type of object called a Collection knows how to manipulate multiple instances of some class.  So a person would use an instance of a Collection as a tool to find a particular instance of an Apple in a collection of Apples.

To define an object we need to understand exactly what it looks like and how it behaves.  We describe an object in code by the internal variables (and externally visible properties) used to store its state, other variables used to store values required by one or more of its behaviors, and only the behaviors that are required for that object.  What else should go into a class?  NOTHING!

While this is not meant to be the last word on object responsibility it is meant to be a guideline on how to create well-designed objects.  Understanding what an object's responsibilities are helps in knowing when to stop adding things to your classes.  Use common sense and good judgement and don't add unnecessary things to your classes, it just clutters up your code and makes maintaining your software harder and more time consuming.

Posted by jbennett | 0 Comments
Filed under: ,

Design Patterns

I'll be speaking to the TRINUG Design Patterns group on February 25, 2009 about creating highly cohesive and loosely coupled applications using the Unity Dependency Injection framework.  Come check it out.

Posted by jbennett | 0 Comments
Filed under: ,

Loosely Coupled Applications

I've been working with the Unity Dependency Injection Application Block lately.  It is part of the Enterprise Library beginning with version 4.0.  You can also get it as a separate download without EntLib.  Pick your flavor at www.CodePlex.com/Unity

The benefits of using Unity (other than the cool factor) are from the way it encourages developing your software as loosely coupled modules.  Anyone who has ever worked with a tangled mess of spaghetti code will understand the advantages of loose coupling. 

Although it's great as is, there are a few shortcomings in version 1.2 I'd like to see addressed.  I'd like to see MS throw some more complete extensions into the mix.  Currently, you get a simple event broker extension.  It's very cool and easy to use.  Limitations on the type of the event and event handler are a bit of an annoyance, but you can work around that.

Overall, for a version 1.x product the guys at Patterns and Practices have produced some very cool and very useful software in Unity.  You should get it now and use it in your projects.  Thanks P&P guys!  I look forward to future versions of Unity.

Posted by jbennett | 0 Comments
Filed under: , ,

VSLive Rocks!

I spent the last week at VSLive in Dallas.  Think mental overload.  There were more sessions I wanted to attend, than there was time to attend them.  John Papa gave some very interesting presentations on the Entity Framework.  Miguel Castro gave an excellent presentation on sexy extensibility patterns.  Richard Hale Shaw chaired the event and his presentation on applied generics was great!  There were just too many great presentations to mention.  It was a fun time and it should be on your list of things to do.

Posted by jbennett | 0 Comments
Filed under: , ,

Enough Said...

PDC

Posted by jbennett | 0 Comments
Filed under:

Slick Tools from SlickEdit

Over the last few weeks I've been using the new suite of tools from SlickEdit for Visual Studio.  They are organized in two toolboxes, one for editing and one for version control.  Installation into Visual Studio 2008 was smooth and painless.  Installation into Visual Studio 2005 was not quite as smooth, but I've been using 2005 for fewer tasks since 2008 was released so I'm not really bothered by that.  Your mileage may vary.

The Editing Toolbox does not include the SlickEdit editor, but utilities that make the time you spend editing in Visual Studio more productive.  Included in the toolbox are:

Aliases and Acronyms: I doubt I'll be using these much.  Aliases for directories save you keystrokes when opening files and acronyms are a few characters that expand to longer class or method names.  I find myself typing directory names so few times I forget about aliases and by the time I remember what the acronym is for a class name I could have typed it and been on about my business.  Maybe I'm just not used to it, but I don't see myself as an alias and acronym kind of guy.

Auto Code Doc Viewer: This one is a gem.  Have you ever wanted MSDN style documentation for your code?  Have you been a sad developer since NDoc fizzled?  Have you ever wondered what happened to Sandcastle?  This little jewel does it on the fly, right in Visual Studio.  Very nice!

Code Annotations: This is another keeper.  Do you ever write notes on a legal pad about some feature in code or an idea you don't want to forget?  Just use annotations.  The source code file is not modified and you don't have to look through your desk drawers wondering what you did with that legal pad.  I think I could learn to love this one.

Comment Wrapping:  This is my favorite in this toolbox!  I write comments for at least the public and protected members in my code.  Then I read the comments, and thinking I'm going to make them clearer, spend the next five minutes rewriting and moving things around, making sure the lines are about the same length, putting the triple-whacks back at the beginning of the line and driving myself nuts over what should be a simple task.  That's all history, now I just edit until I'm satisfied with the comment and comment wrapping takes care of wrapping at the proper line length and keeping the triple-whacks where they belong.

Icon Extractor:  I'm kind of lukewarm on this one.  I just don't do enough icon extraction to get excited.  If you do, then this is worth a good look.

Quick Profiling: A profiler is one of those tools that when you need it, nothing else will make you happy.  There have been several times in my career that I've looked for a free profiler because I needed to do some quick profiling and didn't want to spend a few hundred dollars to use one for a couple of hours.  Having a good one right in Visual Studio is a good thing.  Sprinkle a few Trace.WriteLine calls in your code and analyze the timings in a viewer in Visual Studio.

Regex Evaluator:  If you have ever used regular expressions you know how complicated they can be.  Now you can express yourself regularly with ease.

Code Navigation: This is another utility that I probably won't use much.  It allows keyboard shortcuts to take you from a symbol to its definition and to find everywhere that symbol is referenced. Those capabilities are already in Visual Studio; I'm used to how they work and probably won't change my ways.

Word Completion: I can't really say wow about this one.  This feature is available in the IDE and I don't really see a need for a replacement.

The Versioning Toolbox is intended to make using source control easier and more convenient. 

CVS and Subversion Source Control: Excellent support for both CVS and Subversion is provided and their commands can be used right in the Solution Explorer.  If you use either of these popular products, source control just got easier.

Backup History: Easily compare and restore any version of your files.

DIFFzilla: This is my favorite diff and merge tool.  It's easy to use and rock solid.  Diffing and merging of anything from files to entire source trees is fast and easy.

Find Version: Do you need to find all the files Frank edited and checked in last week?  It's easy with this tool.  Now you can easily find which files meet specified criteria.

Line Version Info: We've all looked at information stored about the last check-in that affected a file.  Now you can look at the same kind of information for each line in a file.  The devil is in the details.

Version Graphs: Get a graphical view of the history of your files.  This is interesting, but I'm not sure how useful. 

Version History: View the complete history of each check-in of your files.  The date, branch, author, check-in comments, and labels are available.

Visualizations: Color schemes indicate specific characteristics about each line in your source file.  For instance, who wrote this line and when that line was checked in can be answered visually.  Talk about an explosion in a paint factory...

SlickEdit has created a couple of toolboxes that contain some very nice tools.  They work well in Visual Studio and don't interfere with your normal workflow.  For the price of a tank of gas, get yourself some tools.

Posted by jbennett | 0 Comments

Brad Was Here

Brad Abrams came to the TRINUG meeting on April 9 and knocked us all out.  He always gives a great presentation and this time he gave us a peek at some of the new technologies from Microsoft.  He demonstrated some Silverlight 2.0 features, and showed the MVC framework.

FarPoint came through with a great meal!  Barbeque with cole slaw, baked beans, hush puppies and banana pudding, and of course, sweet tea.  A regular feast and much better than the typical pizza.  And they didn't just bring the food, they cooked it!  Way to go FarPoint!  Thanks to the whole gang over there, they are great folks.

Posted by jbennett | 0 Comments
Filed under: ,
More Posts Next page »