I thought I would comment on the problem of leadership because there are so many opinions and so many books, why not another little blog entry in the world of words.
Always gentle
Always decisive
Always open
I came up with these tenants, intentionally conflicting, to convey the personality profile of a leader. No leader can always be one or the other, the best leaders know when to switch and how to blend these ideas.
A team member presents an idea. The leader shows openness to listen and understand, then they have to switch, do they go to decisive to accept the idea and drive an action into the plan or to gently to discuss the idea until the team member sees its flaws.
It's never that simple though, a situation that distracts the team from a goal may require closed, firm, decisiveness. A good leader can be resolute and confident as opposed to closed and gentle.
Word games, yes, but these are the gray areas of human emotion, none of them absolutes, so a leader has to monitor guidelines and feel their way towards goals.
Your leadership goals might include, "be respected", "be approachable" or "I will always listen". Does this sound like a love fest? It's not a leaders goal to be liked but it helps. Leaders drive to a goal, the doors they break on the way are the tinder of their fire. This can conflict with being liked.
Your leadership goals might include more practical concepts like "will achieve goal within time line" or "maintain high customer rating". There is a cold, unemotional side to leadership that can help drive success but can loose some of the moral boundaries that we live by. Who should you fire when the budget is tight? When do you give up on the unteachable underachiever?
These are the sides of this game that I have the most difficulty with. I have always loved the teaching, mentoring and guiding parts of this job. I don't mind playing the motivational games to get more investment from a team. I do have a really hard time with knowing the right time and technique to cut.
I have a lot to learn about being a leader.
2/27/2007
Leadership, the conflict
2/02/2007
Two New Coding Mantras
What we tell ourselves drives what we are. A simple psychobabble statement. To a developer this drives what we produce.
Are you won't to say "that is good enough" or "sure that will work".
Or are you more likely to ask yourself "is this the best approach?" or "what would happen if we tried this alternative?".
Certainly, time and pressures push us back and forth between these attitudes so this isn't driven by personality alone but also represents an assessment of your personal priorities.
While reviewing code today I noticed two symptoms that represents trends of focus that the developer needed to address.
The first was the attention attributed to which class file they were typed their code in. Every word we type has a domain relevance that should force us to consider its appropriateness in the class we are editing.
The second is the tendency to think in instances instead of across time. The code I write today works today but will it work tomorrow or in another situation or environment. This actually occurred in a test for proving a date manipulation method worked and the test only worked yesterday.
So, from these two observations I decided I needed to more mantras to add to my preaching.
All tests work always.
They could probably be made a little more succinct and perhaps the second shouldn't be test specific but "that is good enough".
1/01/2007
Firefox and Skype Integration
I recently got back into using Skype to chat with my family in the UK and with the upgrade I was asked to install a new Firefox extension. This extension scans all the pages that you browse looking for phone numbers. When it finds them it converts them into Skype protocol call links.
Combine this with the new Skype free calls anywhere within the US and you get the easiest way to integrate voice into the web.
11/15/2006
Upgrade Blogger Version
Hope this upgrade doesn't cause anyone any problems :) They have a nicer templating editing feature and some better default templates than I can create.
4/04/2006
The Emotional Side of Design
Design sessions can often become emotional but this is not what I am talking about. People have strong feelings about the right and wrong way to do things but this is not what I want to address.
I want to try to describe the emotional feelings that one gets when a design idea is proposed. These aren't the strong passions of right or wrong but more of a gentle tickle deep inside that something is wrong.
We have all read articles on the "art" of programming and design. We have seen and experienced the best designers become the worst teachers. There is much written on the levels of knowledge from:
- I don't know how much I don't know.
- I have studied the process and am comfortable with it.
- This process is crap and these are the improvements we need to make.
- I understand thing well enough that I can explain it in simple terms.
we all exist at all levels. On many computing subjects I have no clue how ignorant I am and on others I teach.
I experienced a level 3 yesterday that went something like this:
Ed: Yes, you should replace VSS with CVS.
Customer: But CVS can't do file linking across branches. We only want to have to make a change once for all the product branches.
Ed: While that sounds like an advantage, it is actually the most horrific situation you could possible create for yourself.
I don't think I conveyed this statement quite as strongly as I might have but I couldn't articulate why file level release versioning was such a bad idea. I explained how I would manage it with branch and merge techniques in CVS and I think they saw this as a possible alternative but I didn't have the knowledge necessary to explain that the process they were using was exactly the thing that was killing their development throughput.
They gave me some hints to their atrocities, "We make developers send emails to the configuration team to check in and out files" and "The last release is managed on the O: drive because it was too difficult to manage in VSS".
Perhaps I could have got into the mathematics of why X files with Y differences takes Z brain hours to manage and the slope of the graph looks more like Everest than a manageable process.
So what is this emotional link we get with a set of ideas. Perhaps emotional is the wrong word, is it a 6th sense, intuition or perhaps just random gas.
Anyway, I have no answers, just experiences.
3/22/2006
Site Integration - Maps, Music, Chat and Sound
Site Integration - Maps, Music, Chat and Sound
I have been playing with techniques for site integration for a little while and have some interesting samples that are worth cataloging.
We all know that Web Services and B2B are the primary architectural vehicles for integrating computer systems but its not what is visible in the real world. Certainly we are building web services and certainly they serve to integrate systems but to the internet culture as a whole they are an irrelevance.
Let me say it this way. Corporations use B2B techniques to seamlessly integrate symbiotic features. Web Site builders use other techniques to integrate user experiences.
Perhaps we could look at the two as layers of the same cake. An internet user experiences features presented to them. Some of those features might require Web Services to achieve their goal but the user integration of experiences is a "higher" level integration.
Ok, so I can't explain it. Lets go with some examples. These are all on my home page.
Frapper
Frappr allows us to share graphical locations and present them as a map. A piece of this map can be integrated onto your web site. The XP Cincinnati site integrated this information into a blog entry.
They use simple javascript to link the two sites together.
Odeo Blogging
Odeo has developed a technology that allows us to record sound and publish that sound. Most use it for blogging but I have heard that some are using it to record and publish their music as well.
I have an Odeo blog and this allows me to record snippets of sound and then integrate that sound into my web site.
In this case the integration is achieved with an object tag that runs a some flash. The parameters point to the recorded mp3 that is stored on the Odeo site.
last.fm Music Listening
last.fm is a music tracking site. It supplies you with plugins for winamp, Media Player and others that will send the name of the music you are playing to their site. This can then be retrieved in a variety of formats to your website so that your customers can see what music you are playing at that moment.
This uses a little pseudo javascript insert that retrieves the HTML necessary to list your music.
Instant Messaging or Instant Talk
There are lots of features that allow you to publish your Instant Message online status to your web site but I was focusing on Skype since it includes the voice and video features that will ultimately become part of the communication applications of the future.
This site uses a little javascript with a new embedded protocol "skype:" so if you have an anchor with "skype:Edward Sumerfield?call" in it and you have the skype client installed then clicking on it will call me.
Conclusion
I think this point has been made in other blogs already but it doesn't hurt repeating. The primary site integration tool is javascript since it is the glue code that allows countless disparate technologies to interact.
If you are developing any kind of user interface tool today. Make very sure that you are including your javscript hooks. It will allow your tool to become integrated in ways that you can not imagine.
3/02/2006
Agile Set Me Free
My current client is thinking about adopting a more Agile approach to software development. We have had initial discussions and passed out books to read. We have been running an XP project for them for 6 months so they have all witnessed its success.
Someone found an article written in July 2002 that goes to town discrediting XP. So, I need to spend time trying to understand this 4 your old paper and trying to explain where it is misunderstanding the Agile proposals.
This is when it hit me. All the comments the author makes fall into one category. Fear. Fear of change. Fear that iterations make projects unmanageable. Fear that less documentation will cripple the maintenance effort. Fear that Test Driven Development will not produce a perfect object model. All of the answers stem from the base feelings that we have developed over years of working with requirements that changed and software that we kept on finding bugs in. We have beaten ourselves up so much about how little discipline we have and how bad we are at talking to the customer that we can't imagine that the opposite approach might be better. We are just not good enough to execute the perfect process we have been working at all these years.
All the complaints I read about Agile take everything it says at face value and fail to see the depth that it is suggesting. Release early is miss-read as ignore requirements. Allow the customer to change requirements is miss-read as never knowing what you are about to release. Don't write irrelevant documentation is immediately the terrifying idea that there will be no documentation.
So much confusion from simple, practical improvements in a process.
Agile is a liberation of our freedom to produce great software. Agile is a reconnecting with the essence that is writing software to solve business problems. Agile gives us the excuse to succeed when all we had before was more disappointed customers and another bug to fix.
Dam this job could be depressing. I have always loved programming but hated the job. It never made any sense until Agile opened my eyes. Actually, to be more specific, Mark Windholts opened my eyes when he pitched the test first practice to CinJug. Dude, you rock.
2/26/2006
Another Hour Another Rails Release
While I am a complete novice at this and my controller tests still don't work I have been able to add basic delete and create functionality to "WebZone On Rails" in about 5 hours.
The reason I couldn't do this in Java is because of ActiveRecord and the tight integration between the controller and the page.
With ActiveRecord I have been able to create and delete from an existing MySQL schema with just a couple of lines of code. With the integrated mock data infrastructure that comes with Rails I have full unit tests for all these steps.
With the tight integration of controller and page I am able to create controller instance variables and directly reference them from the rhtml pages. This makes it mind blowingly easy to load data and reference that data directly on the page while maintaining the MVC isolation. This is similar in concept to the .Net idea of the page and code behind being the same instance.
I still can't run my controller tests. Ran the gem update rails with no improvement.
Blog Entry From Camera Phone

Trying the mobile blogging feature at blogger.com. Just have to send an email to go@blogger.com and 'they do the rest'. Sound too easy.
Publishing Rails with SwitchTower
I need a simpler way to get my changes out to the web site. currently I am just copying file by file to FTP but this is tedious and error prone. I have heard that Switch Tower is the tool of choice for deploying Rails apps so here goes:
gem install switchtower
The install seemed to go well with the following dependencies also being installed.
Attempting local installation of 'switchtower'
Local gem file not found: switchtower*.gem
Attempting remote installation of 'switchtower'
Updating Gem source index for: http://gems.rubyforge.org
Install required dependency net-ssh? [Yn] y
Install required dependency needle? [Yn] y
Install required dependency net-sftp? [Yn] y
Successfully installed switchtower, version 1.0.1
Switch Tower needs to make some changes to the current rails app so that it can deploy it.
switchtower --apply-to [full path to rails app]
This seems easy enough but the first run gives me this. After a hour of google searching and drilling down into the gem install I find that the error, is infact, correct, the rails_generator/sripts/generate code does not exist as part if the switchtower install but I don't know where to get it so I am stuck.
d:/products/ruby-1.8.2-14/lib/ruby/site_ruby/1.8/rubygems/loadpath_manager.rb:5:
in `require__': No such file to load -- rails_generator/scripts/generate (Missin
gSourceFile)
from d:/products/ruby-1.8.2-14/lib/ruby/site_ruby/1.8/rubygems/loadpath_
manager.rb:5:in `require'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/activesupport-1.2.
5/lib/active_support/dependencies.rb:214:in `require'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/switchtower-1.0.1/
lib/switchtower/generators/rails/loader.rb:7:in `load!'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/switchtower-1.0.1/
lib/switchtower/cli.rb:248:in `execute_apply_to!'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/switchtower-1.0.1/
lib/switchtower/cli.rb:219:in `execute!'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/switchtower-1.0.1/
lib/switchtower/cli.rb:12:in `execute!'
from d:/products/ruby-1.8.2-14/lib/ruby/gems/1.8/gems/switchtower-1.0.1/
bin/switchtower:11
from d:/products/ruby-1.8.2-14/bin/switchtower:19:in `load'
from d:/products/ruby-1.8.2-14/bin/switchtower:19
WebZone port to Rails
I have been using a product called WebZone since 2001. I built it to do what I want and have extended for me. It supports other users and sharing data with them but primarily it has always been for me.
Its primary goal is to allow me to collect information in one place and organize it. It does this with good support for drag and drop into the browser, JavaScript scriptlets that can add the current page to your WebZone account and the ability drag your information around your WebZone to relate it in anyway that you want.
At 5 years old it needs some serious re-writing. When I started it I was just getting into test first so it doesn't have many tests. It has no mock data so continuous testing is out.
Since Rails is getting so much press I have decided to try it our there.
Phase One. Allow a rails app to read and navigate a WebZone database.
Phase Two. Add edit feature.
Phase Three. Add delete feature.
Phase Four. Add create feature.
We are in Phase three and it is now deployed to
So far so good.
The basic app was easy to create but I needed some ActiveRecord help from the XP Cincinnati team to get the database interface working nicely. Thanks to Jim Weirich.
With that part working, putting the rhtml files together to display the data was a snap.
A continuing problem is getting the controller tests working. So I am doing as much unit testing as possible but not being able to test the controller level is a serious problem. I am getting the error:
Exception: No url can be generated for the hash
{:targetId=>"1", :controller=>"read", :action=>"item", :targetType=>"TableText"}
generated_code/routing/generation.rb:5:in `generate_default_path'
.../action_controller/routing.rb:419:in `send'
.../action_controller/routing.rb:419:in `generate_path'
.../action_controller/routing.rb:415:in `generate'
.../action_controller/routing.rb:602:in `extra_keys'
.../action_controller/test_process.rb:86:in `assign_parameters'
.../action_controller/test_process.rb:295:in `process'
.../action_controller/test_process.rb:307:in `get'
webzone3/test/functional/read_controller_test.rb:20:in `test_item'
12/28/2005
Java Closure Chaining
I am playing with closures in java. Not as simple as the Ruby counter parts but a benefit to our programming arsenal I think.
I have come to realize two new things from this experience.
Testability
Compare
Iterator iter = list.iterator();
while (iter.hasNext())
{
A a = (A)iter.next();
do something
}
With
ListTools.each(list, new ClosureObject()
{
public void call(Object a_object)
{
A a = (A)a_object;
do something
}
});
How many pre-bugs do you see in each version. Both have 4 lines of code but the first requires 3 dot references which adds opportunities for those methods to do something unexpected.
Because of the the "final" requirement in java I found this construct to be a rarity. Instead we need something like this.
ListItemMunger munger = new ListItemMunger();
ListTools.each(list, munger);
System.out.println(munger.something());
class ListItemMunger implements ClosureObject()
{
public void call(Object a_object)
{
A a = (A)a_object;
do something
}
});
The most significant benefit with using Closures in java is that the loop-core is removed and is more testable than ever before.
public void testLoopCore()
{
ListItemMunger munger = new ListItemMunger();
munger.call(new SomeObject());
munger.call(new SomeObject());
munger.call(new SomeObject());
assertTrue(munger.something());
}
Now that I have classes that scan directories recursively, scan the files within them and then the line of text within each file this testability feature has been invaluable.
Closure Chaining
So I can scan directories, files and lines within files. How do I do that with these closure things.
DirectoryRecurseLookup.each("my path", new ClosureFile()
{
public void call(File a_directory)
{
FileLookup.each(a_directory, new ClosureFile()
{
public void call(File a_file)
{
StreamLineLookup.each(a_file, new ClosureIntString()
{
public void call(int a_lineNumber, String a_line)
{
System.out.println(a_lineNumber + " : " + a_line);
}
}
}
}
}
});
Well that's a lot of nesting but relatively simple syntacticly, no pre-bugs waiting to pop out at me. My first version took each of the closures into a separate class to simplify the code and make it more testable and it all worked fine.
Then I realized what I was doing wrong. I am just chaining closures so why can't the closures encapsulate that.
StreamLineLookup lineScanner = new StreamLineLookup();
FileLookup fileScanner = new FileLookup(lineScanner);
DirectoryRecurseLookup dirScanner = new DirectoryRecurseLookup(fileScanner);
DirectoryRecurseLookup.each("my path", dirScanner);
So as an example:
class DirecotryRecurseLookup implements ClosureFile
{
public static each(String a_path, ClosureFile a_closure)
{
// find files and pass them to the closure
}
private ClosureFile m_closure;
public DirectoryRecurseLookup(ClosureFile a_closure)
{
m_closure = a_closure;
}
public void call(File a_directory)
{
each(a_directory, m_closure);
}
}
10/27/2005
XP Cincinnati - Frappr
I am probably late to the party but this Frappr idea rocks. I created a frappr map for XP Cincinnati to see if we can get an idea of how spreadout we are.
Frappr XP Cincinnati
9/07/2005
Pre-bug - Variable Notation
A prebug, is a piece of code that is about to become a bug.
This is much like Martin Fowler's code smells (http://www.martinfowler.com/books.html#refactoring) but his writing comes from the perspective of how to find and recognize bad code and refactor it to improve it. The pre-bug concept is more like patterns for defensive coding strategies.
I coined the phrase prebug to describe code that you are typing in that will very soon be re-classified as a bug. Hopefully the test turns your prebug into a bug by failing but what if you can work out a way to type in your code that will prevent you from entering pre-bugs in the first place.
For example, one of the old C bugs that was so common was the single-equal-if problem.
if (a = 1) { printf("I think its one but who really knows"); }
For those unfamiliar with C, this statement would assign 1 to a and return true, always.
As a developer is typing in this code they may not be considering the possible bugs they are generating. So what if we retrained ourselves to always type this.
if (1 = a) { printf(("I know its one"); }
In this case the compiler will thrown an error saying that you can not assign a to the constant 1. What we have done here is slightly change the way we type in code and avoided a nasty bug from passing on down the development stream, potentially to production.
Here is another prebug idea that I want you to suggest solutions for. How would you enter this code to reduce the likelihood of the bug getting passed your ever vigilant eyes?
class Counter extends Thread
{
private static int counter = 0;
public void run()
{
while (counter < 10)
{
counter++;
doSomething();
}
}
}
The bug is that the counter is static and is able to run inside a thread, clealey a problem in this case. The same problem can occur with any static variable even its not so obviously in a class intended for multi-threaded operation.
The best solution I have found for spotting this kind of bug as I am entering it is to classify the variable names by scope and lifetime. We have all seem these notations in coding standards docs for years but I think the application of these ideas for the specific purpose of preventing bugs is not so commonly realized.
The java prefixes I use for these problems are:
statics: s_
instance: m_
arguments: a_
With the statics, instance and argument variables clearly identify to the reading eye what the scope of the variables are. The previous code should be entered like this.
class Counter extends Thread
{
private static int s_counter = 0;
public void run()
{
while (s_counter < 10)
{
s_counter++;
doSomething();
}
}
}
Eclipse offers auto-prefixing so all of its code generation features work once you have configured these notations.
8/23/2005
Emailing to a Blog
3/29/2005
Decoupled UI
My original question:
I want to be able to do this but it will not compile because the EventHandler does not have a no arg constructor.
IDictionary collection = new Hashtable();
collection.Add("myevent", new EventHandler());
A single event has the syntactic oddities
event EventHandler fred;
fred += new EventHandler(this.SomeMethod);
fred("x", eventArgs);
So how do I add fred to a collection so that I can do this
collection["myevent"] += new EventHandler(this.SomeMethod);
The answer:
I found the answer so here it is. Thanks to Mike Wood for his expertise.
The first and simple answer is that you can't do what I was asking. Events can't be constructed in the way that we would expect so can not be stored in a hashtable.
Background
The new information that I learned was about multicast delegates. These are the normal delegates that are created for us in our WinForms apps but they actually have the ability to store more than one callback.
It turns out that an event is completely unnecessary when declaring a callback. MSDN says that its just a safer syntactic representation of a multicast delegate (An Event to Remember).
delegate void MyCallback();This will fail to compile because fred is not assigned and you should not += to it.
MyCallback fred;
fred += new MyCallback(this.SomeMethod);
delegate void MyCallback();This will work because fred is first assigned with a delegate and then one more is added. Note that we can not re-assign a callback to the delegate to clear all existing delegates. This is the danger of the delegate syntax. This is now a multi-cast delegate since fred contains multiple callbacks that can all be invoked in turn by:
MyCallback fred;
fred = new MyCallback(this.SomeMethod);
fred += new MyCallback(this.SomeMethod);
fred();So the alternate syntax allows for the += in any situation. By placing the keyword "event" in front of your delegate declaration you allow the += to always work. This doesn't prevent you from doing an assignment so its not much protection but it does mean that whenever you see an assignment to an event you should be suspicious.
delegate void MyCallback();
event MyCallback fred;
fred += new MyCallback(this.SomeMethod);
Problem
What I wanted was a single class that could manage a set of delegates, categorized by data type, that could be subscribed to and published from different areas of your code to ensure that there was no compile time coupling between them.
Example of the problem:
class A
{
private B b;
public A()
{
b = new B();
}
public OnButtonPressed()
{
b.MakeBread();
}
}
class B
{
public MakeBread()
{
Console.Write("rise rise rise");
}
}
Notice how A has a reference to B. This means that when I want C to do something when the ButtonPressed event occurs I have to edit A to add a new reference. Also, If I want to add another layer between A and B then I have to change A to make the new reference and move the B reference into the new location. Lots of code changing is bad from a maintenance and testing perspective.
Design principle. Open Close Principle
"Software entities (classes, modules, functions, etc.) should be open for extension, but closed for modification."
C2 Wiki - OpenClosedPrinciple
In this example I had to change lots of existing code to rearrange my structure. This is very common in UI applications as you move the UI around the elements of the UI have to be moved between source files and the call backs have to be moved as well.
Solution
The solution to the original problem is to put a delegate in the hashtable and then add additional delegates to the same element. No events were used during the making of this code.
I wrapped this in a class called PubSub with two static methods Subscribe and Publish (Download Solution)
Example:
class A
{
public A()
{
}
public OnButtonPressed()
{
PubSub.Publish(new UiEventButtonPressed());
}
}
class B
{
public B()
{
PubSub.Subscribe(typeof(UiEventButtonPressed), new EventHandler(MakeBread));
}
public MakeBread(object sender, EventArgs args)
{
Console.Write("rise rise rise");
}
}
Notice now that class A doesn't know who is reacting to the ButtonPressed event, all its doing it notifying the world that something happened. Class B on the other hand is a simple standalone class that knows it has to do something when the button is pressed so subscribes for that event.
I could now write a class C that subscribed for the same event without changing any existing code at all. This is a massive maintenance and test advantage. Imagine being able to extend an existing system by dropping a new dll into the deployment. Sweetness.
This type of abstraction also offers extension advantages. Imagine the day when your UI gets so slow that you have to start backgrounding some of the actions. You can add extend your PubSub class to submit all the callbacks on background threads.
What about the idea of distributing your application. Say you want a background service to manage the synchronization of data from your UI to some external storage. You could extend PubSub to post events across process or machine boundaries and plug into your existing application without changing it.
Obviously, I am simplifying this a little but the abstractions are the key to making your system flexible enough to be tolerant of these kinds of changes.
2/18/2005
CinDnug 2-20-05
Doug Rohrer, of Avanade Inc employ, presented an overview of the Microsoft Enterprise Library (entlib).
Apparently Avanade are the original writers of these libraries as the copyright at the top of the source indicates. Oh did I mention that we get the source? The license allows you to modify for your own use but you can not redistribute your alternations and you must leave any existing copyright notice at the top if you do not change the code.
// Copyright © Microsoft Corporation. All rights reserved.
// Adapted from ACA.NET with permission from Avanade Inc.
// ACA.NET copyright © Avanade Inc. All rights reserved.
This is a library of "application blocks" that are intended to help developers with the basic plumbing of an application. A block is just a subset of a library which is akin to an assembly. In java terms its just a jar. I don't know why "block" replaced "library".
Doug writes about the entlib in his blog.
Doug Rohrer's Blog
Download it here after some registration steps:
Microsoft Enterprise Library
I am afraid that I arrived 30 minutes late so missed a couple of the initial block descriptions but the website doc is good. These are the blocks in the entlib
o Configuration Application Block
o Data Access Application Block
o Caching Application Block
o Exception Handling Application Block
o Logging & Instrumentation Application Block
o Cryptography Application Block
o Security Application Block
One the most interesting features of this library is that it comes with source. When you download it you get a selfextracting exe that unloads the source to your disk and, with compile checkbox checked, proceeds to compile the library in place. Having the source available makes this a far more valuable resource since we can not only use it but also learn from the code.
All the libraries use the Configuration block and most use the Logging block so there is a good synergy between them all. They all have good factory abstractions so its simple to replace the various providers with your own implementations. Each folder in the source contains a Test directory where NUnit tests sit.
Here is a simple sample of each.
Logging:
Logger.Write("My message", "someMessageCategory");
Each write can optionally, specify a category that can be configured in the configuration file and drives where the message is written to.There is no method level distinction between error, warning, info and debug messages. There is also no class level message filtering. You could use the category names for either but not both.
This being a class level API, instead of instance level, its flexibility is limited. A simple improvement would be to allow us to create our own reference to the logger and then we can choose to make it an instance or static property.
So, compared to Log4Net (http://logging.apache.org/log4net/), this solution is not adequate.
Configuration:
settings = (MySettingsType)ConfigurationContext.GetConfiguration("section name");
settings.MyProperty
The advantage of this package over the built-in App.config is that you can select the storage type. This seems like a good solution for .Net app config loading.Data Access:
myDataSet = DatabaseFactory.CreateDatabase("Sales").
ExecuteDataSet("GetOrdersByCustomer", myCustomerId );
I missed the comments on this one but the code snippet looks simple enough. I asked Doug after the presentation about support for Transactions but he didn't have any concrete information.Longer term I am more interested in libraries like NHibernate (http://nhibernate.sourceforge.net/) that support a full Object/Relational mapping solution. Then you can look into Spring for .Net (http://sourceforge.net/projects/springnet/) and abstract your transaction management out of your code completely.
Caching:
factory = new CacheManagerFactory(Context);The location of a cache can be configured as in-memory or in-database so it can be used within a clustered environment. It supports various cache ageing algorithms that allow you to control how stale you data gets.
cacheMgr = factory.GetCacheManager("SmallInMemoryPersistence");
cacheMgr.Add("key", "cache");
cacheMgr.Remove("key");
cacheMgr.Dispose();
I am unsure about this library. With a IDictionary type interface you are limited in the types of data that you can cache. Not that you can't store anything but that you can't get it back as easily. Say I wanted to store a row from a dataset, what would I use for a key? It would have to be the unique key to the row but if that is a compound key I would have to come up with a string representation of that information.
I am sure that there are some good uses this library can be put to but with caching being such a complex layer I am not sure that it is flexible enough for the more complex applications.
Exception Handling:
catch (Exception ex)The goal here is to centralize the processing from all our catch blocks. The HandleException method reads configuration where a set of exception handlers are configured. You can relate a list of handlers to a policyname that can log, write to the event log or add you own custom handler.
{
bool shouldRethrow = ExceptionPolicy.HandleException(ex, "policyname");
if (shouldRethrow)
{
throw ex;
}
}
The biggest downside to this approach is that you loose all your context logging. Most exception handlers are going to format a message that includes information from the local context that will help debug the problem. The only way I can see to add this feature and still use this exception handler is to wrap the thrown exception in your own exception and pass that in.
MyException mx = new MyException(ex, "Context specific message");I question whether the function that I want to perform in my exception handlers should be abstracted to the configuration file level. Certainly, common code should be extracted into some application specific class but to standardize that and push it all the way to a config file seems unnecessary and not very useful.
bool shouldRethrow = ExceptionPolicy.HandleException(mx, "policyname");
Crypto:
Cryptographer.EncryptSymmetric("dpapiSymmetric1", "plain text");
Cryptographer.DecryptSymmetric("dpapiSymmetric1", encrypted,);
Cryptographer.CreateHash(hashInstance, plainTextString);
Doug also demoed encrypting with sha1 and it was as simple. This is going to be really easy and will, hopefully, ensure that every programmer gets comfortable with this subject matter and uses it. There is way too much data out there that is not secure because the average programmer doesn't know how to use the cryptography api.Security:
factory = new AuthenticationProviderFactory();A simple authorization and authentication abstraction that will simplify your login pages and access checks in your code. You can plug in your own providers and perform application specific checks as needed.
IAuthenticationProvider provider = factory.GetAuthenticationProvider();
if (provider.Authenticate(new NamePasswordCredential("Fred", "password"), out identity))
{
// Woohoo
}
factory = new AuthorizationProviderFactory();
provider = factory.GetAuthorizationProvider();
if (provider.Authorize(principle, context))
{
// Woohoo
}
Conclusion:
Some of these seem to be very useful libraries that I expect to start using in my current project.A possible improvement that could be made to the distribution would be to formalize the mock classes that are used. The "Test" folders are full of mock classes that help prove that various pieces of functionality work. When I am testing my code I will have to concoct some mock configuration to drive the various paths though my code. If the library supplied some mock implementations it would save me from writing my own.
Thanks Doug for a great presentation.
2/11/2005
Cold basement
My office is in my basement. Yes, a little corner of a cold dark hole in the ground. Winter makes it intensley cold with one electric heater making my body hot on one side and leaving the other blue.
Still, it beats trecking through the snow to a small dark cube.
Cincinnati doesn't get too cold in the winter, not compared to the more northern areas. However, this is my home and that gives me the right to whine about it a little.
The view from our back window is nice after a fresh snow. The last snow was windless so produced some excellent depth on the individual branches.
2/06/2005
Referencing EXE assemblies in VS.net
The problem, as discussed in the CinDnug use group, was that a VS.net project that contains tests can not reference a project that generates an exe. The only design solution is to make the exe code a one liner that calls a main dll but this has quite an impact on other design decisions.
When you try to add a reference from a dll project to an exe project in VS.net you get a warnings stating that the reference target has to be a dll. You can solve this problem with some judicious editing of your .csproj file.
Editing your .csproj file will show references declared like this
<Reference
Name = "ProtoTabBack"
Project = "{6292AE62-0514-40F7-99C0-C2C181BF9A15}"
Package = "{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}"
/>
<Reference
Name = "TabulatorFront"
AssemblyName = "TabulatorFront"
HintPath = "..\TabulatorFront\bin\debug\TabulatorFront.exe"
/>
Note there are two types of declarations here. The first type uses the package project guid that you can find in your .sln file in the following format. The first guid is the Package and the second the Project.
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TabulatorFront",
"TabulatorFront\TabulatorFront.csproj",
"{DD6F402B-1823-489F-AC6C-B9B8FE18391D}"
ProjectSection(ProjectDependencies) = postProject
EndProjectSection
EndProject
Using this "project reference" in your .csproj file results in VS.net flagging the reference with a little yellow triangle and saying that it has to be a .dll file.
However, using the second Reference format and referring to the exe file directly works. I am now able to code to and link my tests with the exe project code, utilize existing test infrastructure to write tests against UI code and keep my test code out of my production deployments.
Thanks James for the suggestion.
2/03/2005
Robust code
Trying to get people to stop hard coding expected results in tests is not easy.
IList rowList = db.GetSomeRows()
Assert.Equals(4, rowList.Count);
EEEEEEkkkkkkk
Code is like poetry
blowing in the wind,
beaten from left and right
crashed and regularly skinned,
choose the best of parchment
to ward against the eternal din.
