There is a more generic question asked here. Consider this as an extension to that.
I understand that classes represent type of objects and we should use nouns as their names. But there are function objects supported in many language that acts more like functions than objects. Should I name those classes also as nouns, or verbs are ok in that case. doSomething()
, semantically, makes more sense than Something()
.
Update / Conclusion
The two top voted answers I got on this shares a mixed opinion:
Attila
In the case of functors, however, they represent "action", so naming them with a verb (or some sort of noun-verb combination) is more appropriate -- just like you would name a function based on what it is doing.
Rook
The instance of a functor on the other hand is effectively a function, and would perhaps be better named accordingly. Following Jim's suggestion above,
SomethingDoer doSomething; doSomething();
Both of them, after going through some code, seems to be the common practice. In GNU implementation of stl I found classes like negate
, plus
, minus
(bits/stl_function.h) etc. And variate_generator
, mersenne_twister
(tr1/random.h). Similarly in boost I found classes like base_visitor
, predecessor_recorder
(graph/visitors.hpp) as well as inverse
, inplace_erase
(icl/functors.hpp)