Date: Sat, 2 Apr 2022 10:59:30 -0400
This is the wrong place for talking about language changes. Those are
discussed in the std-proposal ML.
In any case, there are several problems.
The first problem is that it looks really *weird*. A variable is
declared outside of the function scope, and is returned from outside
of it, but all modifications are within it. That just looks strange.
To remember what the function is returning, you have to go back to the
function header. Also, functions that return values with no return
statement are broken, and programmers should be suspicious of them.
But your proposal effectively "fixes" such code, making it much easier
to accidentally write a function that doesn't return correctly.
Second, if you need to return from multiple places, you have to go
back to the old pattern. If people start liking the new pattern,
people will be encouraged to do things like this to avoid explicit
`return` statements:
```
auto func() int ret{}
{
ret += 5;
if(something)
goto leave;
ret += 10;
leave:
}
```
That's not good.
Next, it doesn't work with coroutines and `co_return`.
Let's not make walking off the end of a function implicitly return things.
discussed in the std-proposal ML.
In any case, there are several problems.
The first problem is that it looks really *weird*. A variable is
declared outside of the function scope, and is returned from outside
of it, but all modifications are within it. That just looks strange.
To remember what the function is returning, you have to go back to the
function header. Also, functions that return values with no return
statement are broken, and programmers should be suspicious of them.
But your proposal effectively "fixes" such code, making it much easier
to accidentally write a function that doesn't return correctly.
Second, if you need to return from multiple places, you have to go
back to the old pattern. If people start liking the new pattern,
people will be encouraged to do things like this to avoid explicit
`return` statements:
```
auto func() int ret{}
{
ret += 5;
if(something)
goto leave;
ret += 10;
leave:
}
```
That's not good.
Next, it doesn't work with coroutines and `co_return`.
Let's not make walking off the end of a function implicitly return things.
Received on 2022-04-02 14:59:44