Code Smell 93 — Send me Anything
Magic functions that can receive a lot of different (and not polymorphic arguments)

TL;DR: Create a clear contract. Expect just one protocol.
Problems
- Fail Fast principle violation
- Error prone
- Readability
- If polluting
- Nulls
- Bad Cohesion
Solutions
1. Take just one “kind” of input
2. Arguments should adhere to a single protocol.
Sample Code
Wrong
Right
Detection
We can detect this kind of methods when they do different things, asking for the argument kind.
Tags
- If Polluter
Conclusion
Magic castings and flexibility have a price. They put the rubbish under the rug and violate fail fast principle.
Relations
Referential transparency is a very desirable property: it implies that functions consistently yield the same results given the same input, irrespective of where and when they are invoked.
Edward Garson
This article is part of the CodeSmell Series.