Survey. Which frameworks do you use in .Net projects?

Later this week I will be doing a talk at the Microsoft DevDays conference at the Congrescentrum in Den Haag. This talk is titled Navigating through the hypes, Software architectures and patterns to help avoiding your projects to crash. Read more about it at www.devdays.nl.

Please fill in the little survey I’m conducting at
Survey: Which frameworks do you use in .Net projects?

Benefits and pitfalls of using frameworks

In short, during this talk I will address both the benefits and pitfalls of applying frameworks to your projects. Be it Microsoft frameworks, open source frameworks or even self developed frameworks, there’s always a catch.

image

What if you require additional features that aren’t implemented in the framework? What if you decide that another framework would have been better and want to switch halfway your project? What if the author of your favorite open source framework suddenly stops developing? What if the framework contains bugs or omissions? And what if a new version of the framework is released that is implemented totally different? These and many more everyday problems will cause your project to come to a halt, or at least make you perform serious refactoring.

So, I will address some pragmatic software architectures and patterns that will help your projects to stay away from framework problems, and how to make your code less dependent of framework choices.

Which frameworks do you use?

This brings me to my question to you. I’m curious to which frameworks you use – Microsoft, open source and / or own developed, and what your experiences are with these frameworks. Where they helpful, challenging or just plain crap?

Please fill in the little survey I’m conducting at
Survey: Which frameworks do you use in .Net projects?

Agile and Scrum anti-patterns. Wildcard proposal DevDays 2009

After a dozen years of promoting and evangelizing agile software development in the current years of economic unpredictability a breakthrough in applying agile processes and techniques is emerging. But with the rising popularity of Scrum, MSF Agile, OpenUP, Smart, XP, Lean, FDD and the likes, it’s not only success stories any more. Similar to failing traditional waterfall projects there patterns of failure emerging from agile projects too.

IMAGE_459

During this highly entertaining and educational talk speaker Sander Hoogendoorn will guide his audience through the best practices of agile, but moreover will present you with a large number of misconceptions and pitfalls that have surrounded agile projects, in the hope that you will be able to avoid failure, to avoid your manager saying: “This Scrum thing is not for us, it’s too unpredictable. We’ll just go back to how we worked before.” Patterns such as Scrumdamentalist, Trojan Rigidity, Bob-the-Builder (revisited), Process People, Sit-Down Meetings, and Huddle will pass, illustrated with many real life examples, and visualized in clear pictures.

Vote!

One thing I forgot to mention earlier, you may vote for this talk to appear on the program for Microsoft’s DevDays 2009 conference.

Check: Vote for this talk on DevDays 2009.

Navigating through the hypes, Software architectures and patterns to help avoiding your projects to crash – this year’s DevDays talk.

Good to hear that I’ve made the program of this year’s Microsoft DevDays. Will be a challenging talk on software architecture and patterns, titled just like this blog post. Here’s the description. Hope you like it.

Navigating through the hypes, Software architectures and patterns to help avoiding your projects to crash

When it comes to .Net software development, more and more frameworks enter the market. Both from Microsoft and in open source. Just think of all the very useful frameworks, such as ASP.NET MVC, Castle, WF, Entity Framework, Unity, Linq2SQL, ADO.NET Data Services, WCF, nHibernate, Spring.NET, CSLA, NUnit, Enterprise Library or ADF.

Once a project chooses to apply one or more frameworks, trouble begins. What if you require additional features that aren’t implemented in the framework? What if you decide that another framework would have been better and want to switch halfway your project? What if the author of your favorite open source framework suddenly stops developing? What if the framework contains bugs or omissions? And what if a new version of the framework is released that is implemented totally different? These and many more everyday problems will cause your project to come to a halt, or at least make you perform serious refactoring.

During this highly interactive talk Sander Hoogendoorn, principal technology officer at Capgemini, chief architect of Capgemini’s agile Accelerated Delivery Platform, and member of Microsoft’s Visual Studio Advisory Board, will demonstrate pragmatic software architectures and patterns that will help your projects to stay away from framework problems, and how to keep your code independent of framework choices. In his well known slightly ironic style Sander will present different models of layered architectures, and explain and use bridge patterns, managers, dependency injection, descriptors, and layer super-types.

Of course, the speaker will illustrate these insightful patterns with lots of demo’s and (bad) code examples using blocks from Microsoft’s Enterprise Library, nHibernate, Log4Net, and the Entity Framework. Delegates will benefit from this talk by learning how to improve the structure and quality of their software architecture and code, and how to avoid the pitfalls of applying frameworks to .Net software development.

Client/service architecture. Domain driven development in the distributed era. Episode IV

Go to episode three.
Go to episode two.
Go to episode one.

In case you’re wondering why doesn’t this dude come to his point, you’ve probably missed it. I’ve made it already. The point is: you should always have a single point of truth, and at most have it reproduced on the server side. Which in most cases you don’t control anyway. Centralize your domain or business logic in the domain or business layer. Do not go directly from your front end to the server, but always use the domain layer as an intermediate. The longer I’m in this business, the more I am convinced of this simple, but golden rule.

Client / service architecture

Now you’re probably wondering why I am still blabbering on about this client / server technology. Client / server is dead and long gone isn’t it? Well, it should have been. But it isn’t. A lot of water went under the bridge since 1996, but this two-layered architecture is hard to wash out – in a sense it’s a bit like waterfall or Cobol. It’s still here in our everyday projects, on a day-to-day basis. Even though we are now building applications in service oriented architectures, and have build in a component based model before that, and perhaps in the near future are even building in a cloud model. Let’s call this client/service architecture.

Much to my liking, I get to do a lot of code audits, mostly on .NET applications. Code in these newer styled projects, such as web, service oriented, or even cloud is not that different from our old client/server code. Or if you just witness presentations at conferences on new technologies, or on emerging frameworks, such as ASP.NET MVC or ADO.NET Data Services. Or scroll around the average code example on web sites and blogs. Nothing changes. Developers are still binding their DataSet to their DataGrid. Please check out the following code.

private void ManageCustomer_Load(object sender, System.EventArgs e)
{
   string connString = "server=(local)\\SQLEXPRESS;database=MyDatabase;Integrated Security=SSPI";
   string sql = @"select * from customers";

   SqlConnection conn = new SqlConnection(connString);
   SqlDataAdapter da = new SqlDataAdapter(sql, conn);

   DataSet ds = new DataSet();

   da.Fill(ds, "customers");

   grdCustomers.SetDataBinding(ds, "customers");
}

The Hello World excuse

I just picked this code example from an arbitrary web site. It comes from an ASP.NET web page. There’s two options: either this is a Hello World style demo, or it represents the architectural style of the whole application. In the first option, the developer is forgiven. The developer in question will use Hello World as an excuse not to practice good architecture. There’s probably very little time during his demo to explain about good architecture – although I think you should always explain about good architecture, as many developers will just follow the code examples offered and build them into their real-life applications. “But hey, I only wanted to demonstrate this new piece of technology.” Sorry, that’s no excuse.

Hence, the second option: this code example could actually represent the architectural style for a real-life application. In which case you’re screwed. Having a connection string and a SQL statement set up – in strings – on every web page is probably not what you should do. Even though these mistakes will already kill you in maintenance mode, this is not what I wanted to express. Things get worse: this code does not have room for business logic. A DataSet with customers in it is retrieved from the database, and a grid view called grdCustomers is filled with this data. What if I want to run some business logic on my customers? Where do I put it?

The service oriented Hello World excuse

Let’s move on. You might consider that the previous code example is from the old world as it is still centered around the database. Even though it is quite recent code. Let’s consider a real new age code example.

private void GetAccountsData()
 {
     CrmAuthenticationToken token = new CrmAuthenticationToken();
     token.OrganizationName = "MicrosoftCRM";
     token.AuthenticationType = 0;

     CrmService service = new CrmService();
     service.CrmAuthenticationTokenValue = token;
     service.Credentials = System.Net.CredentialCache.DefaultCredentials;
     string result;
     string fetchXml = @"<fetch mapping='logical'>
         <entity    name = 'account'>
         <attribute name = 'name'/>
         <attribute name = 'telephone1'/>
         <attribute name = 'address1_city'/>
         <attribute name = 'address1_country'/>
         <attribute name = 'websiteurl'/>
         <order attribute = 'name' descending='false' />
         </entity></fetch>";

     result = service.Fetch(fetchXml);

     _crmData.ReadXml(new StringReader(result));
 }

This particular code example comes from a SharePoint WebPart. This web part is used to represent a list of accounts and select an account from this list. These account are retrieved not from a database, but from a service in Microsoft CRM. The accounts retrieved are stored in an instance variable called _crmData. Unfortunately, this variable is not a collection of Account objects, but rather is defined as a DataSet.

DataSet  _crmData       = new DataSet();

And to complete this service oriented example, the instance variable _crmData is then used to render the web part by binding the GridView to the first table in the DataSet.

protected override void OnPreRender(EventArgs e)
 {
     grdCrmAccounts.DataSource = _crmData.Tables[1];
     grdCrmAccounts.DataBind();

     lblHeader.Text = "Accounts from Microsoft CRM";
     lblHeader.ID = "header";
     base.OnPreRender(e);
 }

All in all, again this is a typical Hello World demo scenario that was presented to illustrate the combination of SharePoint and Microsoft CRM. But again, this kind of code will also appear in real-life applications without any doubt. It’s easy to see what’s missing here. There is no location to put our possible business logic.

In a service oriented scenario this means  we totally rely on the definition and signature of the objects from the server, in this particular example on the definition of the Account object in Microsoft CRM. Although relying on services sound reliable, it is in fact no more reliable then to trust on the definition of a table called Accounts in an underlying database. Hence the phrase client/service architecture.

Single point of truth. Domain driven development in the distributed era. Episode III

Go to episode two
Go to episode one

Client / server could have been a much more successful era in software development, if it wasn’t for this copy-and-paste programming, leading to applications that slowly became unmanageable. I have seen this anti-pattern occur in any of the popular client / server technologies. Without exception, whether it was Visual Basic, PowerBuilder or SQL:Windows and even the older web technologies, such as ASP and even early Java applications.

Splashed business logic

We still bare the fruit from the client / server era. Many of the projects we currently undertake are application migration projects, or re-engineering projects. Although tools exist that claim to do fully automated migration of client / server apps, I find that hard to believe. Having done many code reviews on these poorly constructed applications, these all seem to have one thing in common: the business logic is splashed all over the place, and hardly ever consistent.

Single point of truth

And the nasty thing is: we could have prevented most of this problem, if we would have known then what is now much more common, although less widespread as it should be. But I’ll come back to this in later episodes.

We should have introduced a single point of truth in our client / server applications. We should have constructed a domain layer – or business layer – that contains our business rules and validations, as in the figure below. Separating concerns is a popular catch phrase. In this case separating the presentation logic of the user interface from the domain logic in the domain layer.

image

Now we only have one location of our simple business rule. For now, I’ll leave it in the middle where in the domain the business rule sits. There are a few options. If the customer changes his mind in this situation not much harm is done. We simply modify the one business rule in the domain layer and we’re back on the road. All presentation logic simply refers to this location, so we’re good.

For as long as they both shall live

Of course, this refactoring comes with a couple of consequences. For starters, you could reason about the fact whether a copy of the business logic should also be present in the database underneath. There are a couple of thoughts to consider here:

  • How and by whom is the is the database approach. If our application is the only party to talk to the database, and if this situation remains in tact, you’re quite safe, and you could consider not implementing the rules in the database.
  • If you’re not sure who else approaches the database, you will need to implement the rules at least in the database too, otherwise there is no way of guaranteeing continuity and consistency.
  • If you decide to have the business rules implemented double, make absolutely sure that the two versions of the truth are in sync, and will remain in sync for as long as they both shall live.

This taking into consideration, applications and database should have been much easier to extend and to maintain. Of course, back in the nineties of the previous  century, more and more people started to realize this. That’s when multi-layered architectures became in fashion, which they still are.

The merits of two-tier architecture. Domain driven development in the distributed era. Episode II

Go to episode one.

So now you’re stuck with this two-tier architecture. Is this a problem. Well, not yet. However, it can become a huge problem, and it has become a huge problem in many, many client / server applications, in a vide variety of technologies, including several types of (legacy) web application technologies.

The truth is out there

The problem with this architecture again is fairly simple. There is no single point of truth. Business logic is scattered. Consider this simple piece of business logic below.

if (StartDate < EndDate)
{
   ...
}

This code is now in the database, to keep the database from getting harmed. But it is also copied into one of the forms in the application, preferably on an event that is fired when the user tabs out of the field StartDate from, let’s say a Contract.

Eventually, there will be someone on the team of developers who is going to build another form that involves manipulating a Contract. It could be yourself, or any of the other well-educated developers, but there’s always someone how will copy-and-paste the business logic from the other form to the new one. And from that time on the truth is out there. Somewhere. After a while, you will end up with an application that looks like this.

image

And you might not even see that, because it happens over time. For instance, much of this copy-and-paste activity will take place after the application is deployed and it enters maintenance mode. Especially when the boys and girls doing the maintenance were not on the team that built the software.

Customers changing their minds

Still, this doesn’t have to be bad. It will become bad when something peculiar happens: the customer changes his mind on the business rule. Now, I know, that never happens on your projects, but on mine it did and it does. On average, requirements will change about 20% to 25% during the project. And there you go. Let’s say the customer just thought of the fact that the previous rule must be altered. Just a very small change, isn’t

if (StartDate <= EndDate)
{
...
}

So the boys and girls in the development or maintenance team start looking for the locations this business rule applies to. Of course, there is hardly any documentation, so they start searching the code. And you know what, they will find occurrences of the business rule and fix them. But, that’s Murphy for you, they will likely not find all the occurrences. The applications will now look like this.

image

And that’s where client / server fails. Miserably.

Back in the days of client/server. Domain driven development in the distributed era. Episode I

At this point in time, where we slowly shift from service orientation to cloud computing, building business software is more complicated then it has ever been. There are many platform that your software needs to target, and there are even more ways of writing the software.

Beyond choosing technology

Choosing a technology goes way beyond stating that you are doing Java, .Net or Adobe, and can be quite complicated. A vast amount of architectures, patterns, frameworks – open source and vendor specific – is available to make life easier, but choosing more complex. With this paper – in episodes – I will try to make a point for building software around its domain, also in applications that consume services in a distributed environment. Especially in such a service oriented environment, since there is a wide variety of sources your domain can be fed from, including database, ERP, web services and the cloud – where ever that leads us to. In the sequential episodes of this paper, I aim at presenting a collection of patterns that will help you leverage your domain driven design independent of the back ends this domain needs to interact with.

Back in the good old days

But first things first. Back in the old days of client/server life was fairly simple. You could find the a way to get the data you needed from the database, usually using ODBC, and splash that data to a form, usually a Windows form. You could build applications in a jiffy. Didn’t we all love PowerBuilder, SQL:Windows and Visual Basic?

Then life got a little more complicated at the time the customer wanted some validation in the application. Let’s say hew wanted to make sure that the end date of a contract was either blank or later in time than the starting date. Here’s where the discussion started. The developers that previously worked with Clipper or DBase would insist to put this validation in the database. And they did. Nice and safe. The younger developers, including me, however would mention that if validation was delayed until the data reached the database, it was fairly late. Couldn’t we just build the validation into the form? Well, yes we could. And we did. So we ended up with a simple architecture, as shown below.

Client / server softwar architecture

The nasty thing about this architecture is that both arguments hold. Yes, validations in the database is fairly safe. And yes, validating until the data is in the database is fairly late. So now we keep two versions of our little validation rule. One in the database, and one in our form. It’s the same rule. For now.