Use the Principle of Least Surprise
Design code and interfaces so that they behave in ways that are intuitive and predictable for users and developers alike. When people interact with your software, they should feel it behaves as expected without needing to double-check or mentally adjust to unexpected quirks. Favoring immutability and more explicit APIs can help reduce surprise for users of functions you write.
Examples
- You’re designing a 'delete' button for your app. To avoid surprising users, you add a confirmation dialog to prevent accidental deletions and use standard red color to signal caution, aligning with user expectations. But you also remember that relying on color is not enough (many are color blind or even completely blind), so you make sure you add descriptive text as well.
- When creating an API, you ensure that it uses common HTTP status codes like 200 for success, 404 for not found, and 500 for server errors. This makes it intuitive for other developers who interact with the API.
Share this principle