21

I'm pretty sure there is a special name for the 'spec' of a function/method. It's a word that refers to

  • how many arguments it takes
  • the order of arguments
  • which arguments are optional

Is there a name for that?

  • 2
    There are a few different kinds of "specs". You mention argument type, order, and necessity. Taken together with return type, that's called a type signature. Do you consider the name of the function part of the spec? How about it's namespace, like class, package, module, etc.? Is this spec for programmers or machines? See my answer. – kdbanman Sep 22 '15 at 17:44
  • 4
    I'm suprised this question has four close votes - it's a perfectly legitimate question IMHO, and quite answerable (in fact, it has been answered already). – sleske Sep 23 '15 at 12:47
  • @callum, please edit your question to be less ambiguous so it can be unflagged. Are you concerned with a specific language? A machine spec or a programmer spec? A spec for calling or a spec for implementation? – kdbanman Sep 24 '15 at 15:39
  • 1
    @kdbanman I was just trying to remember the word "signature". It's not ambiguous. It's not language-specific. It's been answered. It's OK. – callum Sep 24 '15 at 18:36
  • @callum, that's what I thought. Thank you for the reply. – kdbanman Sep 24 '15 at 19:02
47

Usually this is called a type signature.

A type signature includes the function's return type, the number of arguments, the types of arguments, or errors it may pass back.

  • 6
    Usually? I'm used to "prototype". Which apparently is the type signature plus the name - en.wikipedia.org/wiki/Function_prototype – ShadSterling Sep 22 '15 at 15:17
  • 14
    @Polyergic, signature is more general than prototype (and more correct in this case): a prototype declares a signature. Specifically, "prototype" implies declaration without implementation, as in a Java or C# method declaration in an interface, or a C/C++ function declaration in a header file (literally called a prototype). – kdbanman Sep 22 '15 at 16:28
  • 12
    Also, arity is a less commonly used term for just the number of arguments. – Sebi Sep 22 '15 at 18:12
  • ^ Ooh, that's an interesting one! I'll have to remember that for when I dabble in JS, since I only have argument counts to guide me, not types. – underscore_d Sep 23 '15 at 11:40
23

TL;DR You're probably talking about a function signature (or method signature), part of which is a type signature.

But really depends on what you consider a function "spec". I interpret it as "all the information required for a programmer to call a function". This includes the function name, the parameter type, order, and necessity, probably the return type, and probably even that function's namespace.

But whether or not all those things are required (or even well defined) depends on the language/environment you're using. Also, if you change the definition to "all the information required for a machine to call a function", the spec is likely different1.

Strictly speaking, a function (or method) signature is not a consistent term,2, 3 even within the same language.4, 5, 6, 7 But it's almost certainly the word you're looking for, because it'll be understood by almost any programmer.


  1. C++ Spec Draft n337, definition 1.3.17, signature does not include return type, because it is not necessary to resolve the function.

  1. "signature" does not include namespace information
  2. "signature" includes exceptions and modifiers like public, static, etc

  1. C++ "signatures" do not include return type
  2. C++ "signatures" do include return type.
  3. C++ "signatures" do not include return type, unless the function is the specialization of a template.
  4. C++ "signatures" include namespace (scope) information and "other miscellaneous" stuff...

  • I would include also at least what the method does when talking about its "spec". Depending on the focus of the day I may or may not include whatever additional information is necessary to implement the method. – a CVn Sep 22 '15 at 20:28
  • @MichaelKjörling, those are valid concerns, but those are pretty significant digressions from what most programmers would call a "signature". What the function does should be included in the function name, so it is indirectly part of the signature. Regardless, I don't think function behavior or implementation are what the asker intended. I will edit accordingly if it turns out he did. – kdbanman Sep 22 '15 at 20:44
  • Signature yes, "spec" no. (FWIW, I think your answer is quite good, and well cited.) – a CVn Sep 22 '15 at 20:45
  • Thanks for the feedback. I don't think the answer is quite so clear cut as "'spec' no". It depends on what is meant by spec - one could certainly come up with a reasonable definition of spec that includes function behavior and implementation guidelines. You're welcome to do that in your own answer. But like I said, I don't think those are what the asker intended. – kdbanman Sep 22 '15 at 20:51
  • 1
    Upvoted because, though not language-agnostic, the C++ examples are (A) relevant to me and (B) illustrative of the confusion that so often surrounds human terminology – underscore_d Sep 23 '15 at 11:43
0

I believe the term is "contract". It defines the interface and what's expected of caller and callee; however it also covers things like allowed values of parameters which is not something many languages allow to be defined by the function or class definition, so the term "contract" might be broader in meaning than what you meant. I have seen it in several object oriented and Java specific programming books. I'm not sure if it's Java specific but I don't see why would it need to be. Signature is the other commonly used term but I grew to like "contract".

  • This is the best answer if question is really the name for "spec" of the function/method. The signature itself doesn't tell anything about what the method actually does, allowed range of parameters, non-functionnal contraints and so on... – ch7kor Sep 25 '15 at 16:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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