Annotation of functions
Tony
tonytdominguez at aol.com
Thu Feb 22 07:41:06 UTC 2018
On Tuesday, 20 February 2018 at 12:15:57 UTC, psychoticRabbit
wrote:
> I've noticed that Go and Rust annotate functions.
>
> func (in go)
> fn (in rust)
>
> I was kind of wondering why they made that choice, given
> compilers in many languages do not.
On Tuesday, 20 February 2018 at 12:15:57 UTC, psychoticRabbit
wrote:
> I've noticed that Go and Rust annotate functions.
>
> func (in go)
> fn (in rust)
>
> I was kind of wondering why they made that choice, given
> compilers in many languages do not.
I think it is common to have a keyword used in function
definition - outside the
C-family. The Pascal family has keywords for function and
procedure declaration, as does Fortran. It looks like Cobol uses
the "function" keyword for when you call a function and
"function-id" for when you define it. Perl, Python and Ruby all
have a keyword for function definition.
>
> Would this be a useful feature in D?
>
> Everything else seems to have an annotation (e.g structs,
> classes.) So why not functions?
>
> What are people's thoughts about it?
I think keywords for functions may be to avoid or minimize the
difficulty C and C++ have with declaring (and deciphering the
declarations of) function pointers. Seems it also would have
prevented years of C++ having "the most vexing parse", where a
class instantiation can be confused with a function declaration.
More information about the Digitalmars-d
mailing list