RFC: should we spell lambdas like functions?

I argue we should spell C++ lambdas (and other function-like variables) like functions, not like variables.

  • Use verbs, not nouns.

  • Use lowerCamelCase.

Here’s a patch that implements the change to the coding standards:
https://reviews.llvm.org/D48991

Thoughts?

I argue we should spell C++ lambdas (and other function-like variables) like functions, not like variables.

  • Use verbs, not nouns.

I think I agree with this.

  • Use lowerCamelCase.

In lld we use UpperCamelCase, as they are technically not function names but variable names. Using lowerCamelCase for function pointers feels really weird to me, as they are really variables than functions to me.

I also agree that this is weird either way because they are variables when declared and passed around and functions when invoked.

A potential solution would be to adopt the style that large parts of the Clang frontend (informally) uses, and spell variables as lowerCamelCase, too.

-- adrian

How is this different to function pointers in traditional C?

Makes sense to me, I think that all callable values could be named in the same approach, including function references and std::functions? Function pointers are not callable (you need to dereference them) so it is arguable that they should be capitalized. It would be nice to include some rationale of why you’re picking one thing or another in coding standard paragraph.

-Chris

Err, yeah, of course function pointers are callable. I meant to say C++ member pointers :slight_smile:

-Chris

It’s not different. The patch proposes to spell C++ lambdas and other function-like variables like functions. Essentially, anything that’s callable.

That seems a bit more awkward/not-clearly-good to me (though I do appreciate that the standard C++ naming convention, for all that it doesn’t really differentiate between anything (except macros) by having everything lower_case, does use the same convention between variables and functions so you don’t get that disconnect) - ending up with function-named variables that don’t behave like functions (get used in assignments, have member functions called on them, compared to nullptr (weak functions notwithstanding), etc).

Seems more like a narrow kind of hungarian notation to me - to designate that this variable can be called. Which doesn’t seem important enough to callout with a separate naming convention.

But I’m not too fussed about it if others feel strongly.

  • Dave

I wrote that I prefer CamelCase over camelCase for callable objects, but I don’t have a strong opinion. If the majority prefers camelCase, I’m happy to update the existing lld’s code to conform to the new coding style.

I argue we should spell C++ lambdas (and other function-like variables) like functions, not like variables.

  • Use verbs, not nouns.

Totally agree.

  • Use lowerCamelCase.

Really disagree.

I don’t like having two different case conventions for variables. They’re all variables, and I think they should be named using the same convention.

Really agree.

What about situations where a function is a parameter:
   template <typename Func> void fred(int Arg, Func Do) {...}
If we use lowercase names for the function parameters it is going to look awful.

-Krzysztof

  • Use lowerCamelCase.

FWIW I would prefer to name them like variables too. Since being callable is their raison d’etre I’m unlikely to forget to use them that way. On the other hand, naming them like variables is a subtle but helpful reminder that they can be assigned to, moved from, may be default constructed (and so in a not-callable state), etc.

Cheers,
Lang.