3 ms·
> C strings, no matter how much people have complained about along decades (often quoting Pascal as a good counter-example!), Because Pascal is a good counter-
by brmgb 6y ago
> C strings, no matter how much people have complained about along decades (often quoting Pascal as a good counter-example!),
Because Pascal is a good counter-example to the awfulness of C strings.
I need to point to you that any strings in C is a potential buffer overflow. You can't use a string in C without introducing a potential security risk you will have to thoroughly check for. Ada gives you compile-time guaranties.
> C strings, no matter how much people have complained about along decades (often quoting Pascal as a good counter-example!), were simple and versatile and thus could stand all usages without a change in the base principle (so other string types never took off).
C strings are not so much versatile that they are not actually strings (as usual in C). They are raw byte arrays (in so much as you can C arrays arrays) with a special termination code and UTF-8 took care of staying compatible with this representation.
- wott 6y agoWhy do you think I am not aware of those points? Those complaints have been made a million times. Yes, C is not a memory safe language and you may run into trouble if you don't use stdlib string functions properly or hand-manage characters without paying attention to the termination and the reserved space, we know it. I am talking about the mess of the evolution of strings in the Pascal family. There was, and there isn't any such mess in the C world. That's a fact that cannot be disputed. Of course it is because C strings are extremely simple, and as such didn't have to suffer the superiorly intelligent design of Pascal strings and their original limitation to 256 characters and their incompatible indexing with arrays. You can't seriously keep on talking about the "terrible design" of C-strings when you put Ada and Pascal in front of it. Any other language, yes. Not Pascal and Ada. These are the string types in Pascal: Array of Char, PChar, String, ShortString, AnsiString, WideString, UnicodeString. I probably forget a few, and then there are aliases which may or may not be the alias of this or that other type depending on compilation. Compatibility and automatic conversions between those vary. There are many ways to shoot yourself in the foot with those. Some have remained 1-based indexed to keep indexing compatibility with original strings despite the fact that it doesn't make sense any more (there wasn't a good option to pick: either you were consistent with original strings or you were consistent with other arrays and the new string implementation). Some are 0-based to interact with real world. In Ada, you have a bit fewer types (String, Bounded_String, Unbounded_String, I'll spare you the Wide_ versions), but manipulation is more difficult than in Pascal (and conversions are of course the Ada way : heavily verbose). Not sure if it is still the case, but there wasn't the same display of functions provided for each string type, so you'd convert and convert and convert. And even Unbounded_String is often not versatile enough.
- foerbert 6y agoI'm really not fond of string handling in Ada, but I can't imagine seriously arguing that C-strings are better. Ada strings can be a pain to work with - but that's basically just my problem. And I haven't found it to be all that terrible, actually. Use unbounded strings. Don't mix fully-specified string types. There's even some fairly common styles for shorthands, like the unary '+' for unbounded conversions. It's not great, but it's pretty fine. I don't do so much string manipulation that it's a huge deal. Most all problems will be caught at compile time. Things like the OP are pretty much all taken care of by simply not mixing fully specified string types. And even if you do do it, the worst that'll happen is an exception. That's it. Meanwhile, try misusing a C-string. If you don't get to enjoy trying to track down that problem from all the strange problems it causes, somebody else will be glad to gleefully use it to exploit your program. Ada strings are annoying to you, but they won't cause massive problems - either for you or your users. You cannot say the same for C-strings. I'll take a bit of easily solved bother over trying to debug buffer overruns or massive security problems.
- brmgb 6y ago> You can't seriously keep on talking about the "terrible design" of C-strings when you put Ada and Pascal in front of it. Of course I can. I have used Ada strings extensively. As long as you don't mix bounded and unbounded strings too much (unbounded should be avoided anyway) it's mostly fine. > Yes, C is not a memory safe language and you may run into trouble if you don't use stdlib string functions properly or hand-manage characters without paying attention to the termination and the reserved space, we know it. As far as I'm concerned, that automatically puts C as pretty much the worst you can do regarding strings handling. Even the most misguided attempt to improve on that should be (and have been) an improvement.