concept signature in category c#

appears as: signature, signature, The signature, signatures, The signature, signatures
Functional Programming in C#: How to write better C# code

This is an excerpt from Manning's book Functional Programming in C#: How to write better C# code.

The types for the domain and codomain constitute a function’s interface, also called its type, or signature. You can think of this as a contract: a function signature declares that, given an element from the domain, it will yield an element from the codomain.[3] This may sound pretty obvious, but you’ll see in chapter 3 that in reality, violations of the signature contract abound.

Figure 3.1. An honest function does exactly what the signature says.

Remember, a signature is a contract. The signature int → Risk says “Give me an int (any of the 232 possible values for int) and I’ll return a Risk.” But the implementation doesn’t abide by its signature, throwing an ArgumentException for what it considers invalid input. (See figure 3.2.)

Figure 3.2. A dishonest function can have an outcome that isn’t accounted for in the signature.

These last two signatures are so expressive that you can make a good guess at the implementation, which is, of course, a desirable trait. When you write an API, you want it to be clear, and if the signature goes hand in hand with good naming in expressing the intent of the function, all the better.