OdeToCode IC Logo

Windows Workflow as a Rule Engine

Monday, August 14, 2006 by scott

One interesting facet to Windows Workflow is how I can combine procedural knowledge with declarative knowledge. Procedural knowledge is the "how-to" knowledge of performing a task. If a bank requires me to make three web service calls to process a payment, I can arrange those three calls inside a Sequence activity and model the exact ordering of calls required by the bank.

WF also provides a Policy activity to process declarative knowledge. Declarative knowledge is the knowledge of facts and relationships between data. Instead of "how-to" knowledge, declarative knowledge provides the "what-is" knowledge. For example, if I want to expedite a payment, the bank will charge me an extra 3%. "All bankers are thieves" would be another piece of declarative knowledge.

Rules engines are pieces of software specialized for processing declarative knowledge. There are a few .NET rules engines around. The most recent entry, as I found out from Larry Obrien's blog, is Drools.NET. BizTalk Server also provides a rules engine, and Charles Young has a good overview of Biztalk rule processing versus Windows Workflow rule processing.

There are some great "rules-centric" Windows Workflow samples on netfx3.com. Samples include a rules driven user interface, rules in Microsoft Excel, how to use an external ruleset (think of rules stored in a database), and more.

Treat Warnings as Errors in ASP.NET 2.0

Friday, August 11, 2006 by scott

The web.config file controls all compilation settings in a default web site project. To treat compiler warnings as errors, you'll need the following in web.config:

<system.codedom>
  <
compilers>
    <
compiler            
      
language="c#;cs;csharp" extension=".cs"
      
compilerOptions="/warnaserror"
       type="Microsoft.CSharp.CSharpCodeProvider,
             System, Version=2.0.0.0, Culture=neutral,
             PublicKeyToken=b77a5c561934e089
" />
  </
compilers>
</
system.codedom>

Note: You can only twiddle with compiler settings under full trust, but then you'll only need this setting at build time.

7 Virtues for Software Developers

Thursday, August 10, 2006 by scott
The Perfect Programmer

Diligence - Diligent developers take ownership of their work without being possessive. Diligent programmers fix broken windows.

Humility - Humble developers take pride in their code, but don’t snub constructive criticism. Humble developers know they can always improve themselves.

Patience - Patient developers remain calm during times of stress, and don't surrender to the temptations of a quick fix. Patient developers have the endurance to carry a product across the finish line.

Liberality - Broad-minded developers base their decisions on proofs and particulars instead of preconceptions and prejudices. Broad-minded developers listen to the other side and attempt understanding.

Creativeness - Creative developers find a way around the brick wall in front of them, and do so without creating a mess. Creative developers find the elegant solution to a difficult problem.

Adaptability - Adaptable developers have the ability and willingness to learn new skills and accept new responsibilities. Adaptable developers continue to grow.

Resilience - Resilient developers bounce back from boneheaded bugs and bursting dotcom bubbles to code again another day. Resilient developers appreciate failure as the upward slope of the learning curve.

Eric Gunnerson's "Seven Deadly Sins of Programming" (and others) inspired this post.

I still have to work on 6 or 7 of these.

Dear Candidate

Wednesday, August 9, 2006 by scott

Every so often, I get an email that looks like:

Dear Candidate,

While conducting a search for our client we came across your resume and it appears to be a good match for this opportunity. Blah blah fast-paced blah blah great benefits blah blah and so on.

Using the word "candidate" is not only presupposing, but a sign of laziness. Even the male enhancement spammers can personalize their messages. I'm sure the recruiter will have his pick of top talent with emails like this.

I think I'll reply with the following.

Dear [Recruiter Name],

Thank you for getting in touch about the [Position Name] offer with [Company Name]. Unfortunately, I'm busy on a project that will generate automated responses to mass mail job offers. I'm still working out a few bugs.

Sincerely,

[My Name]

What's Wrong With this Code? (#2)

Tuesday, August 8, 2006 by scott

A developer wanted to keep track of some birthdays with the following table design and data.

CREATE TABLE [Birthdays]
(
  [Name]
varchar(50),
  [BirthDate]
datetime   
)

INSERT INTO [Birthdays] VALUES('Gene Wilder',  '6/11/1935')
INSERT INTO [Birthdays] VALUES('Nicola Tesla', '7/9/1856')
INSERT INTO [Birthdays] VALUES('Miles Davis',  '5/26/1926')

To sort the data by name and by date, the developer wrote a single stored procedure to handle both cases.

CREATE PROC GetBirthdays
  @Ordering
int
AS
BEGIN
  SELECT [Name], [BirthDate] FROM [Birthdays]
  
ORDER BY
    CASE @Ordering
      
WHEN 1 THEN [Birthdate]
      
WHEN 2 THEN [Name]
    
END
END

The developer tested the proc by passing a value of 1, and was pleased to see a resultset ordered by birth date.

What can go wrong? (Hint: Try passing a 2).

How could the developer fix the problem by changing only 1 line?

Windows Workflow Hosting

Monday, August 7, 2006 by scott

Hosting Windows Workflow is a new article covering the WorkflowRuntime class and the WF services. The article shows how to configure and use the scheduling, persistence, and tracking services provided by Windows Workflow.

Feedback is appreciated.

ASP.NET Best Practice Analyzer

Friday, August 4, 2006 by scott

The alpha release of the ASP.NET Best Practice Analyzer was about 5 weeks ago. Similar to the popular SQL Server BPA, the ASP.NET BPA evaluates a set of best practice rules and tells you about configuration problems in your applications. The tool checks both machine level and application level config files. Currently, the tool only has a handful of rules. It will raise red flags if the application runs in full trust, or if debug / trace flags are enabled, and a few others.

Ironically, the tool suggest AutoEventWireup="false", which isn't the default for C# web forms in VS2005.

I can't think of too many hard and fast rules for web.config settings, but here are a few: more that could be useful:

  • No plaintext passwords in the <identity> section.
  • Make sure the <httpHandlers> section maps appropriate extensions to the HttpForbiddenHandler.
  • Make sure the <pages> section has smartNavigation disabled and validateRequest enabled.
  • No enabled trace sources inside <system.diagnostics>.