Do you use nouns for class names that represent called objects?

A more general question is suggested here . Consider this as an extension to this.

I understand that classes represent the type of objects, and we must use nouns as their names. But there are function objects supported in many languages ​​that act more as functions than objects. Should I call these classes also nouns, or are verbs approved in this case. doSomething(), semantically, makes more sense than Something().

Update / Conclusion

The two top voices I received share a mixed opinion:

Attila

However, in the case of functors, they represent an β€œaction,” so assigning them a verb (or some combination of nouns-verbs) is more appropriate - just as you would call a function based on what it does.

rook

An instance of a functor, on the other hand, is actually a function, and might be better named accordingly. Following Jim's suggestion above,SomethingDoer doSomething; doSomething();

Both of them, having passed some code, seem to be common practice. The GNU implementation stl I found the classes such as negate, plus, minus(BITS / stl_function.h), etc. And variate_generator, mersenne_twister(tr1 / random.h). Similarly, in the boost I found the classes such as base_visitor, predecessor_recorder(graph / visitors.hpp), as well as inverse, inplace_erase(icl / functors.hpp)

+5
source share
4

(, , ) "", . "", ( -) - , , , .

, (, ..) , , /.

( , "" ) . ( , "" ) , , , "" ( ).

, , , , , (, ++). , (.. , operator(), command.do()), / , .

+4

- , (, ), . , , , , . , SomethingDoer doSomething; doSomething();

, , , , ... Filter Show . .

+3

Function, Callback, Action, Command .., SortFunction, SearchAction, ExecuteCommand Sort, Search, Execute, .

+2
source

I think there are two ways to see this:

1) A class that can be reasonably called so that it can be called as a functor directly during construction:

Doer()(); // constructed and invoked in one shot, compiler could optimize

2) An instance in cases where we want the functor to be called several times in an object-object without a name, or, perhaps, for stylistic reasons when syntax C # 1 is not preferable.

Doer _do;
_do(); // operator () invocation after construction

I like the @Rook sentence above to designate a class with words that have the same form of a verb and a noun, such as Searchor Filter.

+1
source

All Articles