2 ms·
That would not catch the bug if the input is not under is control. You could as well say "Just check if the object is a string" in the method, which would work
by cc81 7y ago
That would not catch the bug if the input is not under is control.
You could as well say "Just check if the object is a string" in the method, which would work but the point was rather that it is difficult to notice if you did not think about it. Compared to other languages that would crash or not compile instead.
- CydeWeys 7y agoYeah, the input isn't really under control because it's coming from deserializing a YAML file. It worked for the exact type of input I was expecting, namely, when you configure a specific value as a list, but it wasn't working for anything else. And YAML has plenty of types it can split out, so my naive fix still only handled lists and strings properly!
- winstonewert 7y agoYeah, YAML deserialization is the worst case scenario for dynamic typing. In most situations, types are pretty consistent and assuming you run your code at least once, you'll find most errors. But with YAML deserialization all bets are off. YAML is even worse then JSON for this because seemingly minor changes in the YAML can change the shape of the data. I've had success validating such data against a schema, so I know it had consistent type structure before working with it.