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.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
…and connection strings, and command builders, and data adapter builders, and…
great idea.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
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.
August 16, 2004 at 12:00 am
JTD,
Thats just because they are the low hanging fruit
August 16, 2004 at 12:00 am
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.
August 17, 2004 at 12:00 am
You should post this suggestion up on the Ladybug site: http://lab.msdn.microsoft.com/productfeedback/Default.aspx
August 17, 2004 at 12:00 am
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
August 17, 2004 at 12:00 am
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.
August 17, 2004 at 12:00 am
It would be pretty neat if building connection strings and things could fire up something akin to the UDL editor.
August 17, 2004 at 12:00 am
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.
August 17, 2004 at 12:00 am
Cool! I voted for it, and solicited votes for you entry on my blog as well.
August 18, 2004 at 12:00 am
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.
August 18, 2004 at 12:00 am
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.
August 18, 2004 at 12:00 am
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.
August 18, 2004 at 12:00 am
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.
August 18, 2004 at 12:00 am
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).
August 18, 2004 at 12:00 am
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.
August 18, 2004 at 12:00 am
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
August 19, 2004 at 12:00 am
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.
August 23, 2004 at 12:00 am
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…
August 24, 2004 at 12:00 am
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
September 14, 2004 at 12:00 am
Hi Mitch,
This post is linked from the latest episode of the DotNetRocks show.
http://www.franklins.net/fnetdotnetrocks/dotnetrocks.aspx?showid=81
September 14, 2004 at 12:00 am
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.
February 21, 2008 at 11:31 am
[...] Orcas Code Builders [...]