Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider function return syntax -> is not necessary #1600

Closed
pache-Ak opened this issue Jul 23, 2022 · 2 comments
Closed

Consider function return syntax -> is not necessary #1600

pache-Ak opened this issue Jul 23, 2022 · 2 comments

Comments

@pache-Ak
Copy link

The identifier -> used to indicate that the return type follows.

But even ignore it, we and compiler also can know ) follows is return type.

The identifier -> has no meaning, it is only a convention said that follows return type. So we also can convention (args) follows return type, -> increases the burden on us and the compiler.

Let's consider function syntax as this:

func name(args) return-type { }

Now, let's consider the case where the exception description is included.

I suggestion the syntax like this:

func name(args) return-type throw exception-type { }

As you see, -> is not necessary, we don't need it to indicate that the return type follows. As long as we agree that the parameter is followed by the return type.

In the long-term generic practice of C++, the post-return type is good, not only simplifies the writing, but also in the template function the return type often depends on the parameter type. So, carbon uses this syntax I feel very happy. If can remove -> is better.

@chandlerc
Copy link
Contributor

The function declaration syntax was considered and decided in #438.

There are of course a very wide variety of syntaxes that we might consider and that would be workable in theory.

However, beyond any aesthetic desire to have an unambiguous marker that a return type follows the parameter list, there is the simple fact that C++ uses this exact syntax for its trailing return types, as do both Swift and Rust. I think the consistency alone makes an extremely strong argument for the syntax we have.

Unless there is a significant signal of new interest from the community in revisiting this (can use reaction emojis for example), or a specific articulated problem with this syntax (as opposed to feeling like it is unnecessary), I don't think this is something we should revisit at this point. Closing as "not planned", but happy to reopen if anyone thinks there is important signal that the leads should reconsider this.

@chandlerc chandlerc closed this as not planned Won't fix, can't repro, duplicate, stale Jul 23, 2022
@EchoPouet
Copy link

The related discussion -> #1520

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants