News for hackers. Stuff that matters.
Re:Lisp for C++ programmers by rayiner on Monday October 28, 2013 @08:56AM (#6626584)
It seems as if every new iteration of C++ proves Greenspun more and more correct. The standards committee has been trying very hard to push templates as an "ad hoc, informally-specified, bug-ridden, slow implementation" of macros.

As for Lisp syntax being ugly, I beg to differ. (Common) Lisp syntax is somewhat arcane, with terminology and abbreviations that aren't common these days, but it reads pretty smoothly.

You know what's ugly? C++ lambda syntax:

    [=]() mutable throw() -> int
At some point C++ started following Perl down the road of using as many symbols above the number keys as possible. That's ugly.
Re:Lisp for C++ programmers by detrino on Monday October 28, 2013 @09:48AM (#6626861)
You are being intentionally dishonest by using the most verbose lambda expression you can think of. It would be very unusual to write something like that. You even managed to include one of the rare deprecated language features.
Re:Lisp for C++ programmers by rayiner on Monday October 28, 2013 @09:54AM (#6626895)
The example is from the first hit for a Google search for "C++ lambda syntax" (an MSDN article). In any case, unusual language features still are part of the syntax. They must be parsed and they must be understood by programmers in case they come across them. The ugly parts of a language don't go away just because you don't use them that often.

Also, I'm not sure what you're objecting to. The throw clause? The ugly part here is the overloading of the brackets and equal sign to specify the capture list.

Re:Lisp for C++ programmers by detrino on Monday October 28, 2013 @11:00AM (#6627312)
"[=]" Capture all variables by value, fair enough.

"mutable" Don't capture them const, this is very rare.

"throw()" Promise not to throw an exception, this is very rare for a lambda, and also deprecated in favor of noexcept.

"-> int" Explicit return type, usually not needed, and nearly never needed in C++14.

I was objecting to a contrived example used out of context to make C++'s syntax look worse than it is.

Re:Lisp for C++ programmers by rayiner on Monday October 28, 2013 @11:42AM (#6627584)
I'm not trying to make C++'s syntax "look bad." The standard itself makes C++'s syntax look bad. All those features, except maybe the empty throw clause, are basic things someone needs to know to use lambdas properly and to read code that uses lambdas. We're not talking about deprecated, never-used, features like "export" here.

I don't understand your line of reasoning here. Is syntax not ugly if you usually don't use the ugly parts? I think everyone would agree that the parser ambiguity that used to exist between "vector<vector<int>>" and the right-shift operator ">>" was ugliness in the syntax. Is it a defense that you don't usually instantiate a template with an instantiation of another template?

Re:Lisp for C++ programmers by greyfade on Monday October 28, 2013 @01:38PM (#6628406)
None of these features, except the capture clause, are things that anyone has to learn to use C++ lambdas; they should know these other features anyway, from other parts of the language.

The late return type syntax (`-> type`) works with nearly all functions (`auto fn(foo) -> bar { ... }`), the `throw()` (now `noexcept`) specification has been used for long time, and `mutable` is a well-known syntax for potentially const objects; so the lambda syntax is, or at least should be, unsurprising.

To say it's ugly is not saying much. We all know C++ is ugly. This is a given. But singling out lambda syntax, which is comparatively easy to grasp and largely consistent with the language, doesn't really make a case.

Re:Lisp for C++ programmers by vinkelhake on Monday October 28, 2013 @10:50AM (#6627250)
There is, of course, a reason why symbols are used (and keywords are re-used) instead introducing new keywords: backwards compatibility. Whenever a new keyword is introduced, there's a very real chance of breaking old programs and that is considered bad.

What are the bugs you speak of?

Re:Lisp for C++ programmers by rayiner on Monday October 28, 2013 @11:34AM (#6627530)
> What are the bugs you speak of?

It's part of the quote. I'm not sure if there are bugs with respect to lambdas, but historically, C++ implementations have been pretty buggy. Even with all the resources that go into C++ implementations, it took forever to get ones that correctly supported C++98.

Re:Lisp for C++ programmers by greyfade on Monday October 28, 2013 @01:39PM (#6628415)
That has changed a great deal over the last 10 years. Modern C++ implementations are quite stable, and the push for and uptake of C++11 support has been quite rapid. Most of the new standard was implemented before the final draft was even published.
Re:Lisp for C++ programmers by 10098 on Monday October 28, 2013 @01:31PM (#6628340)
Most of the time your lambda looks like

[](arg1, arg2){ short line of code};

which isn't that verbose at all.