Maintainers are burdened with understanding, documenting, and testing both classes when only one is really needed. Code must handle the case when hibernate is true, even though all callers pass false, as well as the case whenSleepreturns an error, even though that never happens. This results in unnecessary code that never executes.Eliminating those smells simplifies the code:
class Human { ...
void Sleep() { age += kSevenHours; }
};
Here are some other YAGNI smells:
Code that has never been executed other than by tests (a.k.a. code that is dead on arrival)
Classes designed to be subclassed (have virtual methods and/or protected members) that are not actually subclassed
Public or protected methods or fields that could be private
Parameters, variables, or flags that always have the same value
Thankfully, YAGNI smells, and code smells in general, are often easy to spot by looking for simple patterns and are easy to eliminate using simple refactorings.
Are you thinking of adding code that won't be used today? Trust me, you aren't gonna need it!