Share via


What annoys me when writing generic functions in Visual Studio...

When writing a generic function I start from left to right (the same way I write most things except when I took Yiddish in college).  For example, Lets say I am writing a simple generic method which return the first element of a generic list. I want the signature of this method to be:

 private T First<T>(List<T> list)

 

I start by writing the visibility:

 private 

I then need to write the return type so I type T.  The problem is that since T is not defined as a generic type parameter yet so intellisense tries to help me out by showing me all types that begin with T:

image

 

Now my instinct here (every time) is to press space since I just want to move on to the next word since T is all I want.  But space will auto-complete T with ThreadStaticAtrribute.  What I need to do is press esc to close the intellisense window and then press space.  This may seems like a silly issue, but I seem to never remember that I need to do this.

Visual Studio and intellisense have done nothing wrong here , I just wish intellisense had the ability to read my mind and understand exactly what I am intended to do.  It could save me a couple key presses a day!

Comments

  • Anonymous
    October 14, 2008
    Yea, it's annoying. Of course, it's also annoying you have to specify the return type and generic parameters at all :).

  • Anonymous
    October 14, 2008
    Actually, yes, VS is the culprit here - it really should learn the generic syntax and try to figure out that you're typing a generic. I.e., when typing "<" after an identifier in the class scope when it can only be a method/property/event declaration (which means that it already has a return type), do not show that dropdown. Actually, I often think that Java guys were right when they lifted the generic arguments outside the signature, as in: public <T> T First(List<T> list). It reads quite naturally if you treat <T> as "for all T" (which is the way it should be), and has proper lexical scoping in a sense that you first introduce the symbol, and only then use it. That also helps code completion to not be confused when parsing the return type.

  • Anonymous
    October 15, 2008
    I am confused by "I.e., when typing "<" after an identifier in the class scope when it can only be a method/property/event declaration (which means that it already has a return type), do not show that dropdown." For me it does not show the dropdown (unless I am misunderstanding what you mean).  For example if I am define a method: private void Matt<T At that point no drop down appears. About your second point, I havn't use generics in java yet but that isnt a bad way to do it.  It does make a lot of sense listing the type variables the function is parameterized over.

  • Anonymous
    October 15, 2008
    Yes this is very annoying.  It's interesting that of the 4 main languages of VS (C#,VB,C++ and F#) only C# has this issue.  Namely because it's the only one of the languages who uses a generic type before it's specified.  The othre three languages will define the generic (left -> right) before ever using it.

  • Anonymous
    October 22, 2008
    why not uncheck "commited by pressing the space bar" in IntelliSense options?

  • Anonymous
    October 22, 2008
    Because I like it commiting by pressing space bar :) I like it all the time except in this generic function definition case.