3 ms·
Strings have nothing to do with objects. You can write a string library, eg. [sds](https://github.com/antirez/sds https://github.com/antirez/sds). It's just not
by c-cube 6y ago
Strings have nothing to do with objects. You can write a string library, eg. [sds](https://github.com/antirez/sds https://github.com/antirez/sds). It's just not standard.
- user5994461 6y agoThe challenge is not to write a string library, but to write a "nice" string library. Let's say, something that's easier to use and doesn't have all the footguns of the char arrays. The library you link doesn't come anywhere close to that. It's 99% like the standard library and it has the exact same issues.
- mariusor 6y agoI would love to see what you mean by "exact same issues". sds strings contain their lengths, so operating on them you don't have to rely on null termination, which (to my knowledge as a lower-midlevel C programmer) is the most prevalent reason why people take issue with C strings. If you mean that they're not really "strings" but byte arrays I would say that I agree, but to all intents and purposes that's what the C ecosystem considers as strings. Keeping an API which is very similar to the standard library is also a plus, as it doesn't force developers to change the way they reason about the code.
- CRConrad 6y ago> sds strings contain their lengths, so operating on them you don't have to rely on null termination, which (to my knowledge as a lower-midlevel C programmer) is the most prevalent reason why people take issue with C strings. Wait, haven't I seen that idea somewhere else...? > If you mean that they're not really "strings" but byte arrays I would say that I agree, but to all intents and purposes that's what the C ecosystem considers as strings. Aha, strings as byte arrays but with a built-in length marker. But yeah, Pascal is sooo outmoded and inferior to C... Sigh.
- kergonath 6y agoYou’re moving goalposts now. Just earlier you wrote that you couldn’t write a library in C because C does not support objects, not that you couldn’t write a nice library (for whatever definition of “nice” you want to use, which will be different from someone else’s). In fact there are several libraries for string-like objects; the main barrier to use them is that none of them is standard. You can at least acknowledge that before talking about nice-ness, which is a whole other point.