PDC Languages Panel and (Shortened) Lambdas Talk

At PDC 2010 this week, I participated in a panel and gave one talk. Both are now online for live on-demand viewing.

Note: The talks should work on any browser. They do not require Silverlight. If you get a message that Silverlight is needed, it just made a mistake in auto-detecting your browser (I’m told this happens with Firefox sometimes), so just click on one of the alternate formats and Bob’s your uncle.

Here they are:

1. Languages Panel (update: new link)

I got to participate again this year on a fun panel on programming languages and software development, together with fellow panelists Anders Hejlsberg (creator of Turbo Pascal, Delphi, and C#), Gilad Bracha (of Java and Newspeak fame), and Mark S. Miller (of Ecmascript and E and general security fame). Our esteemed moderator, Erik Meijer, is one of the original designers of LINQ in C# and has contributed heavily to many other languages.

2. Lambdas, Lambdas Everywhere (update: new link)

This is a shortened version of the full lambdas talk I gave at C&B on Wednesday, and will be giving again at C++ and Beyond Encore this December. To get the full talk, come to C&B Encore… but to get a good chunk of it, check out this version online.

Note: Just before the talk, I went around the room to chat with individual attendees, and discovered that a lot of the audience members were C# programmers who didn’t realize this was a C++ talk. Just before we went live, I spoke up to the room and alerted everywhere about that, and nearly everyone stayed anyway, which was nice. But if you wonder why I mentioned C# lambdas a number of times to this audience, that’s why.

11 thoughts on “PDC Languages Panel and (Shortened) Lambdas Talk

  1. Hmmm… I don’t think your comments parser likes embedded > or <‘s. I hope you get the idea anyway…

  2. Hey Herb,
    I attended the C&B talk (thanks again!) and I was thinking about lambdas the other day and something occurred to me that I don’t believe ever came up in our discussions…

    Is this legal:
    auto fasc = [](int l,int r) { return lr; }

    sort(v.begin(),v.end(), bAscending ? fasc : fdesc );

    ?

    … or would you have to separate it into two calls:
    if ( bAscending )
    sort(v.begin(),v.end(), fasc );
    else
    sort(v.begin(),v.end(), fdesc );

    ?

  3. I, too, would like to thank Herb for posting these talks (and Alexis for linking to the mp4’s). This is great stuff.

    A couple of minor points regarding the lambda talk:

    1) On the slide(s) titled “Attempt #2: Localize All Data And Functions” you write

    int g()(int k) {

    The parentheses after g should be removed. They seem to be a leftover from a previous slide, where you were defining operator().

    2) On the slide where you discuss calculating a product with accumulate, you say that long long is lost. Couldn’t you have used multiplies to promote every int encountered to a long long? (assuming you had also replaced 1 with a long long version).

    Cheers,
    Alex

  4. @Maxim: Thanks!

    Re auto for C++03: Yes, I should have shown the non-auto version in that line, thanks.

    Re Boost bind and lambda: On the one hand, I don’t mention them because they’re nonstandard. On the other hand, I do mention them… I mention bind as std::bind in the one example (because now bind is draft-standard), and in the longer version of my lambdas talk I use Boost.Lambda as a motivation for why lambdas need to be done in the language and can’t be done well as a library. I’ve been a longtime booster of Boost.Lambda, but it has serious drawbacks that prevent me from recommending its widespread use, such as that it’s great for short expressions but it doesn’t handle member functions or longer bodies well, and that it’s great as long as you type the code perfectly but the error messages are truly impenetrable.

    Re Adobe: Again, I haven’t mentioned it because it’s nonstandard. I’ll look at including a mention in the slides though.

    Thanks again,

    Herb

  5. For those having Silverlight problems, high resolution mp4 of the languages talk is now available here:

    [video src="http://videoaz.microsoftpdc.com/vod/downloads/FT11_High.mp4" /]

    and of the lambda talk:

    [video src="http://videoaz.microsoftpdc.com/vod/downloads/FT13_High.mp4" /]

  6. Hi Herb, great presentation, as usual!

    Just a couple of remarks.
    – You were cheating :) in your loop vs. algorithm example: without auto the for loop becomes times uglier because of the std::vector::const_iterator (not to mention typename if inside a template). I don’t think you’ll get this many raised hands if you showed how it really is in C++03. :)

    – Why didn’t you even mention Boost.Bind and Boost.Lambda (not mentioning giving examples)? People put a lot of efforts to make them convenient to use, and they did pretty good job so far, and still do – unlike boost, C++0x lambdas are monomorfic (you need to specify the type of the argument, so for example you can’t iterate over a tuple). I understand they will be polymorphic (template) in the next Standard, right?

    – There is another library that I’m sure you know of and it’s worth mentioning in this context: Adobe’s ASL. (For those who doesn’t know: http://stlab.adobe.com/group__algorithm.html) They provide standard algorithms wrapped with Boost.Range so you don’t need to write begin/end, just pass the container there. With ASL and Boost.Lambda your printing example looks like (omitting namespaces):
    for_each( strings, cout << _1 << '\n' );
    To me, it's still more concise than even with C++0x's lambdas (of course, range-based for loop will beat this as well).

    It doesn't mean that C++0x's lambdas are bad (automatic capturing is great), but in some contexts they still don't beat Boost/ASL solutions, so at least they deserve to be mentioned.

    P.S. [Offtopic] I'm happy we finally have nothrow!

  7. Herb, there is probably the only topic you’ve forgot to mention about.

    Let’s say we have a lambda function that is capturing outer variables by reference. And then we would like to post() that lambda to e.g. queue for later execution.

    Problem is that the context where the lambda was created gets destroyed before the lambda execution. What happens with captured references?

    In e.g. JavaScript this is made by creating a closure – frame stack of outer function is placed into the heap. But this works in managed environments. How C++ lambdas will deal with this problem?

  8. Those presentations sound very interesting, but the format does not work on my platform. I would be very happy if there was even a low quality audio version of this somewhere. Maybe some kind soul could hack me a version, by holding a mic to the speakers :) *only half kiddin*

  9. Paul, you can download the PPT deck from the master schedule at http://www.microsoftpdc.com

    Herb, I really enjoyed the talk, and would love to attend CBE. I just have to convince the people that control the $. I have a question about slide 48. You have “for(i = first; “, but first never appears anywhere else. I read over the function a few times, and it looks like the “i = first” should just be removed. Is that correct?

  10. I enjoyed your lambdas talk, especially substituting a for loop with std::algorithm examples. I looked at this issue back in pre lambda times and C++ syntax required was a total show stopper for me. With lambdas available, I will always consider using std::algorithm first as it clearly states intended semantics. Similar change of perspective occurred with Intel TBB. Using functors was a syntactic mess, having lambdas makes TBB more user friendly. Kudos for very convincing examples!

    I had a problem reading your slides though. The resolution used was terribly low. Using scalable vector format would be nice.

    Half seriously: I was a little bit disappointed that in the last example of const initialization you haven’t replaced for loop with for_each algorithm and lambda.

Comments are closed.