Workflow 4 and Visual Basic expressions

When using Windows Workflow Foundation 4 you often need to enter expression in some activity property. The new thing is these expressions are all in the Visual Basic dialect regardless of what language you project is in. So when developing a project in C# the expressions are sill in Visual Basic.

Weird right?

Well not really when you think about it!

After all power business users are expected to be able to modify workflows. And guess what their favorite tools are. That would be Microsoft Excel and Word. And what do they use to create macros? Right Visual Basic for Applications is their language of choice.

So if they use VBA letting them enter VB into expression dialogs is a far more natural fit than having them use C#.

A case for the Delay activity

So lets take a look at the delay activity. This activity takes 1 input property Duration of type Time Span. So I guess that means our VBA power users are going to have to enter something like if they want to wait 5 seconds:

Now for some reason I suspect that is not the first thing they are going to type. In fact they are more likely to time something like “0:0:05” instead. Not very VB like right?

Well it turns out workflow is smart enough to realize it can convert the string literal to a Time Span and use this. So when our power users does the following it just works [:)]

That on not the explanation I was given. And it would be a new experience where CSD reused something from another team. Normally they rebuild/reinvent everything as they believe they can do a far better job.

Forcing everyone to use VB because it is more convenient for business people is the stupidest excuse I have ever heard. What about all the applications that have nothing to do with business? Being forced to write code in the .net language for amateurs sucks big time. If you set aside this really irritating issue the workflow team is doing a great job IMHO.

It would be better to have an expression interpreter provider that to do the job. So everyone can write the expressions in the language that thay prefer, just changing/adding the provider in config file, just like memberships provider or something else.

I agree, the workflow should just store a parsed version of the expression and you should be able to edit it in whatever dialect works best for you. Unfortunately that isn’t the case for now. Lets hope they enable that some time in the future.

the workflow runtime is agnostic when it comes to expression languages, there are all the extensibility points to add in a parser, even an extension point to add a custom dialog/ visual editor for the expressions. It is possible to enable the scenario that you mention, where we could have a provider, it is just not something that we enable out of the box, nor do we have a designer that we ship for other languages besides vb (specifically referring to the expression text box).

We’re working on a sample that shows how you could implement a different expression text box if you want to support a different language (and also require a parser, etc).

Omg, this is probably the worst explanation I can ever imagine. Why MS deals with business users in technology for developers? Have you ever seen any business user who at least understands exception handling, compensation, transactions, persistence, services or event driven execution? How can people without solid knowledge of these key concepts modify WF? How many WF projects target on business users? I guess no more than 20%. But I understand it sounds great on marketing presentations.

I know the feeling. However that said there is some benefit to this. Having the workflow runtime to let users add to your app by rehosting the designer is not a bad idea by itself. The question is how practical this is in the real world. It remains to be seen.

And there is nothing wrong with marketing. No really, it means we can get payed to do all the cool stuff we enjoy 🙂

Why in world VB ? I have been preparing myself for WF 4.0 for some time and now when I finally started to get my hands dirty , I found myself into completely different world.I have never programmed with VB and I have no idea whats the syntax for initializing Dictionary in VB(yes I can look into google for help but that’s too much).

Maurice , Just let us know how much of knowledge of VB will be okay to get started with WF.

Don’t worry about it. Its only VB expressions not complete functions so the difference isn’t that big. For the most case VB has some extra but optional behavior. There are a few thing different like && is “And” and || is “Or” and “\n” isn’t seen as a newline.