|
|
|
|
|
by qsort
1204 days ago
|
|
It's in the same sense of "whitelist, don't blacklist", or "by the love of god it's 2023, do not escape SQL". Don't define reasons why the input is invalid, instead have a target struct/object, and parse the input into that object. |
|
There are plenty of cases in real-world code where an array that's part of a struct or object may or may not contain any elements. If you're just parsing input into that, it seems like you'd either still end up doing an equivalent of checking whether the array is empty or not everywhere the array might be used later, even if that check is looking at an "array has elements" type flag in the struct/object, and so you're still maintaining a description of ways that the input may be invalid. But I'm not a world-class programmer, so maybe I'm missing something. Maybe you mean something like for branches of the code that require a non-empty array, you have a second struct/object and parser that's more strict and errors out if the array is empty?