Public Interfaces and Internal Helpers
A public function forms part of the promise made to callers. An internal helper can change with the implementation as long as that promise holds.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Identify the stable boundary
A reader API can promise records in file order even if its parser is later replaced. Callers depending on the parser's temporary intermediate shape have taken on a second dependency. Function postconditions specify the stable order.
Express intent in the module
Python projects commonly use a leading underscore for names intended for internal use. Exported names deserve clear descriptions and examples because refactoring them can affect callers. Keyword arguments are one example of a seemingly small public change.[1][2]
Identify the feature external callers depend on
A parser might publicly promise records with three named fields, while internally splitting strings and converting numbers. Changing the splitting method in a future version need not affect callers if the field values and parse errors remain consistent. Tests checking calls to a particular internal splitter can pin an implementation detail while missing a regression in returned records. Test a valid row, an incomplete row and a quoted separator through the public parser. See writing function contracts.
Treat unadvertised access as a compatibility question when needed
A Python name beginning with an underscore signals an internal convention, although code can still import it explicitly. If real callers depend on such a helper, moving it may affect them. Decide whether to offer a supported public operation or document the existing boundary and coordinate migration. For the public API, specify the types, units and error behavior that callers may use. See changing a contract safely.