Wednesday, November 24, 2010

RE: C++0x lambda syntax

Bram Moolenaar wrote:
>
> Andrew Venikov wrote:
>
> > in c++0x it will be possible to use lambda functions.
> >
> > So, for example, this:
> >
> > [](int n) { return n+ 1; }
> >
> > Will become valid c++.
> >
> > Unfortunately it breaks current C++ highlighting.
> > After a line like the one above, all curly brackets will be
> highlighted by VIM as "unmatched", making reading the code really hard.
> >
> > Is there a quick way to fix that?
>
> You can vote for the C++ standard to not add things like this to make
> the language even more cryptic.


Funny you should mention it, but the whole reason for the lambda
functions (and not just in C++) is to make code more readable.
Oftentimes when you need to pass a function or a function-object to
a generic algorithm, this function would consist of only a short expression.
Currently, you're forced to define this expression else-where, where
it's out of context. The lambda functions allow you to specify the logic
in-line so that the whole algorithm would be in one place.

I understand the knee-jerk reaction to this new feature, but the C++
community has been anxiously waiting for lambdas (closures) for a
long time for a reason. The other languages (JavaScript, Python, Ruby,
Haskell, heck even Perl has it) have had them for a long time.
Lisp had them since, oh 1965?


>
> Well, perhaps that's not a quick way, but it will make programmers who
> try to decipher C++ programs a lot more sane.

I guess C++ does have a bad rep in this area. But the reason for that is
that there was a wide-spread misconception that C++ is just C with classes.
And a lot of C programmers (good and bad) tried to write C++ code with C
mindset. You just can't do that.

But I promise you that things will get much better, as C++ community has
evolved since then and proper C++ techniques are much more wide-spread now.
Reading a properly written C++ code is like watching a beautify painting.
It's a work of art.

But the bottom line is:

PLEASE, don't make me chose between my favorite language and my favorite editor.


Thanks,
Andy.

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

No comments:

Post a Comment