6 ms·
Ive come to agree with this. Say you have a struct that contains a name. If you limit the name size to say 64 bytes, then you can store it in the struct, otherw
by quelsolaar 4y ago
Ive come to agree with this. Say you have a struct that contains a name. If you limit the name size to say 64 bytes, then you can store it in the struct, otherwise you need to have a separate allocation and an indirection. This makes the code slower, more error prone and more complex to use. So think hard of when “infinite” is justified.
- AlotOfReading 4y agoYou should also be careful about incorrectly imposing limits on human input, as every "falsehoods programmers should know about x" repeatedly hits on. To continue the name example, there are people with legal names and titles that take far more than 64 bytes to store and truncation is not an appropriate solution. You should store the entire thing, even if that's a small bit more difficult technically. The other limit also applies. Some people don't have any characters in their legal names at all, like my mother (birth certificate name was blank).
- zeroonetwothree 4y agoI think "should" is a bit strong here. There are always tradeoffs. Having support for very long names can cause other problems, like the opportunity for abuse, making it hard to format UIs, making human inspection of data much harder, or even limiting algorithmic efficiency. For example, US Passports have a relatively small limit for name length (I think it's around 20 characters each for first/middle/last).
- jiggawatts 4y ago“Who you are is inconvenient for me.”
- GMoromisato 4y agoConversely, "The needs of the many outweigh the needs of the few, or the one."
- PKop 4y agoYes? Why is someone's existence or circumstance de facto an obligation for someone else? No one lives their life completely accommodating every random stranger's needs.
- hugh-avherald 4y agoMy first name is defined to be the concatenation of all other forenames in the United States.
- PKop 4y agoOr you can make a tradeoff and simply exclude these outliers from using your product, instead of optimizing for their unique case.
- quelsolaar 4y agoWho said anything about the name being the name of a person?
- zeroonetwothree 4y agoThis is true, but note that the "Zero one infinity rule" only applies to the number of items, not the size of an item. Limits on size are a lot more typical anyway. (Yes I know someone will point out that to store a list of items requires a linear amount of space, so therefore an unbounded number of items inherently implies an unbounded amount of space)
- meghan_rain 4y ago> more error prone not when using Rust ;-)
- xigoi 4y agoIf you're using any reasonable language, using data structures without arbitrary limits is just as easy or easier than those with arbitrary limits.