Something more succinct than Function ?

I really dislike VB’s inline Function syntax… it’s incredibly verbose.  When they were looking at it, I suggested Func, but given that usage in the framework that would be confusing. (I hadn’t seen the Func(Of T,…) delegates at that time )  I would still like something more succinct. I’m wondering if we couldn’t have something like if you type f( and press tab or hit space, that get’s changed (similar to a snippet) to ƒ(

That is, why not use ALT+0131 if we can make it easy for users to add via IDE auto-modification.  So instead of :

Dim cust = customers.Where(Function(c) c.FirstName = “Smith”)._
                     Select(Function(c) c.FirstName & ” “ & c.LastName)

you’d have :

 

Dim cust = customers.Where(ƒ(c) c.FirstName = “Smith”)._
                     Select(ƒ(c) c.FirstName & ” “ & c.LastName)



4 Comments so far

  1.   Julie Lerman on February 23rd, 2008          

    Here’s a whacky idea.

    How about

    customers.Where(c=>c.FirstName = “Smith”)

    There’s probably a technical reason that won’t work though.

  2.   Roger Jennings on February 23rd, 2008          

    Bill,

    I dislike Function(c) intensely, but how about Where(c => c.CustomerID = “ALFKI”) for VB as well as C#? I never understood the VB team’s reluctance to use =>.

    –rj

    P.S. Enjoyed your garden posts!

  3.   bill on February 23rd, 2008          

    Wow! So both you guys wrote the same alternative !! (comments were awaiting moderation so you wouldn’t have seen each other’s at all)

    I’m not sure I like =>. I’d prefer that to be -> or → , but then again that’d jsut confuse C heads way too much 😉

    One thing we need to consider is multi statment lambdas, in which case c =>(…) would probably work a lot nicer than Function (c)(….) or Function(c) …. End Function

  4.   Granville Barnett on February 25th, 2008          

    Yeh I don’t get that either, but I’d stick with the => as like you said I think -> for C/C++ guys would mess them up!