| >32bit or 64bit length? Signed or unsigned? It doesn't make sense to have a signed length. 32 bit should be enough for everyone, it's easier to type as int, and you have less problems with variable sized integers on different targets. Signed length makes sense because length is a number, and numbers are signed, also in conjunction with array -1 sentinel value is often used. >If you don't, you cannot represent a null string (IE a missing value) differently to an empty string. C++ can't do it either with std::string and sky doesn't fall, because such distinction is rarely needed and for business logic empty string means absence of value, actually in languages with nullable strings null string and empty string are routinely synonymous and you often use a method like IsNullOrEmpty to check for absence of value. Anyway you need the concept of absence for other types too, like int, so string isn't special here. >You have to mandate that they use a special stringFree function, or rely on callers first freeing the pointer field and then freeing the struct. pointer+length struct is a value type, see https://en.cppreference.com/w/cpp/container/span |
Incorrect. I'm literally, today, working on a project where the business logic is different depending on whether an empty string is stored in the database, or no string.
"User didn't get to fill in a preference" is very different from "user didn't indicate a preference".
In more practical terms, a missing value could mean that we use the default while an empty value could mean that we don't use it at all.