r/cpp • u/jackie_kay • Jan 26 '17
Stop calling "Function Objects" "Functors"
http://jackieokay.com/2017/01/26/functors.html8
u/Gotebe Jan 27 '17
yes, ok, but different surely different domain can use one word, each domain with their own meaning?
To form a really bad analogy, should we stop using the word "container" since it means something else in... waste management?
3
u/enobayram Jan 29 '17
Except the domains aren't that different. With the rising popularity of functional programming (and the newer C++ features that support it), the mathematical concept of a functor isn't that far from practical C++.
6
u/Yuushi Jan 27 '17
A number of languages have "functors" (all with different meanings). As much as I agree that it's an abuse of terminology, It's probably a little late to put the genie back in the bottle.
5
u/TartanLlama Microsoft C++ Developer Advocate Jan 27 '17
I really enjoyed this article, and I think the distinction is useful. "Function object" is (AFAIK) a term which grew up in the programming world and clearly communicates its meaning. "Functor" is a term which certain programming communities have borrowed from category theory and twisted into something related, but not the same.
If you talk to someone who is unfamiliar with the terms about "function objects", they'll probably be able to intuit what you're talking about pretty easily. "Functor" is less obvious, and downright confusing if you come from a mathematics background. Why not use the clear, non-overloaded term? In addition to the clarity, it'd free up the other for discussing functional programming and category theory and how they can be applied to multi-paradigm languages like C++.
4
u/doom_Oo7 Jan 27 '17
I'm pretty sure that a majority of programmers alive today were first introduced to the word "functor" through the "function object" meaning. This ship has sailed a loooong time ago. https://en.wikipedia.org/wiki/Functor_(disambiguation)
2
u/NottingHillNapolean Jan 30 '17
Funct that. If everybody in a group uses a word to mean the same thing, that's what it means. The fact that it means something else in another context to another group is irrelevant.
38
u/STL MSVC STL Dev Jan 26 '17
Actually, that isn't the Standard's formal definition, where a function object is anything that can be called with parentheses. This includes function pointers, classes with overloaded operator(), lambdas (special case of the previous one), and classes that are implicitly convertible to function pointers.
Granted, the latter basically never comes up except in <functional> unit tests.
On the other hand, "lambda function" drives me nuts. Lambdas aren't functions (or std::functions), but such terminology encourages confusion.
No, that's math. Programming is different. Mathematicians consider a "vector" to be different from what we consider it to be.