KBD

Keith Devens .com

Saturday, March 20, 2010 Flag waving
Crying is all right in its way while it lasts. But you have to stop sooner or later, and then... – C.S. Lewis (The Silver Chair, ch 2)
← µTorrentI love when Slava rips Java →

Daily link icon Sunday, September 18, 2005

Anders Hejlsberg on C# 3.0

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.

← µTorrentI love when Slava rips Java →

Comments XML gif

Hannibal (http://agentmine.com/blog) wrote:

Is that a new record for the number of updates of a blog post?

∴ Hannibal | 22-Sep-2005 9:56am est | http://agentmine.com/blog | #8317

Keith (http://keithdevens.com/) wrote:

Not a record, but certainly one of the more heavily updated posts in a while.

Keith | 22-Sep-2005 1:27pm est | http://keithdevens.com/ | #8318

Hannibal (http://agentmine.com/blog) wrote:

It's a very interesting subject. I do have to disagree with Slava's "Sun scramble to catch up with Microsoft, yet again" comment.

Sun didn't even come close to catching up to C# with the 1.5 release.

∴ Hannibal | 23-Sep-2005 10:20pm est | http://agentmine.com/blog | #8326

Feel free to post a comment below. Please see my comment policy.

Formatting Rules (No HTML):

  • **bold**, *italic*, _underlined_, --strikeout--
  • "text"="url" creates a link, and URLs are auto-highlighted
  • Blockquote: Like e-mail, begin paragraph with > (greater-than sign)
  • Lists: begin paragraph with *,-, or + (unordered), or # (ordered)
  • Code block: ?!code:language=perl|php|sql|javascript|etc.{\n}...{\n}?!/code

:
(will be your IP address if blank)
: (optional)
(Will not be shown on site)

: (optional)
:

March 2010
SunMonTueWedThuFriSat
 123456
78910111213
14151617181920
21222324252627
28293031 



RSS feed RSS feed for Keith's Weblog
Atom feed Atom feed for Keith's Weblog
Weblog archive
Recent comments
  on 2 posts

Recent comments XML

I hate ASP.NET

I hate ASP... I was doing wonders​with PHP, then suddenly one of my​clients...

Johnies: Mar 17, 6:14am

Quantum physics and free will

I knew you were going to say that....

Tom Massey: Mar 15, 9:26pm

Generated in about 0.124s.

(Used 8 db queries)