Sat, November 24, 2007, 11:21 AM under Orcas
I was reading this post on the VB blog about hidden gems in VB
with the VS2008 release. I knew all of them until I came to item 8: the "Go To Type Definition" menu (I am not sure if this was functional in Beta 2...). This is available only on the variable
declaration and it takes you to the definition of the type of the variable.
But hang on! Couldn't we always do that? Yes, we could: The existing "Go To Definition" menu does that if you execute it by right clicking on the type
rather than the variable. So, the only benefit of the new "Go To Type Definition" menu is for scenarios where you are using local variable type inference
and hence don't have the type explicitly appear in your code (in order to use the existing "Go To Definition" menu).
I thought that was cute, but something was bugging me about introducing a whole new menu item for this purpose. Couldn't the VB team simply go to the type definition if I selected "Go To Definition" on the Dim keyword? I checked with some C# code that uses local variable type inference
, and indeed that is what it does when you select "Go To Definition" on a var. As it happens, I prefer C#'s approach on this one.
Regardless of what I prefer, I would have like some consistency here between the two language approaches but I am sure this is where the product teams tell me that they are catering for two different audiences and I don't want to open that can of worms again.
I'll finish off by saying that I prefer what VB means by go to definition for a type, as opposed to how C# does it. In VB, going to a type definition that is not in your code, is interpreted as going to the Object Browser. In C# (since VS2005), it disassembles the signatures of the type from the external binary and presents it in C# code in a separate file – yuck! Why can't C# just take me to the OB where I can see in a more concise format all signatures and documentation? There should be a separate
command for disassembling the type in header style just in case I need to copy/paste something... Anyway... mini-rant over.