Skip to content

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

Closed
@zesterer

Description

@zesterer

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.");
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    proposalThis issue suggests modifications. If it also has the "accepted" label then it is planned.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions