Skip to content

Functions should default to returning void if the return type is omitted #737

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

Closed
zesterer opened this issue Feb 2, 2018 · 2 comments
Closed
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Milestone

Comments

@zesterer
Copy link

zesterer commented Feb 2, 2018

The fact that the function is not intended to return anything is immediately obvious to both the programmer and anybody reading the code. Omitting the return type is a nice shortcut that doesn't increase the complexity of the language and doesn't require huge changes to the compiler internals. It has the advantage of improving code readability by getting rid of things the developer needs to read that do not aid in understanding the semantic meaning of the code.

Example return-less (distinct from noreturn, of course) function definition:

fn outputSomething(file: std.File) {
    file.write("Something") catch {};
}

As an optional consideration, perhaps it may be possible to omit the call brackets for functions with no arguments too? I'm unsure whether this creates parser ambiguities, however. Example:

fn doPanic {
    @panic("This is a panic.");
}
@zesterer zesterer changed the title Functions without an explicit return type should default to returning void Functions should default to returning void if the return type is omitted Feb 2, 2018
@Hejsil
Copy link
Contributor

Hejsil commented Feb 2, 2018

Well, the optional void was just removed.
#720

@andrewrk andrewrk added this to the 0.3.0 milestone Feb 3, 2018
@andrewrk andrewrk added the proposal This issue suggests modifications. If it also has the "accepted" label then it is planned. label Feb 3, 2018
@andrewrk andrewrk modified the milestones: 0.3.0, 0.4.0 Feb 28, 2018
@andrewrk andrewrk modified the milestones: 0.4.0, 0.5.0 Nov 21, 2018
@wilsonk
Copy link
Contributor

wilsonk commented Mar 6, 2019

@andrewrk Should this be closed since the optional return was removed...as per Hejsil above? Also, the grammar doesn't allow an optional return expr at this point.

@zesterer zesterer closed this as completed Mar 7, 2019
@andrewrk andrewrk modified the milestones: 0.5.0, 0.4.0 Apr 8, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
proposal This issue suggests modifications. If it also has the "accepted" label then it is planned.
Projects
None yet
Development

No branches or pull requests

4 participants