Orcas: Code Builders

August 16, 2004

I’m sure there are some people out there that are going to hate me for this, but I started thinking about the sorts of features that I want in the version of Visual Studio after VS2005 (codenamed Orcas). This idea came to me while I was talking to a student in the class I taught today as we walked down-stars.

Over the past twelve months or so I have become a huge fan of designer technology and I’ve started to imagine how good things could be not only on the component design surface but also inside the code-window – I was inspired in a big way by the improvements that have been made to the debugger, but I wanted something that could help me as I wrote the code – not as I watched it crash.

Anyway – my idea is “Builders” – I don’t know if there is any prior art here, I don’t care either, I want this feature. Basically, while typing in the code for my application I want VS to look-up metadata associated with the classes, properties, methods and method arguments that I am typing and render builders. As an example I have mocked up an XPath expression builder which is being applied to a string.

The method signature for the SelectSingleNode method would look something like the following.

public XmlNode SelectSingleNode(

    [Builder(typeof(XPathExpressionBuilder))] xpathExpression

    );

Because you’d want to be able to retro-fit the builders to existing code I would imagine some kind of XML drop point like we have for expansions to hook up builders to classes, properties, methods and method arguments. There would also be some overlap with existing property editors – perhaps “we” could find a way to host the editors inside a builder display when editors were specified, but builders weren’t – the usual codedom generation could also come into play – but that would be secondary – and somewhat ugly.

The idea here is to reduce mistakes and also made the actual task of code development a little bit more guided. I chose XPath specifically because its a hard syntax to grasp sometimes – it also makes a good case for cross-language builders – the same builder could be mapped to functional programming langues – but also to declaritive data structures like XML.

Update: I made another post here about code builders – please read it before commenting re: embedding filenames in source code.

28 Responses to “Orcas: Code Builders”


  1. Wow, cool!!!

    I can see a usage with filename parameters.

    The Xceed FileSystem exposed many filename parameters, I sure would love to provide users with a “FilenameBuilder” class:

    DiskFolder myFolder = new DiskFolder(

    BOOM! A FilenameBuilder would then let the user type a file or folder name with auto-completion based on existing files and folders “à la AddressBar”, browse with a treeview, select from an history, create subfolders from within the builder, etc.

    Obviously, this would apply to many System.IO.* classes too.

  2. anon Says:

    …and connection strings, and command builders, and data adapter builders, and…

    great idea.

  3. JTD Says:

    It’d also be nice if VS.NET automatically stored away the result in a config repository of some sort, and what got added to your code was a lookup from the repository. Maybe some intelligent lookup to avoid duplicated strings.

    I would imagine most of the places you would use a ‘builder’, you wouldn’t want the actual string embedded in your code.

  4. Mitch Denny Says:

    Hi Martin,

    Glad you like the idea. I was also thinking that the mapping between the code and the builder should a live two way thing. So if you change the text the builder UI would (or atleast could) hook those changes and respond accordingly.

  5. Mitch Denny Says:

    Hi JTD,

    The result caching idea is a good one (files that one away until he can corner someone of the designer team at MS). But I think you may have missed an important point – the builders wouldn’t just be used for creating strings – they could be used for building complex objects too.

    I’m thinking things like WSE 2.0 security configuration, or (back in string land) finding out the OID of the crypto algorithm that you want to use.


  6. Sure!

    In my filenames example, we could think or having the builder open on a particular shortcut, and if I were to hit it while having typed this incomplete string param:

    DiskFolder folder = new DiskFolder( @”C:\My Music\MOD\Martin

    It could show something like this:

    http://www.cam.org/~max/images/FilenameBuilder.jpg

    The same would apply for an XPath expression. The builder would recognize what’s been already typed, and provide a better input UI (and syntax validation). And the builder would work properly for either an incomplete (not-yet quote terminated) string and a complete string.

    It’s power code completion for string parameters. And I’m sure somebody can give an example for something else than a string.

  7. JTD Says:

    Gotcha! Yeah, Mitch, I see the bigger scope of what the builders could be used for now. All the examples and discussion I saw was about ‘build’ing string parameters.

  8. Mitch Denny Says:

    JTD,

    Thats just because they are the low hanging fruit :P

  9. Andrew Storrs Says:

    Like Martin said earlier – I would want to be able to create builders for other developers to make use of. Developers could greatly simplify the use of more complex object types, and greatly reduce on the learning time required to make use of them…

    … and anything that helps me use XPath without being forced to look up the syntax is a winner. :)

  10. Mitch Denny Says:

    Hi Bruce,

    I just did that:

    http://lab.msdn.microsoft.com/ProductFeedback/viewFeedback.aspx?feedbackId=FDBK13881

    Now – can you help me get enough votes on it to make it a feature in Orcas or what :P

  11. AIM48 Says:

    Neat Idea – the only problem I can see (at least with the file dialog suggestion) is that you would be encouraging “magic values” thruout the code instead of a more central constants module – which would lead to a maintnence nightmare. Specifing hard file paths is hardly ever a good idea.

  12. DrPizza Says:

    It would be pretty neat if building connection strings and things could fire up something akin to the UDL editor.

  13. Mitch Denny Says:

    Hi AIM48,

    Thats the magic of it. The mechanism could actually encourage good programming practices by having an option box on the balloon that lets you choose between a literal or typing in a configuration key.


  14. Cool! I voted for it, and solicited votes for you entry on my blog as well.

  15. Eric Newton Says:

    i would shoot somebody first.

    unless this builder knew how to persist these changes to a config file. otherwise BAM we got MILLIONS of developers Drag-N-Dropping HARD CODED LITERALS ALL OVER THE PLACE.

    Yikes. but only for FILE PATHS and such because that crap changes too much. you CAN however hard code XPath queries because the XML moving back and forth is supposed to be somewhat agreed upon.

    So I just hope to NOT see these builders unless it has built in abstraction to config files.

  16. lexp Says:

    Builders for me are ideal for:

    1) XPath expressions

    2) Regex expressions

    3) In-place Resources browser (besides intellisense as in VS2005 beta1)

    As to hardcoding strings, it’s a great pain for developers to maintain such code, and builders are really bad idea in this case.

  17. Roger Heim Says:

    Visual FoxPro has had ‘builders’ for a few versions. They do pretty much exactly what you’ve described.

    Plus they’re extensible (using a ‘builder’ builder) so the developer can create his own builders.

  18. Mitch Denny Says:

    Hi Roger,

    Could you post some screenshots of the FoxPro stuff somewhere – while you are doing that I am going to annoy one of the friendly local .NET evangelist who happens to be a Fox guru.

  19. Mitch Denny Says:

    Hi lexp,

    Its not just for strings – it could be used for complex objects too (I’m thinking things like crypto, building SqlCommands inline etc).

  20. Mitch Denny Says:

    Hi Eric,

    I’d imagine that MS would be the ones to implement the first and most powerful builders. Programmers would put literals in anyway – this way the builder could guide the developer to creating a better solution by doing the requisite config bound stuff.

    One important feature would be the ability to override the [Builder(...)] attribute via some config files in VS so that you as a tech lead could provide your own builder delivered guidance about code.

  21. secretGeek Says:

    this is brilliant mitch.

    first-class thinking!

    Everyone who reads it gets that same feeling. Their mind explodes with the possibilities.

    xpath and reg-ex are great candidates.

    cheers

    lb


  22. You may already know this, but it’s EASY to create these with CodeRush…I’m working on one for XML Documentation now. Works right in the editor.

  23. Eric Newton Says:

    I hate being the nay-sayer but a builder for such things that are so fluid like FilePaths and IPs for instance, without some kind of configuration store abstraction is kinda a bad idea.

    However, the XPath builder is a great idea.

    Other great suggestions of things that would lend themselves to a Builder pattern would be the RegEx’s, the XPath Queries, and more or less SQL Queries… [suggestions by others]

    So I’d say these things would work well. but not FilePaths or virtual directories or things that are so fluid in most circumstances…

  24. Mitch Denny Says:

    Hi Eric,

    I see you point, and a lot of people have raised it. I created a new post which covered that kind of aspect – I specifically went for string literals again to drive the point home. Notice the code that it generates.

    http://notgartner.com/posts/547.aspx

  25. Chris Garty Says:

    Hi Mitch,

    This post is linked from the latest episode of the DotNetRocks show.

    http://www.franklins.net/fnetdotnetrocks/dotnetrocks.aspx?showid=81

  26. Mitch Denny Says:

    Thanks for letting me know Chris. Looks like Mark had some interesting feedback. I wonder if there is any way it could work for him too. Maybe sliding the code down.


Leave a Reply