I recently stumbled across this idea in a Hacker News comment.
The principle of least astonishment applies to user interface and software design. A typical formulation of the principle, from 1984, is: "If a necessary feature has a high astonishment factor, it may be necessary to redesign the feature."
In general engineering design contexts, the principle means that a component of a system should behave in a way that users expect it to behave; that is, users should not be astonished by its behavior
In my experience it's often a good idea to draft your program's public API before actually building it. Don't let implementation details influence design.