October 2007 - Posts

Answers to WF Interview Questions

Due to popular demand, here are some answers to the questions.

Well, not answers exactly ... just some pointers to the get you in the right direction...

1. Are there advantages to building workflows using only XAML? Are there disadvantages?

See Keith Elder's blog on "Leveraging Workflow Foundation", particularly the section on storing workflow definitions in the database.

Also, see Matt Miler's Templates for Windows Workflow XAML activation projects

2. What are the pros and cons of using an ExternalDataExchange service versus going directly to the WorkflowQueuingService?

Sam Gentile: Windows Workflow 102
3. When are attached dependency properties useful in WF programming?

See: Dependency Property Notes
4. What behavior does the default scheduling service provide?

Hosting Windows Workflow
5. How can my code participate in a database transaction with a workflow instance?

Advanced Workflow: Workflows and Transactions
6. Why would I use a tracking service?

Follow the links in Tomas Restporo's WF Tracking Services Explained.

7. Describe a scenario where the WF runtime will cancel an executing activity.

I'd be looking to hear, for example, what happens inside a Listen activity. Also, see Matt W's Implementing the M of N Pattern in WF

8. Describe a scenario where I'd need to spawn a new ActivityExecutionContext.

Matt Milner: ActivityExecutionContext in WF.

9. Tell me why I'd use a compensation handler.

Guy Burstein explains the essence: Compensating and Fault Handling.

10. Tell me about the following activities: Replicator, Parallel, and Policy.

Advanced Workflow: Replicator Tips and Tricks

Kirk Allen Evans: Understanding ParallelActivity in WF

Sahil: Composite Activities in WF.

WF: Rules and Conditions

posted by scott with 4 Comments

Windows Workflow Interview Questions

A few people have asked me what "hard core" WF questions to ask a job candidate.

For advanced topics, I like open-ended questions. Not all these questions have a right or wrong answer- but they should give you an idea of the candidates WF experience, and how they'd design and implement software with WF.

  1. Are there advantages to building workflows using only XAML? Are there disadvantages?
  2. What are the pros and cons of using an ExternalDataExchange service versus going directly to the WorkflowQueuingService?
  3. When are attached dependency properties useful in WF programming?
  4. What behavior does the default scheduling service provide?
  5. How can my code participate in a database transaction with a workflow instance?
  6. Why would I use a tracking service?
  7. Describe a scenario where the WF runtime will cancel an executing activity.
  8. Describe a scenario where I'd need to spawn an ActivityExecutionContext.
  9. Tell me why I'd use a compensation handler.
  10. Tell me about the following activities: Replicator, Parallel, and Policy.
A candidate who can run the table on these 10 questions knows their WF stuff.
posted by scott with 8 Comments

My RDP Problem Appears to be the Windows Vista Firewall

My desktop computer continued to deteriorate this weekend. Not only could I not maintain an RDP connection into the desktop, I also started having problems synching my phone, copying files across the network, and general performance problems.

On a hunch, I disabled Windows Firewall and all these problems disappeared. Since I am behind a hardware firewall, I'm not concerned about the security implications.

Not sure why this happened – but the firewall rules on this machine numbered over 400 in the private profile (Start -> Search for firewall advanced). Other machines I've checked have ~200 rules.

Perhaps the software firewall was overloaded...

posted by scott with 1 Comments

The New ASP.NET Framework

The New ASP.NET Framework

ScottGu gave a demo of the new MVC framework for ASP.NET at the ALT.NET Conference. Here are some notes and thoughts I had after watching ScottHanselman's recording.

The framework should go live in the spring of 2008. The framework is not a replacement for ASP.NET WebForms, but provides an alternative paradigm for building web applications. The new framework still works inside of the ASP.NET runtime - meaning all of the wonderful infrastructure pieces like the configuration system, provider model, SQL cache invalidation, health monitoring, and master pages continue to exist. Like the ASP.NET AJAX extensions – it sounds like we'll only need a new assembly to start the party.

Being an "MVC framework", the software features the Model View Controller pattern. MVC and its many permutations have been (and continue to be) principal patterns in many application frameworks and development environments. There were several mentions of Rails (both the Mono and Ruby types), and at least one reference to Django (the Django book is a good read to get into the framework's mindset).

The framework will provide:

  1. Mechanisms to enforce a clean separation of concerns
  2. An API designed for testability
  3. A pluggable and extensible technology stack

Separation of Concerns

ASP.NET WebForms map an incoming URL to a single .aspx file. Although one can use an HttpModule or VirtualPathProvider to change this behavior, the majority of ASP.NET web applications use this default behavior. In practice, this approach tends to produce code-behind files with intermingled presentation, data access, and business logic. This approach also tightly couples URLs to the physical arrangement of .aspx files in the file system.

The new MVC framework offers a loose coupling between incoming URLs and the view that will ultimately render HTML. ScottGu describes a flexible and pluggable URL dispatching engine that can handle clean and procedural URLs like:

http://OdeToCode.com/articles/show/450

or

http://www.pluralsight.com/classes/register/appliedsilverlight

The URL dispatching engine examines incoming URLs, routes each request to an instance of a controller class, and invokes a method on the controller (the action).

Controllers

Controllers in the new framework support test first and controller first development styles. In other words, you can implement a controller sans any views, and fully test the controller's ability to utilize application logic and services to respond to a request.

The framework provides a low-level interface definition you can implement to claim absolute power over controller policy, but also provides a hierarchy of concrete controller classes to build upon.

When the controller is ready, it can call RenderView(string viewName, object viewData) to generate the appropriate user interface response. Thanks to generics, this boundary can also be strongly typed.

Views

Views render HTML, but views are not web forms - there is no page lifecycle, postbacks, or viewstate in this framework.

In general, views are simple templates. Templates are concerned only with presentation. To enforce a separation of concerns, many template engines do not allow a template to change the value of a variable or call into application logic, but the ASP.NET framework will allow code blocks and data-binding. The view never references a controller, and the controller never references a view - so testability and a separation of concerns prevail.

Designed For Testability

One of the current difficulties in writing unit tests for code running inside an ASP.NET environment is the pervasiveness of sealed classes like HttpContext.The MVC framework features an interface based API with IHttpContext, IResponse, IRequest, etc.

There is a mock view engine and, I believe, mock implementations of IHttpContext and the like to make testing easier.

At the beginning of the discussion Scott mentioned that the framework will include inversion of control containers, although I don't recall this feature appearing in the presentation.

A Pluggable Architecture

It sounds as if every major service in the MVC framework is pluggable – the view engine (throw in Brail), the dependency injection framework (throw in Structure Map), the URL dispatcher, the controllers, and more.

Look For the CTP Soon

The new framework appears to marry mature paradigms from outside the world of ASP.NET with the high performance and robust infrastructure of the ASP.NET runtime. Look for a CTP by the end of the year.

posted by scott with 2 Comments

Strange Remote Desktop Problems

Before I start my tale of woe, I just want to point out that I've tried disabling the autotuning feature on Vista machines, but this doesn't fix the problem.

I have a relatively clean desktop machine. The desktop is a host for several virtual PCs, and runs Vista.

Remote desktop connections to the virtual PCs hosted on this desktop are solid, and the connections never drop. The virtual PCs run XP and 2003 Server.

But ... remote desktop connections to the desktop itself stall every 5 minutes. Sometimes the RDP connection drops entirely - other times it's just a matter of waiting 10-20 seconds for the connection to reconnect.

Each time this happens I lose a little more hair.

Even stranger - while a connection to the desktop is stalled, a connection to a virtual PC hosted on the desktop is still working great. I can even ping the host machine and see a 2ms response time.

This behavior leads me to believe that:

  1. There is nothing wrong with the RDP client
  2. There is nothing wrong in the networking stack or hardware of the desktop.
  3. There is something wrong with the terminal services service on Vista.

I'm hoping SP1 will fix the issue, and do so before I go bald.

Anyone else see similar behavior?

posted by scott with 14 Comments

Overflow Exceptions

WWWTC #18 highlights the fact that integer overflow detection is ON by default for Visual Basic projects. To change the behavior, you need to go to into the project properties -> Compile -> Advanced Compile Options and click the "Remove Integer Overflow Checks".

In C# projects, overflow detection is OFF by default. To change the behavior, you need to go into the project properties -> Build -> Advanced and select the "Check for arithmetic overflow/underflow" check box.

Changing the C# project settings is one solution to making the unit test in WWWTC #18 pass.

There is another option, too. Use the checked keyword in C#, as Johnathan, Jason, Ronin, and Dave pointed out.

public int AddQuantity(int additionalQuantity)
{
    
// .. some logic

    return checked(_quantity += additionalQuantity);
}

Or …

public int AddQuantity(int additionalQuantity)
{
    
// .. some logic

    checked
    {
        
return _quantity += additionalQuantity;
    }
}

There are a number of other subtleties to overflow detection – try some experiments with floating point and decimal data types to see what I mean, or jump to this article on the The Code Project: Arithmetic Overflow Checking using checked / unchecked.

posted by scott with 2 Comments

October Is Scary Schema Month

Ayende kicked the month off with "Schema to wince by…", then "CRM Horror".

Great timing, Ayende! With Halloween right around the corner, let's make October scary schema month!

Here is one that recently made my hair stand on end:

ALTER TABLE [dbo].[EmergencyPatientAssesments]
   
ADD CONSTRAINT [mspk550470] PRIMARY KEY CLUSTERED
(
   
[BaseID] ASC,
   
[PatientVisitID] ASC,
   
[TreatmentID] ASC,
   
[DateTime] ASC,
   
[ActualDateTime] ASC,
   
[AssessmentSequenceID] ASC,
   
[QuestionID] ASC
) ON [PRIMARY]

This healthcare schema defines a composite primary key using 5 varchar fields and 2 datetime fields. If you think the index is scary, you should see the joins…

Do you have a scary schema to share?

posted by scott with 5 Comments

What's Wrong With This Code (#18)

Here is another golden oldie:

Numeric overflows are a type of software bug that occur when a calculation produces a result that doesn't fit in the intended storage location. One of the most famous cases of an overflow bug is the overflow bug that destroyed an Ariane 5 rocket in 1996*.

Fortunately, .NET has a dedicated exception to highlight overflow problems. Just run the following VB code and watch the OverflowException appear.

Dim i As Integer
i += Integer.MaxValue
i +=
Integer.MaxValue

So, given this class:

public class LineItem
{
    
private int _quantity;
    
public int Quantity
    {
        
get { return _quantity; }
    }

    
public int AddQuantity(int additionalQuantity)
    {
        
// some logic ...
        return _quantity += additionalQuantity;
    }

    
// other stuff...
}

Why does the following unit test fail?

[TestFixture]
public class LineItemTest
{
    [
Test]
    [
ExpectedException(typeof(OverflowException))]
    
public void TestForOverflow()
    {
        
LineItem lineItem = new LineItem();
        lineItem.AddQuantity(
Int32.MaxValue);
        lineItem.AddQuantity(
Int32.MaxValue);
    }
}

What options are available to fix the problem?

* The article Design By Contract: The Lessons Of Ariane says the real error was a "reuse specification error". Quote: "To attempt to reuse software without Eiffel-like assertions is to invite failures of potentially disastrous consequences".

posted by scott with 15 Comments

A 30-Second Introduction to IPv6

IPv4 is hanging around for the near future, but I took a few minutes to find out what all the IPv6 hexadecimal gobbledygook is about when I type ipconfig in Vista.

Tunnel adapter Local Area Connection* 16:
Connection-specific DNS Suffix . :
IPv6 Address. . . . . . . . . . . : 2001:0:4136:e390:3094:8f8:e755:e2d
Link-local IPv6 Address . . . . . : fe80::3094:8f8:e755:e2d%33
Default Gateway . . . . . . . . . : ::

There are a few limitations in IPv4, the most notable being a 32-bit address space. The free pool of IPv4 addresses is nearly empty. IPv6 addresses are 128 bits wide (the same size as a GUID), and provide a mind-numbingly huge address space. TCPGuide.com says:

If we had been assigning IPv6 addresses at a rate of 1 billion per second since the earth was formed, we would have by now used up less than one trillionth of the address space.

Wikipedia explains the :: notation seen in the output above:

IPv6 addresses are normally written as eight groups of four hexadecimal digits. For example, 2001:0db8:85a3:08d3:1319:8a2e:0370:7334 is a valid IPv6 address. If one or more four-digit group(s) is 0000, the zeros may be omitted and replaced with two colons(::). For example, 2001:0db8:0000:0000:0000:0000:1428:57ab can be shortened to 2001:0db8::1428:57ab.

And Microsoft's IPv6 FAQ explains the % symbol:

Link-local addresses are reused on each link. ... Because of this address reuse capability, link-local and site-local addresses are ambiguous. To specify which link on which the destination is located or within which site the destination is located, an additional identifier is needed. This additional identifier is a zone identifier (ID), also known as a scope ID ... The syntax specified in RFC 4007 for identifying the zone associated with a link-local or site-local address is Address%zone_ID.

Now I know what the output means, but I don't know if I'll ever be able to remember a v6 address like I can remember v4 address. At least the loopback address (::1 in v6) will be less typing than its v4 counterpart (127.0.0.1).

posted by scott with 3 Comments

Joe Albahari's LINQPad and LINQPad Challenge

JoeA's LINQPad is an indispensible tool for LINQ development.

Write a query expression and view the results, the generated SQL, and the extension method / lambda equivalent. Works for both C# and VB!

Joe also dares developers to take the LINQPAd challenge:

  1. Locate the shortcut for SQL Management Studio on your Start Menu and move it some place else.
  2. In its place, insert a shortcut to LINQPad.
  3. For the next week, perform all your ad-hoc SQL queries using only LINQPad.

Teachers say language immersion is highly effective when learning a new language. I'm sure the LINQPad challenge is a worthwhile endeavor to learn the subtleties of LINQ.

posted by scott with 3 Comments

Killing Software Projects with Modal Verbs

Modal verbs are the words that express a degree of certainty, like: may, can, will, shall, must. You see them in RFCs all the time:

1. MUST This word, or the terms "REQUIRED" or "SHALL", mean that the definition is an absolute requirement of the specification.

In the old days, software analysts would descend from mountain peaks with reams and reams of software requirements arranged in three-ringed binders. These requirements also came with words like "must" and "may". After a couple months, developers would repurpose the binders as doorstops and monitor risers. 

The days of thick binders are over, thank goodness, and the days of more frequent face-to-face communications are here. The communication has to be obvious and lucid in order to work, however. Analysts were good at using the "proper" language to shape results. The same decisiveness has to come across in today's whiteboard and water cooler discussions.

What the tech lead says: You may want to possibly refactor that class.

What the junior developer hears: The code is gold!

I've been in conversations where the words "may", "maybe", "perhaps", and "might" dominate the discussion. These discussions are never productive, and make a leader or expert appear indecisive and unconfident.

From Hacknot:

A Technical Lead lacking in self-confidence can be a major frustration to their team. They may find themselves waiting on the Lead to make decisions that significantly effect their work, but find that there is some reticence or unwillingness to make a firm decision. Particularly when new in the role, some Technical Leads find it difficult to make decisions in a timely manner, for they are paralyzed by the fear of making that decision incorrectly. Troubled that a bad decision will make them look foolish, they vacillate endlessly between the alternatives, while their team mates are standing by wondering when they are going to be able to move forward.

You could substitute "domain expert", "product manager", or "stakeholder" for "technical lead" and the paragraph still makes sense. Many times the problem isn't timely decision making but ineffective communication. Maybe that's just the individual's personality. Perhaps they are just being politically correct or may be timid.

What the stakeholder says: The last change we might want to possibly make is to change this screen to maybe make the buttons stand out a little more.

What the developers hear: We are done! Ship party!

It's perfectly fine to be an expert and say "I don't know", or "this requires some research", but when possible you need to paint the world in shades of black and white to keep a team moving towards the goal.

You must make decisions.

You must clearly communicate those decisions.

posted by scott with 4 Comments