Slashdot | Anders Hejlsberg on C# 3.0:
The new language enhancements include implicitly typed locals, extension methods, strongly-typed lambda expressions, anonymous types, and LINQ - a builtin SQL-like syntax for data access.
Rock on. I recently saw an article on LINQ at LtU, but the technology didn't pass my importance filter so I didn't read it. Now I find it's going to be in C#. But given my cursory look at some of the samples /. linked to, I don't immediately see how it's much different than Python's list comprehensions.
For instance, in Dan Fernandez' blog post about LINQ linked from the page with the interview with Anders Hejlsberg, he uses these examples:
var result =
from s in aBunchOfWords // query the string array
where s.Length == 5 // for all words with length = 5
select s; // and return the string
var result =
from c in allCustomers
where c.ContactTitle.Length == 5
select c.ContactName;
I don't see how that's any different than Python's:
result = [s for s in aBunchOfWords if len(s) == 5]
result = [c.ContactName for c in allCustomers if len(c.ContactTitle) == 5]
And I think Python's syntax is far more elegant. Of course, allCustomers in the second example was actually a database table. But you can already do that easily with Python's (or any other language's) generators. Consider (from an interactive console session):
>>> def allCustomers():
... custs = ["larry", "curly", "moe"]
... for cust in custs:
... yield cust
...
>>> [c for c in allCustomers() if len(c) == 5]
['larry', 'curly']
Of course, the syntax is a little different between the two examples, so a little bit of the implementation details leak into the syntax. Nothing's perfect.
Update: Slava on C# 3.0:
Take a look at the features planned for C# 3.0; they're basically adding a bunch of features from Common Lisp and ML... For years we have heard Java advocates say that higher order functions and expression trees lead to complex code that is hard to understand, despite plenty of evidence to the contrary. But now that Microsoft is adding these features, watch Sun scramble to catch up with Microsoft, yet again!
Update: Now I know what they mean by "implicitly typed locals". About 5:30 into the video Hejlsberg explains it (calling it "local variable type inference"). You can say var c = customers[i] instead of Customer c = customers[i] or Customer c = new Customer(). I've always complained that the latter two have redundancy, so I'm definitely a fan of that new feature. Plus, does this mark the first entrance of type inference (basic though it is) into a mainstream language?
Update: After watching more of the video, that query language is pretty cool. I love how it works with anything that's IEnumerable, and that the expressions given as filters are actually type-safe (with type inference) lambas, creating anonymous types as they go.
new⇒Perl 6 1.0 in March?
Doh, my mistake. I'm aware of therelation between Parrot and Rakudobut I'...
Keith: Dec 2, 1:03am