| ▲ | chriswarbo 6 hours ago | |
> You'd naturally gravitate towards parsing/transforming raw data into typed data structures that have guaranteed properties instead to avoid writing defensive code everywhere e.g. a Date object that would throw an exception in the constructor if the string given didn't validate as a date It's tricky because `class` conflates a lot of semantically-distinct ideas. Some people might be making `Date` objects to avoid writing defensive code everywhere (since classes are types), but... Other people might be making `Date` objects so they can keep all their date-related code in one place (since classes are modules/namespaces, and in Java classes even correspond to files). Other people might be making `Date` objects so they can override the implementation (since classes are jump tables). Other people might be making `Date` objects so they can overload a method for different sorts of inputs (since classes are tags). I think the pragmatics of where code lives, and how the execution branches, probably have a larger impact on such decisions than safety concerns. After all, the most popular way to "avoid writing defensive code everywhere" is to.... write unsafe, brittle code :-( | ||