fn vs fun vs func vs function

C doesn't use nor require any style at at all. It is entirely up to the programmer. There is no requirement to indent everything inside a function either.

Splitting a function declaration across two lines line that is rare in C. Unless a language enforces a strict layout, users will employ whatever style they like, and I've seen some hairy code where you have no idea what you're looking at.

My own language, without types, allows you to define functions, procs, imports, libraries, variables, named constants, macros, types, records, enums and tables.

All of those start with a keyword, followed by the name being defined. It would be odd to have an exception for functions, probably the most important construct of the lot!

Besides, in such a language, wouldn't you have assignments at module-level too, and function calls (most script languages [not mine] are like this, where you have code outside a function):

subtract = 42
multiply(a,b):
   ...
printx(x):
   ...
printx(multipy(4,5))

So multiply is a function, but subtract isn't? Do you now have to search for ^multiply(, and hope people aren't in the habit of writing 'multiple ('? Plus in the case of 'printx', both definition and call will match ^printx'. Maybe the definition will always be the first match? It's getting a little precarious.

People may want to write a quick editor macro that steps to the next or last function; what would that macro look like, what pattern is it looking for? Can other things appear at the start of a line?

I use a 'function' prefix, yet even with that it is not so simple (eg. sometimes there are extra attributes).

With C, you pretty much need half of a C compiler to do that, and it still may not work 100% (because it depends on exernal macros), and will have the additional problem that a function forward declaration and its definition start exactly the same. (However C is a crazy language anyway - you can have 50 identical declarations - so is a terrible model for a new language.)

/r/ProgrammingLanguages Thread Parent