Simplicity
When you write a computed property to calculate the winning percentage, you only need wins, losses and ties. When you write code to print the full name of a person, you only need a first and a last name.
If you were to write code to do these tasks inside of a more complex object, it could be easy to make the mistake of coupling it with unrelated code:
var winningPercentage: Double {
var percent = Double(wins) / (Double(wins) + Double(losses))
// Oh no! Not relevant! self.above500 = percent > 0.5
return percent
}
That above500 property might be needed for some reason in cricket, but not in hockey. However, that makes the function very specific to a particular sport.
You saw how simple the protocol extension version of this function was: it handled one calculation and that was it. Having simple default implementations that can be used throughout your types keeps the common code in one place.
You don’t need to know that the type adopting a protocol is a HockeyRecord, or a
StudentAthlete, or a class, struct or enum. Because the code inside your protocol extension operates only on the protocol itself, any type that conforms to that protocol will also conform to your code.
As you’ll discover again and again in your coding life, simpler code means less buggy code. :]