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