Prism Digg/Twitter Search Client on Channel 9
by riles on Jun.08, 2009, under News
The Microsoft Patterns & Practices team have posted links to the Channel 9 Prism digg/twitter search application on their CodePlex site. Check it out: patterns & practices: Composite WPF and Silverlight – Home
F# PowerPack for VS2010 Released
by riles on Jun.07, 2009, under News
I am very excited to note that the F# PowerPack has been released for VS2010. So what are you waiting for? Go grab it!
Also, I had performed some tests comparing F# with C# data access and was surprised by the results. Once I get the PowerPack installed for VS2010, I want to re-run it and see if it runs any differently in .NET 4.0, then I’ll post what I found.
ViewModel Futures
by riles on May.12, 2009, under Patterns
Glenn Block asked two questions on Twitter tonight that were too good to pass up. First, do you want better tooling, more testable data binding, or a ViewModel base class? I agree with whoever said patterns exist to make up for faults in a language; however, in this case, I think I would choose enhancements to data binding. It’s a little too magical, imho.
I would like to see a ViewModel base eventually, though, as that would be one less thing to wire up myself, and it hopefully silence all the people complaining about the lack of a model in MVC. (Yes, I am thinking the backend models should be sharable among WPF, Silverlight, and MVC.)
Glenn’s second question related to tv target audience. I am always a fan of simple explocicity, to borrow a word from JB. I think that’s what the experts use. Also, I don’t know many who want to me mediocre some day, so going for the best and letting it trickle down is a great idea.
Just my $.02.
YAGNI–Whose Definition of Simple?
by riles on May.12, 2009, under Patterns, Projects, Tips
I have read a lot about YAGNI lately, especially regarding TDD. The thing that keeps bugging me is the definition of “simple.” Who defines simple? For instance, wouldn’t static methods be simpler than building objects? You could then write more functionally. Or is that not simpler to you? If you follow command-query separation, wouldn’t building everything as either pure functions or commands be simplest? JB and I have found this set of patterns immensely easy to create and test of late, especially in comparison to the ever-increasing-in-complexity procedural/OO code in place before.
So I guess my question is this: Is it really so bad to start with some basic patterns that will let you refactor more easily? I think the desire to make things as simple as possible–especially when you know you will need it–can be a waste of time and a good way of getting bad code into your source.
I know I will hear it from the Agile community that I just don’t get it, but I think I do. I really like starting simple and keeping things in nice, bite-sized testable chunks. And yes, I’m still learning. However, without a consistent and meaningful definition of “simple,” we’re likely to end up with a follow-up movement of making things complex for the sake of extensibility again.
So what do you think: is CQS too complex a starting point, or is it a nice, “simple,” and testable approach for YAGNI?

CQS – A Literary Perspective
by riles on Apr.15, 2009, under Patterns
If you have been following the DDD and DDDD waves, you’re sure to have come across the CQS pattern. When I first heard of this, I immediately liked it but thought it was surely a pattern for very, very large systems. Most systems probably don’t need CQS, but this morning over breakfast, a discussion with my wife on child learning patterns made me rethink this.
We have a friend whose children have grown at very different rates of reading comprehension and writing skill. The interesting part is that the rates are nearly opposite from one another. The one with excellent reading comprehension does not excel at writing while the other is and excellent writer but has trouble reading. I found this somewhat strange. After all, logically, I would think that the one who reads should be able to write better. But that’s not the case. No one can do everything best. The same is true of databases.
This is such a true statement that in the Collective Intelligence session at the Houston ALT.NET Open Spaces, four distinct database tiers were promoted for proper separation of concerns to allow each tier to most effectively perform its task. Is this necessary for every application? Probably not, but as we move toward a more virtualized server world, the cost is really swinging in the favor of using multiple databases for reading and writing concerns. This may break the YAGNI principle, but I think we may often find that simplest may really be the best, simplest, smallest part that can fit the bill. (I’m sure that last statement will really ruffle feathers, but that’s where I am atm.)

Free WPF-LOB Training
by riles on Apr.02, 2009, under News
Karl Shifflett and Jaime Rodriguez will be traveling to Los Angeles, London, New York, Chicago, and Phoenix to teach WPF MVVM for line-of-business apps. If you are interested, you can read more on their training event information and registration page.
Acase().for(patternType.FluentInterfaces).create()
by rookieone on Apr.01, 2009, under Patterns, Samples, Tips
When I was first exposed to the idea of fluent interfaces my response was… big flipping deal.
It wasn’t until I actively started using fluent interfaces in my code did I begin to see their power and elegance.
What is a fluent interface? Here is the obligatory link to wikipedia
In simple terms, its returning a type instead of void in order to achieve method chaining.
The end goal of the method chaining is to provide a more readable interface and code.
First, does it break the Law of Demeter?
Law of Demeter doesn’t equal the number of periods. I am of the opinion fluent interfaces do not violate the Law of Demeter.
What is LoD? Another link to wiki and here is a link to a stack overflow on this very subject!
To me, Law of Demeter is about restricting communication between objects.
A common violation of LoD (imho) is the exposure of a list property on an object. I believe this serves as a good example of LoD as well as being an example on how to make a fluent interface.
A Person object has a name and a list of friends.
1: public class Person
2: {
3: public string Name { get; set; }
4: public List<Person> Friends { get; set; }
5:
6: public Person()
7: {
8: Friends = new List<Person>();
9: }
10: }
I could then add friends by…
1: var roger = new Person{ Name="Roger" };
2: roger.Friends.Add(new Person { Name = "Eddie" });
3: roger.Friends.Add(new Person { Name = "Freddie" });
4: roger.Friends.Add(new Person { Name = "Gordie" });
Now this is pretty typical, so what’s the problem?
Well my code knows WAY too much about Person. I know it has a list of friends and if they change that list to say a dictionary, I am hosed.
Not only that, but poor Person class… people can add friends to his collection without him every knowing. What if some additional logic needs to be done when adding a friend?
What if the person wants to record the birth date of every friend so they can send out birthday cards? Person is SOL.
As for Law of Demeter, my code is using the Person object to communicate through to the List<Person>. I am exposing my code to changes in Person.
Let’s change Person to eliminate this problem.
1: public class Person2
2: {
3: public string Name { get; set; }
4: private readonly List<Person2> _friends;
5:
6: public Person2()
7: {
8: _friends = new List<Person2>();
9: }
10:
11: public void AddFriend(Person2 friend)
12: {
13: _friends.Add(friend);
14: }
15: }
Now the only way to add a friend is through Person. Yippie!
1: var roger2 = new Person2 {Name = "Roger"};
2: roger2.AddFriend(new Person2 { Name = "Eddie" });
3: roger2.AddFriend(new Person2 { Name = "Freddie" });
4: roger2.AddFriend(new Person2 { Name = "Gordie" });
If I wanted to make this a fluent interface all I would need to do is instead of returning void, return the Person class.
1: public class Person3
2: {
3: public string Name { get; set; }
4: private readonly List<Person3> _friends;
5:
6: public Person3()
7: {
8: _friends = new List<Person3>();
9: }
10:
11: public Person3 AddFriend(Person3 friend)
12: {
13: _friends.Add(friend);
14: return this;
15: }
16: }
Now I can do the same logic like…
1: var roger3 = new Person3 { Name = "Roger" }
2: .AddFriend(new Person3 { Name = "Eddie" })
3: .AddFriend(new Person3 { Name = "Freddie" })
4: .AddFriend(new Person3 { Name = "Gordie" });
That is pretty cool, but fluent interfaces really shine with the builder pattern.
This time around I want to force construction of a person through a builder and have the builder use a fluent interface. Notice my Person’s constructor and fields are private. I embed the builder class within the Person class so the builder has access to the constructor and fields. In this manner only my builder class has access to constructing a person. My builder can now act as an anti-corruption layer for Person.
1: public class Person4
2: {
3: private string _name;
4: private List<Person4> _friends;
5:
6: private Person4()
7: {
8: _friends = new List<Person4>();
9: }
10:
11: public Person4 AddFriend(Person4 friend)
12: {
13: _friends.Add(friend);
14: return this;
15: }
16:
17: public static PersonBuilder createAPerson()
18: {
19: return new PersonBuilder();
20: }
21:
22: public class PersonBuilder
23: {
24: private Person4 _person;
25: public PersonBuilder()
26: {
27: _person = new Person4();
28: }
29:
30: public PersonBuilder named(string name)
31: {
32: _person._name = name;
33: return this;
34: }
35:
36: public PersonBuilder withFriend(Person4 friend)
37: {
38: _person.AddFriend(friend);
39: return this;
40: }
41:
42: public PersonBuilder withaFriendNamed(string name)
43: {
44: var friend = createAPerson().named(name).finish();
45: _person.AddFriend(friend);
46: return this;
47: }
48:
49: public Person4 finish()
50: {
51: return _person;
52: }
53: }
54: }
Now to create Roger and his friends I do..
1: var roger4 = Person4.createAPerson()
2: .named("Roger")
3: .withaFriendNamed("Eddie")
4: .withaFriendNamed("Freddie")
5: .withaFriendNamed("Gordie")
6: .finish();
It’s a simple example but maybe it sparked some ideas on how to use fluent interfaces to chain methods and make your code more approachable to people without Computer Science degrees.
JB
Collective Intelligence with F#
by riles on Apr.01, 2009, under Resources
I’m quite interested in Matthew Podwysocki’s application of F# (and functional programming) to collective intelligence. Have any of you worked in the collective intelligence space? If so, with what languages, and what was your experience?
Jaime Rodriguez on MIX 09 Silverlight News
by riles on Apr.01, 2009, under News
I enjoyed reading Jaime Rodriguez’s thoughts on the Silverlight news from MIX 09. Very good info; however, I still think that most WPF apps will begin moving to Silverlight unless those additional features are needed. In most layered architectures, workflows, et. al. are created and used in the service layer, not the presentation layer. Silverlight as Moonlight is also the only option for Mono compiled apps, and I don’t believe the Mono Project plans on adding WPF in full. So for complete cross-platform re-use, you’ll need to stick to Silverlight.
Enterprise Library 5
by riles on Mar.31, 2009, under News
Curious about the next version of Enterprise Library? Why not vote on what you want to see? Grigori Melnik has posted the link to a poll where you can help Microsoft prioritize the features you want in Enterprise Library 5. Vote today!