|
|
|
|
|
by britch
197 days ago
|
|
Early errors are good, but I think the author overstates the importance of filtering out empty strings --- I disagree that erroring out when the app doesn't have ALL the data is the best course of action. I imagine it depends a bit on the domain, but for most apps I've worked on it's better to show someone partial or empty data than an error. Often the decision of what to do when the data is missing is best left up the the display component. "Don't show this div if string is empty", or show placeholder value. --- Flip side, when writing an under the hood function, it often doesn't matter if the data is empty or not. If I'm aggregating a list of fooBars, do I care if fooBarDisplayName is empty or not? When I'm writing tests and building test-data, needing to add a value for each string field is cumbersome. Sometimes a field really really matters and should throw (an empty string ID is bad), but those are the exception and not the rule. |
|
It’s the difference between:
if (fooBarDisplayName) { show div }
And:
if (foobarDisplayName && foobarDisplayName.length > 0) { show div }
Ultimately, type systems aren’t telling you what types you have to use where - they’re giving you tools to define and constrain what types are ok.