Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

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'.

share|improve this question

closed as primarily opinion-based by gbjbaanb, Dynamic, MichaelT, gnat, Kilian Foth May 19 at 7:28

Many good questions generate some degree of opinion based on expert experience, but answers to this question will tend to be almost entirely based on opinions, rather than facts, references, or specific expertise.If this question can be reworded to fit the rules in the help center, please edit the question.

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 at 21:21
    
@jordan How would I name Foo in the OP for example? –  Jeroen Bollen May 18 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 at 21:25
    
@jordan It's modeling a set of functions which work for different types. :s –  Jeroen Bollen May 18 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 at 21:41

1 Answer 1

up vote 1 down vote accepted

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.

share|improve this answer
    
"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 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 at 21:52
    
Well they have something in common. They use the same type, and will be used together a lot. –  Jeroen Bollen May 19 at 6:02

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