Parse, don't validate
This is common lore that experienced programmers have long understood.
When working with data types, strongly avoid free-form types like `str`, `string` or integers.
Instead, prefer types that say what they are and can't be misinterpreted.
This lore is compacted into "Parse, don't validate".
A typical example is: should a column name be "str" or a ColumnName type?
The answer is always the latter. The reason being that it's easy to locate all places in your codebase where a ColumnName is used.
If you'd used str instead, the battle is already lost. If you're writing AI Assisted Python, there's little to no way that you'll be able to do any reasonable refactor once this pattern is well set in the codebase.
Therefore, use your language's type system, use the types and avoid bare types like int, long and str as your fundamental code layers build up.
Comments
Post a Comment