KBD

Keith Devens .com

Sunday, October 12, 2008 Flag waving
Intertwingularity is not generally acknowledged – people keep pretending they can make things deeply hierarchical, categorizable and sequential when they can... – Ted Nelson
← µ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)
:

October 2008
SunMonTueWedThuFriSat
 1234
567891011
12131415161718
19202122232425
262728293031 



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

Recent comments XML

new⇒URL design

http://groups.google.com/group/cool​ndex/web/asian-girl-sucking-to-blac​k-man...

derek: Oct 12, 12:13pm

I hate PHP

Elliot Anderson,

Dude!! You the​man! The reverse replacement for​array_u...

Alex Ndungu: Oct 11, 1:35am

Call a function from a string in Python

?!code:
some_object.__getattribute​__('method_name')()
?!/code

is​the s...

Patrick Corcoran: Oct 8, 3:53pm

Spider solitaire

I have won 185 games of Spider​Solitaire at the "Difficult" level.​ What is...

75.179.28.113: Oct 8, 12:42pm

Sed one-liners

Hi.

I wanted to let you know​that I wrote an article "Famous Sed​One-Lin...

Peteris Krumins: Oct 8, 3:05am

Timesheet Calculator

Hadn't seen it before now, but my​company already uses a time​tracking prog...

Keith: Oct 7, 10:44am

Girls, please don't get breast implants

Hey everyone, 

I am new to this​blog and I have enjoyed reading all​your...

Sarah.M.: Oct 6, 9:45am

Generated in about 0.2s.

(Used 8 db queries)

mobile phone