Special Cases Are a Code Smell

LA Parking Sign

A Warning Sign

Los Angeles is famous for its complicated parking signs:

They’re totems of rules and exceptions, and exceptions to the exceptions. Often, when we code, we forget a lesson that’s obvious in these preposterous signs: Humans understand simple, consistent rules, but fail on
special cases.

A Trivial Example

Say you’re given an array of integers, and you want to calculate the sum of each element’s neighbors. Try it: