Los Angeles Masters Series – Workflow on Dec. 1

I’ll also be doing an all day “Introduction to Windows Workflow” talk on Saturday for the Los Angeles .NET Developers Group . If you’re in the area, or can get a great weekend flight rate in, it’s a fabulous deal. I call it “Introduction” because there’s still so much we’re all learning about workflow. But this will be much more than a little drag drop. I’ll be specifically focusing on architecture guidelines that I want people to work with from their very first workflows. I’ll be looking at Why as much as How. I’m also available to give workflow sessions in your organization if you can’t make it to LA. The link for the LA event is http://www.ladotnet.org/default.asp and I don’t think it is sold out yet.


I’ll be at DevTeach this week. If you’re there, drop by and say Hi! Conferences each have distinct personalities. DevConnections was intense in Las Vegas early this month and I know I walked right past at least one friend without seeing them because my brain was elsewhere. I tend to push myself hardest at DevConnections. DevTeach and SDC (Amseterdam) are much more relaxed for me and I’m looking forward to a great week.  I’m talking on three subjects I enjoy – WPF controls, WF activities, and What’s New in C#. I didn’t manage to get a single conference to let me do both C# and VB new stuff this fall, but I did it at two conferences. I believe in being bilingual.


Next week I’m in Roanoke and then California Maryland. If you can make those user groups, it will be great to see you. That’s my party down ending to an insane quarter. The last of 27 speeches in 90 days. I’ll spend that weekend hanging with some old friends’ labs near Charlottesville and meeting their nearly grown kids for the first time. A totally awesome ending to what’s been a great quarter. I’ve got to be the luckiest person on earth.

 

 

C# 3.0, VB 9.0 and Anonymous Types

Rick Strahl talks about new C# 3.0 features, but leaves a few questions…


Why can’t you change the property values instances of anonymous types?


The problem is that instance of anonymous types are hashed by hashing all values. Thus, if values could change, all hashes would have to be updated (impossible with the .NET design) or hashes would not match and all sort of unacceptable side-effects like dictionaries no longer finding their key values.


Visual Basic used a different approach allowing you to identify individual properties as keys with the “Key” keyword. Only these values are readonly, while other properties can be changed.


Why can’t we pass around instance of anonymous types around?


We can! That was my Thanksgiving present this morning. Check this out… from Alex James


You do however need to know the structure in the receiving routine, and you’ll also needs some casts so this isn’t going to be quite as fast as a real class. I wanted to test this approach in VB console project:


Module Module1

      Sub Main() 

            Dim x = New With {.FirstName = “Fred”, .LastName = “Smith”}


            Test(x)

            Console.Read()       End Sub   

 


      Private Sub Test(Of T)(ByVal x As T) 

            Dim y = x.CastByType(New With {.FirstName = “”, .LastName = “”})             Console.WriteLine(y.firstName & “, “ & y.LastName)       End Sub   

 


      <System.Runtime.CompilerServices.Extension()> _ 

      Private Function CastByType(Of T)(ByVal x As Object, ByVal y As T)          Return CType(x, T)  

      End Function

End Module 

 


The trick is that the cast method takes another anonymous type declaration which matches the one we’re working with. The extension method makes the call look more natural, but I don’t think I’d use it in a real project because CastByType now shows up in Intellisense for every type – anonymous or not.


There’s been some confusion about signatures of anonymous types. These signatures include both name and type, which you can see if you change Test above:


   Private Sub Test(Of T)(ByVal x As T) 

      Dim y = x.CastByType(New With {.FirstName2 = “”, .LastName2 = “”})       Console.WriteLine(y.firstName2 & “, “ & y.LastName2)    End Sub  

 


This results in a runtime error on the cast in the CastByType methods. That’s one more reason to be careful where you use this technique.


Still it’s cool to uncover new things in .NET 3.5.


 


 

DevConnections Orlando

I’m happy to be back at DevConnections in Orlando April 20-23rd. We’ll be at the Marriott again which is big enough to hold the expanding show.


I’ll post soon as to what I’ll be talking about, but I expect to expand on the topics popular in Las Vegas and important to you – Workflow, WPF, and data architecture. I know I’ll be talking about customizing Entity Framework in the Data Access track.


Stay tuned for the schedule to be posted and start twisting your boss’s arm.

More on the VB 9.0 Compiler Bug

Let me give a little more information on the project which demonstrated the VB 9.0 compiler bug and think its best illustrated with a picture.


In addition to having the accidently file reference from a stray assembly (Assembly1 in the picture) there is a relationship among four assemblies that drive the app (there are actually a few more, but these seem to be the relevant ones). To reuse and remove circular reference issues (with the other assemblies) there is a Common base assembly. There is also a GenericBase assembly which contains a set of generic based extensions to Rocky Lhotka’s CSLA. CSLA does not appear to be involved in the VB 9.0 compiler issue. The Common and GenericBase are reused for different application logic modules that happen to be written in C#. I wrote in C# because this is a huge assembly and offered unacceptable IDE performance prior to SP1 of VS 2005. I haven’t taken the time to go back and rewrite to VB, which I will do soon with the LINQ to XML generation approach. Finally, a WinForms application runs the application.


I don’t think there is anything particularly unusual about the relationship between IBase, CBase(Of T As IBase), and CDerived. The syntax CBase(Of T As IBase) describes a generic class that restricts the type parameter to classes implementing IBase – providing the generic constraint that seems to be part of the problem.


What is unusual is the inclusion of C# and VB in the same solution. If you’re doing that, I’ll be curious because I’m one of the few people that seem to encourage using the best tool for any task. Apparently the metadata reference that results contributes to the alignment of stars to cause the problem. I’m trying to find out how confident the team is that if you don’t cross languages you won’t encounter this problem. I’ll post more when I know more.

 

 

How to Sidestep a Visual Basic Compiler Bug in RTM

A couple of weeks ago I ran into a very surprising bug in the Visual Basic compiler after upgrading a project from 2005 to 2008. To make a long debugging story shorter, I realized a line of code was not included in the IL output. This particular function call was missing regardless of how I rearranged the code in a Try block, etc. After confirming this with Reflector, I realized that there was a significant bug and worked as hard to preserve the problem as to solve it.


While I’m not happy that the VB compiler has such a serious bug, I am happy with the team’s response. I’m pleased in how they worked with my zipped project to confirm the problem and look beyond my immediate fix (a solution clean, worked out over IM with Bill McCarthy). I’m also happy that they quickly planned a resolution, even if it couldn’t be ready for the RTM release.


In case the magnitude of the problem isn’t clear yet, there is a scenario in which you cannot rely on fidelity between your source code and the IL that runs.


At least two things have to happen for your project to be vulnerable to this issue – you have a constrained generic in an assembly and that assembly is referenced by both project and file references. It’s not clear to me why this confuses the Visual Basic compiler - but it sometimes does and the reason is clear to the team.


The VB team plans a fix for SP1. Obviously that doesn’t help us today. You need to check your solutions for this mixed reference approach if you are using constrained generics in your common utility classes (which I’d encourage you to do because of the power of generics). There may be other conditions that have to also be in place for the bug that I don’t know about, but avoiding mixing file and project references is the easy way to break the offending cycle.


The team is also working on communicating this problem and probably including a KB article that explains the problem. I expect they will also supply a tool to identify mixed references and set them all to project references for all the goodness that provides to Visual Basic. I’ll let them share their future plans in the VB team blog. Since RTM is out now, I want information on this out so you can protect your projects.  


I do not believe you should avoid the RTM release of VB 9.0 becuase of this bug. I do think its important that you check your projects to ensure you don’t smack into this. And tell all your friends to do the same.


I’ll have more links here as if there’s any new information and certainly to the KB article when its out.


 

Vista Death Watch Overstated

I think it’s awesome that John Dvorak is still writing for PC Magazine.  The world has spun around many times and this industry looks almost nothing like it did when we all started in the 1980’s. One of the things I love about Dvorak’s voice through the years is that he’s not afraid to stick his neck out and be wrong. He did that in his recent editorial on Vista.


Vista, good and bad, is not about marketing and only slightly about price point. You simply don’t need to market and operating system if PC manufacturers are doing it for you. Microsoft did blow the pricing because Microsoft and the ecology need Vista more than you need to move. The pricing is dangerous in the long run, but not terribly relevant in the short term.


The problem with Vista is that the reason you want it on your desktop is technical subtleties, not flash. John says “all the cool and promised features of the original vision of Longhorn”. That implies that a fundamentally better security model isn’t a cool feature. I was in the room when Longhorn was announced at PDC, and it might shock people to learn that people like me were telling our contacts at Microsoft that they were crazy in thinking developers could uptake that many new features in less than a decade. Four years in, we didn’t exaggerate by more than a year or two. The Longhorn vision needs to come in bits and pieces.


What Vista needed most is exactly what Vista has: a new security model and baked in 3D graphics.


I moved to Vista against my will because I bought a new laptop in the timeframe where PC manufacturers were not offering XP. I have fallen in love with the productivity features of the operating system. Real productivity features are rarely flashy. The new Windows Explorer has two features worth the price of admission. I can drag things on and off the “Favorite Links” pane to have a real time view of my focus. The ability to drop down higher level folders to easily reach sibling folders also saves a handful of seconds dozens of times every day.


The downside of Vista is also technical. The real elephant in the room is not price, it’s drivers. I have a perfectly good HP LaserJet 6L which last I heard did not have Vista drivers. I already struggle because it doesn’t have a USB port and laser printers are finally cheap, so this hit my “never waste” nerve far more than my actual pocket book. Microsoft’s belief that hardware manufacturers would write Vista drivers for old equipment was naïve. Microsoft should have provided an independent driver upgrade tool – and if that was not possible, create even low-performing drivers to keep the plethora of accessories functioning and out of landfills.


I advise family members on software and often buy it for them. My Dad’s on Vista. He hates it, but it’s where he belongs so he can play more safely on the Internet. My Mom’s on Vista and doesn’t mind because she upgraded from Windows 95 (no joke). She’s her retirement communities computer expert now because she knows tricks like how to go back up a directory in Vista’s file explorer and how to use that text box in the Start Menu. My brother’s brand new box is XP because he has more invested in peripherals than the new laptop (two expensive keyboards, etc).  My niece is an artist and Vista is gentler and less clunky. An ex stripped my niece’s previous box of MS software and loaded Ubuntu. My son’s are also both on Linux. Their choice but it’s good that they have to pay attention to their OS.


In the short run, the problem is technical features never win without flash. That’s our problem. In the long run, Microsoft chasing Google is stupid. John’s correct that they sell software and they should still be worried about Linux. The reason more people aren’t on Linux is that they are afraid of it. Remove the fear and Linux is a perfectly adequate operating system – already having some of the core security features Vista added.

 

Looking at the List (2 of 6 or 7)

Here’s the next round!

 

11.  Property dialogs


In addition to designing objects for their actual visual interface, we design certain types of objects for how they will behave in the property dialog – whether visible and what editors they have available.

 

12.  Designers (Workflow & UI)


In addition to designing objects for their actual runtime behavior, we design them for how they will behave at design time – visual designers, avoiding issues with instantiating base classes (WinForms disallowing abstract/MustInherit base classes), etc.

 

13.  Design Patterns


Where possible, we design to patterns. Meaning that in addition to the details of our technology, we try to design to the lore of repeatable patterns.

 

14.  Unit testing


In addition to designing for runtime behavior, we design to test. This is particularly evident with BDD/TDD’s use of MVC patterns because they test well. But it’s also true of other applications. If we are testing them well, we wrote them to allow good testing. Testing also raises scope issues.

 

15.  Refactoring


The creation of our classes is dynamic in today’s world. The time of CRC cards when we actually thought we should get the properties close to correct first time out are gone. Renaming, switching parameter order, and more complex refactoring are common.

 

16.  Interfaces (contracts)


This was actually in Booch’s book, and of all the things here perhaps doesn’t belong. However, in my world of the 1990’s we did not think in contracts. Interfaces are contracts in our world and they are arguably more important to get correct because of versioning issues than anything else about our objects.

 

17.  Multiple assemblies


Assembly boundaries have become a critical point of visibility. Protected scope is more public than interna/Friend scope. Also, we do not have a protected and internal scope, only a protected or friend scope.

 

18.  InternalsVisibleTo attribute


Assembly boundary scope visibility can be broken via the InternalsVisibleTo attribute. While not widely used today except in testing, this is an important break to scoping.

 

19.  Overloads


Overloads means the same method can have multiple parameters sets – meaning multiple signatures. This means it’s more difficult to define exactly what a specific method does. This is also an area where few programmers understand details of what happens, and generics alter the impact of the rules.

 

20.Perf and virtual table issues


We shouldn’t program for this because the impact is too small. Unfortunately, Microsoft did and we are faced with an inflexible List class and a System.Collections.ObjectModel.Collection with few features. The impact on our code is we have to determine future needs to select the correct class.


 

Looking at the List (1 of 6 or 7)

I posted a list of ways that development has changed since the days we thought we knew how to design applications. I want to clarify a few things on this. This is about design or approaching architecture – it goes beyond OOD per se. I started out from that perspective because we believed when we were doing OOD that we could get our heads and hands around designing our applications. We can’t anymore, and it’s the changes I’m identifying here that keep us from that holistic approach.

 

I’m sharing with you a process of getting back to that holistic approach. We first have to understand the problem.

 

But calling this a problem is itself problematic. The items on this list are the things that make development great. When I asked Bill McCarthy about this list he said “oh you mean your list of the fun stuff about programming”. This really is the stuff to celebrate. But in the meantime, it’s making us a bit insane.

 

I want to walk through each of the 60 items. To do this, I’m going to split the list into groups of ten so it doesn’t get too overwhelming:

 

1.  Parallel entities


Instead of creating objects that do their jobs, we create sets of objects that work together to supply required plumbing before we even arrive at the point our business objects can start working. We have many entities and they have identical or nearly identical structures. In addition to a vertical design, we have a horizontal design that is at least as important.

 

2.  N-Tier


The horizontal structure stretches across many layers, at least potentially. These layers are essential to proper functioning and performance, and they are quite likely to evolve over the lifetime of the application.

 

3.  Sheer magnitude


Some design aspects, including visual drawings and CRC cards break down when the number of objects is very high – on the order of hundreds, not dozens.

 

4.  Application code generation


Generating code means we design certain things at the template, not object level. It also means we can change our design during the application life cycle which significantly changes up front planning.

 

5.  SOA (Service Oriented Architecture)


Service oriented architectures means we’re writing about tasks and basically designing significant portions of our applications one step higher than business objects. These services interact, not the objects within them.

 

6.  Semantics and canonical messages


Semantics and canonical messaging becomes very important in diverse organizations. The concept of an object is tightly coupled to its name in traditional design and must be decouple to provide a canonical view.

 

7.  Workflow


Like SOA, Workflow uses objects for task sequencing and works more at a task level of thinking than an object level. However, unlike SOA, these services need to be small grained to allow flexible combinations, instead of large grained for communications.

 

8.  Rules engines


Rules engines mean that our objects may not know what will happen when they run. They do not even know their own dependencies.

 

9.  Aspect oriented programming


Aspect oriented programming means we run code in unique ways based on attributes – especially delegates on attributes. .NET has a poor AOP model and this is largely a future looking item.

 

10.Impact of libraries


We no longer live and breathe isolated applications, but applications where much of the code is long lived and reused. These libraries have to be planned and maintained for the greater good, not the benefit of individual applications.


 


 

New Items for the List

While annotating the existing list, I came up with several new Items for the list of things that have changed since the days we thought we knew how to design object based applications (the last 20 years):


48.  Database demands (normalization/denormalization, primary keys, replication keys)


49.  Serialization


50.  Chatty/non-chatty interfaces


51.  FxCop


52.  Using/Import


53.  Generic constraints


54.  Readonly source code files (an implication of code generation)


55.  Events


56.  Lambda expressions, anonymous methods and closures


57.Expression trees (lambda expressions )


58.Attached dependency properties


59.Data binding


60.Late binding