In D I can create templates like this:

template Foo(A) {
    A add(A a, A b) { ... }
    A multiply(A a, A b) { ... }
    A concatenate(A a, A b) { ... }

What should a template be named ideally? What conventions exist out there? I'm looking to something similar like 'function names must always start with a verb'.

  • 1
    The way to decide on a class name should be the same whether the class is templated or not. So use your current pattern for class naming to name this template class also. For example, the template "List" interface in Java isn't named anything more unique than other non-template standard Java classes. I.e. It isn't named "ListForType" or something. Name it in a way to describe the concept you are modeling. – jordan May 18 '14 at 21:21
  • @jordan How would I name Foo in the OP for example? – Jeroen May 18 '14 at 21:23
  • I don't exactly know what you are trying to represent. A number or something? Try to think of what it is you are modeling and name it accordingly. – jordan May 18 '14 at 21:25
  • @jordan It's modeling a set of functions which work for different types. :s – Jeroen May 18 '14 at 21:26
  • 1
    I know nothing about "D" language, but should "concatenate" really be there? It seems like something like "ArithmeticCalculator" or something makes sense without it. It seems odd to add "concatenate" in with these arithmetic functions. – jordan May 18 '14 at 21:41

In your case, I would use a name that refers to the collection of functions that you have. For example:

template Operations(A) { ...

If you hadn't mentioned concatenate, then I would have suggested ArithmeticOperations for example.

  • "Operations" is very likely too broad, since I can put anything in it and it would still make sense, for example "deleteUser". I agree that the OP may need to decide whether the given set of functions really make sense together or not. If they do make sense, then more context is needed in order to answer the question, since some context is missing from the suggested class name to fully describe how it will be used. – jordan May 18 '14 at 21:51
  • Indeed, if it's a collections of functions with nothing in common then I would question whether it's necessary to collect them together at all. – Greg Hewgill May 18 '14 at 21:52
  • Well they have something in common. They use the same type, and will be used together a lot. – Jeroen May 19 '14 at 6:02

Not the answer you're looking for? Browse other questions tagged or ask your own question.