Something more succinct than Function ?

Posted Sat, Feb 23 2008 12:41 by bill

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)

Filed under: , ,

Comments

# re: Something more succinct than Function ?

Saturday, February 23, 2008 8:33 AM by Julie Lerman

Here's a whacky idea.

How about

customers.Where(c=>c.FirstName = "Smith")

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

# re: Something more succinct than Function ?

Saturday, February 23, 2008 8:53 AM by Roger Jennings

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!

# re: Something more succinct than Function ?

Saturday, February 23, 2008 6:17 PM by bill

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

# re: Something more succinct than Function ?

Monday, February 25, 2008 5:54 AM by Granville Barnett

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!