Allow function definitions to omit parentheses if no parameters

Arguably though, these two things aren't what should be made consistent. Properties are already consistent within themselves between how they are declared and how they are called (without parentheses). Likewise, with the exception of the trailing closure case, parameterless functions are already consistent within themselves between how they are declared and how they are called (with empty parentheses).

Removing the empty parentheses from a function declaration makes the language less consistent, not more, unless you propose dropping the empty parentheses from calls as well. Some languages do in fact do that (Ruby comes to mind), but that syntax is already used in Swift to produce a reference to a function. This ambiguity could partially be resolved using inference—the type of a function cannot be the same as its own return type, so the expression f(someFunction) could be resolved to either the result of someFunction or the reference to someFunction based on the type of f's argument—but even that falls apart if f's argument is Any, and that would be introducing a source-breaking ambiguity.

15 Likes