This is an old revision of the document!
Table of Contents
Uniformity Principle (UP)
Variants and Alternative Names
Solve similar problems the same way.
- Use the same naming scheme everywhere
- Use the same techniques and mechanisms everywhere
- In similar methods use the same order of parameters
See section contrary principles.
Relations to Other Principles
- Easy to Use and Hard to Misuse (EUHM): Uniform interfaces are easier to use than others.
Note that UP can be contrary to virtually every other principle as it demands neglecting other principles in favor of uniformity.
- Keep It Simple Stupid (KISS): Sometimes UP demands more complex solutions because they are already applied elsewhere and for the sake of uniformity shall also be applied in simpler contexts where they would not be necessary.
- Model Principle (MP): UP may demand adhering to a certain naming scheme, which may not be best with respect to MP. See example 1: naming schemes.
- Principle of Least Surprise (PLS): When applying UP, PLS should also be considered for naming modules. See example 1: naming schemes.
Example 1: Naming Schemes
A typical example of the application of UP is the naming of method identifiers for common container classes like stacks or queues. This also shows that there are several ways to apply this principle.
Stacks typically have the methods
peek (sometimes also called
push puts an item onto the stack,
pop removes the top most item and
peek retrieves the value of the top most item without removing it from the stack. This is how the common stack model describes this data structure (see MP). Applying UP to this naming decision means that the methods should be named precisely as they are named everywhere else also. So a developer knowing the model or other implementations of the model will immediately know how to use this module as well. In this case MP and UP demand the same thing. PLS is satisfied here as well as a developer knowing stacks will expect exactly that.
Queues on the other hand typically have the methods
first or the like). MP would demand naming the operations of a
Queue module exactly that way. But there are several ways Up can be applied here. The one way is to apply the principle just like above. Resulting in methods
dequeue. This is how it is done in .NET1). The other way is to consider the method identifiers of the
Stack module. A possible application of UP could be to demand naming the queue methods just like the stack methods, meaning also
peek. This is the naming scheme which was chosen in the Delphi RTL2). Here MP and UP are contrary. A further downside of this approach is that
push methods might be surprising for a queue class. So PLS would oppose this solution.
A third possibility is to find a common abstraction and to apply a very general naming scheme to all descendant classes (stack classes, queue classes and others). This is the way it is done in Eiffel3). Here there the method names are
item regardless of the concrete data structure. This is contrary to MP but creates a uniform naming scheme throughout the API. So there is less uniformity across APIs but stronger uniformity within the API. MP and UP are here contrary too. For PLS this means that a developer who is used to this philosophy is never surprised by having these methods. But developers new to it might be nevertheless.