Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

About lambda syntax

29 views
Skip to first unread message

Cholo Lennon

unread,
Nov 7, 2017, 2:31:18 PM11/7/17
to
Hi all,

Silly question: Why 'return' must always be used in lambda's bodies? It
would be nice that it can be be omitted like in Java (if you have only
one sentence, braces and trailing semicolon can also be omitted).

For the sake of comparing both languages, forget the lambda type:

C++: foo = [](auto x) { return x + 1; };
Java: foo = x -> x + 1;


--
Cholo Lennon
Bs.As.
ARG

Öö Tiib

unread,
Nov 7, 2017, 3:57:36 PM11/7/17
to
It is just a question of syntax sugar. C++ designers have
typically extended the verbosity of C. BTW, Java has also taken
most of the verbose features of C (like C++):

* Why it was made that statements must be separated with semicolon
even when those are not on same line?
* Why there are mandatory parentheses around arguments of if, for,
while and switch?
* Why one needs to write "break" for each case of switch instead
of having keyword for (ultra rarely needed) fall-through?
* and so on ... same for C++ and Java

What I think (YMMV) that it does not really matter much.
We can gnaw out few characters here or there but what is
the gain? It is so in C and it works so why to change it?
The result may be even confuses someone. Some people even add
redundant characters voluntarily. They put parentheses around
return value or argument of sizeof or argument of throw.
They add redundant "this->" to member accesses in member
functions. They feel that more characters there helps them to
read the code.

The actual problems to solve are always likely elsewhere.
0 new messages